Skip to content

Commit 8d96061

Browse files
committed
Initial commit for runner based on debian-buster
0 parents  commit 8d96061

File tree

7 files changed

+148
-0
lines changed

7 files changed

+148
-0
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
APP_NAME="tcardonne/github-runner"
2+
3+
# HELP
4+
# This will output the help for each task
5+
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
6+
.PHONY: help
7+
help: ## This help.
8+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
9+
10+
.DEFAULT_GOAL := help
11+
12+
build: ## Build the image
13+
docker build -t $(APP_NAME) debian-buster
14+
15+
shell: ## Creates a shell inside the container for debug purposes
16+
docker run -it $(APP_NAME) bash

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# GitHub Runner
2+
3+
GitHub allows developpers to run GitHub Actions workflows on your own runners.
4+
This Docker image allows you to create your own runner on Docker.
5+
6+
Note : As stated in the [documentation](https://help.github.com/en/github/automating-your-workflow-with-github-actions/about-self-hosted-runners) :
7+
> "GitHub Actions is currently in limited public beta and is subject to change. We strongly recommend that you do not use this feature for high-value workflows and content during the beta period".
8+
9+
## Usage
10+
11+
Use the following command to start listening for jobs:
12+
```shell
13+
docker run -it --name my-runner \
14+
-e RUNNER_NAME=my-runner \
15+
-e RUNNER_TOKEN=token \
16+
-e RUNNER_REPOSITORY_URL=https://github.com/... \
17+
tcardonne/github-runner
18+
```
19+
20+
## Environment variables
21+
22+
The following environment variables allows you to control the configuration parameters.
23+
24+
| Name | Description | Default value |
25+
|------|---------------|-------------|
26+
| RUNNER_REPOSITORY_URL | The runner will be linked to this repository URL | Required |
27+
| RUNNER_TOKEN | Personal Access Token provided by GitHub | Required
28+
| RUNNER_WORK_DIRECTORY | Runner's work directory | `"_work"`
29+
| RUNNER_NAME | Name of the runner displayed in the GitHub UI | Hostname of the container
30+
31+
## Using docker-compose.yml
32+
33+
```yaml
34+
version: "3.6"
35+
36+
services:
37+
runner:
38+
image: tcardonne/github-runner:latest
39+
environment:
40+
RUNNER_NAME: "my-runner"
41+
RUNNER_REPOSITORY_URL: ${RUNNER_REPOSITORY_URL}
42+
RUNNER_TOKEN: ${RUNNER_TOKEN}
43+
```

debian-buster/Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM debian:buster
2+
3+
ARG GH_RUNNER_VERSION="2.160.0"
4+
5+
ENV RUNNER_NAME=""
6+
ENV RUNNER_WORK_DIRECTORY="_work"
7+
ENV RUNNER_TOKEN=""
8+
ENV RUNNER_REPOSITORY_URL=""
9+
10+
# Labels.
11+
LABEL maintainer="me@tcardonne.fr" \
12+
org.label-schema.schema-version="1.0" \
13+
org.label-schema.build-date=$BUILD_DATE \
14+
org.label-schema.vcs-ref=$VCS_REF \
15+
org.label-schema.name="tcardonne/github-runner" \
16+
org.label-schema.description="Dockerized GitHub Actions runner." \
17+
org.label-schema.url="https://github.com/tcardonne/docker-github-runner" \
18+
org.label-schema.vcs-url="https://github.com/tcardonne/docker-github-runner" \
19+
org.label-schema.vendor="Thomas Cardonne" \
20+
org.label-schema.docker.cmd="docker run -it tcardonne/github-runner:latest"
21+
22+
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
23+
apt-get install -y curl git && \
24+
rm -rf /var/lib/apt/lists/* && \
25+
apt-get clean
26+
27+
RUN useradd -ms /bin/bash runner
28+
WORKDIR /home/runner
29+
30+
RUN curl -O https://githubassets.azureedge.net/runners/${GH_RUNNER_VERSION}/actions-runner-linux-x64-${GH_RUNNER_VERSION}.tar.gz \
31+
&& tar -zxf actions-runner-linux-x64-${GH_RUNNER_VERSION}.tar.gz \
32+
&& rm -f actions-runner-linux-x64-${GH_RUNNER_VERSION}.tar.gz \
33+
&& ./bin/installdependencies.sh \
34+
&& chown -R runner: /home/runner
35+
36+
COPY entrypoint.sh /entrypoint.sh
37+
RUN chmod +x /entrypoint.sh
38+
ENTRYPOINT ["/entrypoint.sh"]
39+
CMD ["./run.sh"]
40+
41+
USER runner

debian-buster/entrypoint.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
if [[ "$@" == "bash" ]]; then
4+
exec $@
5+
fi
6+
7+
if [[ -z $RUNNER_NAME ]]; then
8+
echo "RUNNER_NAME environment variable is not set, using '${HOSTNAME}'."
9+
export RUNNER_NAME=${HOSTNAME}
10+
fi
11+
12+
if [[ -z $RUNNER_WORK_DIRECTORY ]]; then
13+
echo "RUNNER_WORK_DIRECTORY environment variable is not set, using '_work'."
14+
export RUNNER_WORK_DIRECTORY="_work"
15+
fi
16+
17+
if [[ -z $RUNNER_TOKEN ]]; then
18+
echo "Error : You need to set the RUNNER_TOKEN environment variable."
19+
exit 1
20+
fi
21+
22+
if [[ -z $RUNNER_REPOSITORY_URL ]]; then
23+
echo "Error : You need to set the RUNNER_REPOSITORY_URL environment variable."
24+
exit 1
25+
fi
26+
27+
if [[ -f ".runner" ]]; then
28+
echo "Runner already configured. Skipping config."
29+
else
30+
./config.sh \
31+
--url $RUNNER_REPOSITORY_URL \
32+
--token $RUNNER_TOKEN \
33+
--agent $RUNNER_NAME \
34+
--work $RUNNER_WORK_DIRECTORY
35+
fi
36+
37+
exec "$@"

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "3.6"
2+
3+
services:
4+
runner:
5+
image: tcardonne/github-runner
6+
environment:
7+
RUNNER_NAME: "my-runner"
8+
RUNNER_REPOSITORY_URL: ${RUNNER_REPOSITORY_URL}
9+
RUNNER_TOKEN: ${RUNNER_TOKEN}

0 commit comments

Comments
 (0)