What is a Runner?
Runner = the machine that executes your workflow jobs.
When you push code:
- GitHub Actions starts
- A runner is assigned
- That runner runs your steps (install, test, deploy)
Types of Runners
GitHub-hosted
- Provided by GitHub
- Ready to use
- Ephemeral (fresh VM each job)
runs-on: ubuntu-latestSelf-hosted
- Your own machine (EC2, on-prem, laptop)
- Full control of tools and network
- Ideal when deploy must hit this server
runs-on: self-hostedRunner = the system that actually executes your CI/CD steps.
Why EC2 for a Self-Hosted Runner?
- Full control of the Node / PM2 environment
- Deploy happens on the app host (no separate SSH dance per step)
- Faster, predictable path for a single-server backend
Setup on AWS EC2
1. Launch and connect
- Ubuntu EC2; open 22, and 80/443 (or 3000 during early testing)
ssh -i your-key.pem ubuntu@your-ec2-ip2. Install app tooling
sudo apt update
sudo apt install -y nodejs npm git
npm install -g pm2 # optional but recommended3. Add a runner from GitHub
- Repo → Settings → Actions → Runners → New self-hosted runner
- Choose Linux
- Follow the download / extract commands GitHub shows (versions change over time), for example:
mkdir actions-runner && cd actions-runner
# Use the exact curl URL from the GitHub UI for the current runner version
tar xzf ./actions-runner-linux-x64-*.tar.gz4. Configure and run
./config.sh
# Enter repo URL, token from GitHub, and a runner name
./run.shThe EC2 host is now ready to pick up runs-on: self-hosted jobs.
5. Install as a service (important)
Keep the runner alive after logout / reboot:
sudo ./svc.sh install
sudo ./svc.sh start
# sudo ./svc.sh stop # when you need to stop itFinal Flow
Push Code → GitHub Actions → EC2 Runner → Deploy App
A self-hosted runner on EC2 lets the pipeline run on the same machine that serves the app, which simplifies deploy for this architecture.