A controller for the self-hosted GitHub actions runner, providing automatic scaling.
474
The GitHub Actions Controller is a Docker controller that provides auto-scaling for GitHub action workflow runners used within an organization.
The project is built using TypeScript and uses Docker as the underlying container runtime.
When running the controller, it will watch for new actions and will create a new runner for each workflow. The runner will be created using the GitHub Actions Runner, after the workflow has finished, the runner will be deleted to free up resources.
The container can be started by running the following command:
docker run -d \
--name github-actions-controller \
--restart always \
-e PORT=8000 \
-e ORGANIZATION=<your github organization> \
-e ACCESS_TOKEN=<your github access token> \
-e CONTAINERS_MAX=10 \
-e CONTAINERS_TTL=3600 \
-p 8000:8000 \
-v /var/run/docker.sock:/var/run/docker.sock \
senither/github-actions-controller:latest
You'll have to substitute the
<your org>for your organization name, and<your access token>for your fine-grained token with access to the organization with permissions to read and write to the organization's runners.
Alternatively, you can start the controller using Docker Compose.
version: '3.7'
services:
controller:
restart: unless-stopped
build:
context: .
dockerfile: Dockerfile
image: senither/github-actions-controller
environment:
APP_ENV: production
APP_DEBUG: false
PORT: 8000
ORGANIZATION: ${ORGANIZATION}
ACCESS_TOKEN: ${ACCESS_TOKEN}
CONTAINERS_MAX: 10
CONTAINERS_TTL: 2700
networks:
- controller
ports:
- 8000:8000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
# Networks to be created to facilitate communication between containers
networks:
controller:
driver: bridge
The environment variables can now be stored in a .env file next to the docker-compose.yml file, once that's created and setup you can now start the controller by running:
docker compose up -d
Note: The
/var/run/docker.sock:/var/run/docker.sockvolume is required so that the controller can interact with Docker and is able to start and stop the action runners.
After the container is up and running you'll need to register the webhook API route as a webhook in GitHub, to do this you can do the following:
/webhook route in the container
application/jsonAnd that should be it, the container will now be notified by GitHub when new workflows are queued, in-progress, and completed, which it can then use to start and stop the action runners when needed.
The controller can take in a few environment variables to modify the behavior of the controller, a list of all the environment variables can be found below.
APP_ENVThe application environment the controller is being started as, if the environment is not set to production the controller will start a dummy container instead of the actions runner to not spam create and delete GitHub runners.
Default to
production
APP_DEBUGDetermines if the debug logging output should be sent to the console or not.
Defaults to
false
PORTThe port the web API should be running on, this is also used to handle the webhook requests.
Defaults to
8000
ORGANIZATIONThe GitHub organization the ACCESS_TOKEN is created for, this is used to tell the controller and the actions runner which organization to register the runners for.
ACCESS_TOKENThe GitHub access token, the token must be a fine-grained token with access to the organization with permissions to read and write to the organization's runners and administration, the administration permissions are used to delete offline runners from the organization.
CONTAINERS_MAXThe maximum amount of action runner containers that the controller should be running at a time.
Defaults to
3
CONTAINERS_TTLThe maximum amount of seconds an action can run before it's counted as having timed out, timed-out actions will be removed from the internal webhook queue.
Content type
Image
Digest
sha256:43a38bff8…
Size
369.5 MB
Last updated
about 3 years ago
docker pull senither/github-actions-controller