👌 Github Actions self-hosted runner provisioning
Simple Docker images for starting self-hosted Github Actions runner(s).
Github official documentation for self-hosted runners.
🚀 Quick start
Add your self-hosted runner from your repository settings:
- Go to repository > settings > actions
- Click on "Add runner"
- Copy the URL and token
# start a runner on your server
$ docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp:/tmp \
-e GH_REPOSITORY=xxxxxxxxxxxx \
-e GH_RUNNER_TOKEN=xxxxxxxxxxxxx \
-e GH_RUNNER_LABELS=label1,label2 \
samber/github-actions-runner:latest# .github/workflows/main.yml on: - push jobs: example: runs-on: self-hosted steps: - name: Hello world run: echo "Hello world"
Runners with language support (NodeJS, Python3...)
Just select your runner in the Docker image tag.
Currently available:
- samber/github-actions-runner:node
- samber/github-actions-runner:golang
- samber/github-actions-runner:python
- samber/github-actions-runner:java
- samber/github-actions-runner:php
# start a NodeJS runner
$ docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp:/tmp \
-e GH_REPOSITORY=xxxxxxxxxxxx \
-e GH_RUNNER_TOKEN=xxxxxxxxxxxxx \
-e GH_RUNNER_LABELS=node \
samber/github-actions-runner:node# .github/workflows/main.yml on: - push jobs: frontend: runs-on: self-hosted steps: - uses: actions/checkout@v2 - name: Fetch dependencies run: yarn - name: Build application run: npm run build - name: Execute tests run: npm run test
Missing language support ?
You just need to write a Dockerfile starting with FROM samber/github-actions-runner:latest.
You can contribute to this repository or create your own Docker image.
💡 Docker compose
Simple runner
version: '3' services: runner: image: samber/github-actions-runner:latest volumes: - /var/run/docker.sock:/var/run/docker.sock - /tmp:/tmp environment: - GH_REPOSITORY=xxxxxxxxxxxx - GH_RUNNER_TOKEN=xxxxxxxxxxxxx - GH_RUNNER_LABELS=label1,label2 \ restart: unless-stopped
Concurrent executors
$ docker-compose scale runner=3
Runners with language support
You will need to register multiple runners, with different name+tokens.
In the following example, we create 2 self-hosted runners: node and golang, with respective tag: "node" and "golang". We will start 2 instances of each.
version: '3' services: runner-node: image: samber/github-actions-runner:node volumes: - /var/run/docker.sock:/var/run/docker.sock - /tmp:/tmp environment: - GH_REPOSITORY=yyyyyyyyyyyyy - GH_RUNNER_TOKEN=xxxxxxxxxxxxx - GH_RUNNER_LABELS=node \ restart: unless-stopped runner-golang: image: samber/github-actions-runner:golang volumes: - /var/run/docker.sock:/var/run/docker.sock - /tmp:/tmp environment: - GH_REPOSITORY=yyyyyyyyyyyyy - GH_RUNNER_TOKEN=zzzzzzzzzzzzz - GH_RUNNER_LABELS=golang \ restart: unless-stopped
$ docker-compose up -d $ docker-compose scale runner-node=2 runner-golang=2
# .github/workflows/main.yml on: - push jobs: frontend: runs-on: [self-hosted, node] steps: - uses: actions/checkout@v2 - name: Fetch dependencies run: yarn - name: Build application run: npm run build - name: Execute tests run: npm run test api: runs-on: [self-hosted, golang] steps: - uses: actions/checkout@v2 - name: Fetch dependencies run: go mod download - name: Build application run: go build -o hello-world - name: Execute tests run: go testt
🤯 Advanced
Run as root
For whatever (bad 😅) reason, if you need to start runners as root, you have to set container user to root, and add an empty RUNNER_ALLOW_RUNASROOT environment variables.
🔬 Build
docker build -f Dockerfile -t samber/github-actions-runner:latest -t samber/github-actions-runner:2.272.0 . docker build -f Dockerfile.node -t samber/github-actions-runner:node -t samber/github-actions-runner:node-2.272.0 . docker build -f Dockerfile.golang -t samber/github-actions-runner:golang -t samber/github-actions-runner:golang-2.272.0 . docker build -f Dockerfile.python -t samber/github-actions-runner:python -t samber/github-actions-runner:python-2.272.0 . docker build -f Dockerfile.java -t samber/github-actions-runner:java -t samber/github-actions-runner:java-2.272.0 . docker build -f Dockerfile.php -t samber/github-actions-runner:php -t samber/github-actions-runner:php-2.272.0 . docker push samber/github-actions-runner:latest docker push samber/github-actions-runner:2.272.0 docker push samber/github-actions-runner:node docker push samber/github-actions-runner:node-2.272.0 docker push samber/github-actions-runner:golang docker push samber/github-actions-runner:golang-2.272.0 docker push samber/github-actions-runner:python docker push samber/github-actions-runner:python-2.272.0 docker push samber/github-actions-runner:java docker push samber/github-actions-runner:java-2.272.0 docker push samber/github-actions-runner:php docker push samber/github-actions-runner:php-2.272.0
♻️ Host cleanup
Clean stopped containers on a daily basis:
$ crontab -e 0 0 * * * /usr/bin/docker system prune -f
🤝 Contributing
This project is open source and contributions from community (you!) are welcome.
There are many ways to contribute: writing code, documentation, reporting issues...
Author
👤 Samuel Berthe
- Twitter: @samuelberthe
- Github: @samber
💫 Show your support
Give a ⭐️ if this project helped you!
📝 License
Copyright © 2020 Samuel Berthe.
This project is MIT licensed.

