Commit fa9d52ad authored by Kevin Daudt's avatar Kevin Daudt

docker-compose: setup entrypoint to register runner on start

Instead of having to manually run a command to register the runner,
automatically register the runner on start if the config file does not
exist yet.
parent 4ed9c80f
......@@ -8,9 +8,9 @@ RUN echo '@edge/testing http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /e
gitlab-runner@edge/testing \
&& adduser -D -S -h /home/gitlab-runner gitlab-runner
COPY register-runner /usr/local/bin
COPY register-runner entrypoint /usr/local/bin/
VOLUME ["/etc/gitlab-runner", "/home/gitlab-runner"]
ENTRYPOINT ["/usr/bin/gitlab-runner"]
ENTRYPOINT ["/usr/local/bin/entrypoint"]
CMD ["run", "--user=gitlab-runner", "--working-directory=/home/gitlab-runner"]
# gitlab-runner docker image
[![pipeline status](https://gitlab.alpinelinux.org/alpine/infra/docker/gitlab-runner/badges/master/pipeline.svg)](https://gitlab.alpinelinux.org/alpine/infra/docker/gitlab-runner/commits/master)
This will create a docker image for running a gitlab runner on Alpine Linux on
all the architectures that Alpine Linux supports.
## Starting the runner
To run the container, 1 required and 2 optional volumes need to be attached:
* docker socket (/var/run/docker.sock)
* conf dir (/etc/alpine-runner)
* home dir (/home/gitlab-runner)
For example:
```sh
docker run -d \
-v /srv/gitlab-runner/conf:/etc/gitlab-runner \
-v /srv/gitlab-runner/home:/home/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab-runner
```
You can execute `./run` to run this command
## Register the runner
There is a `./register-runner` command available in the container to register it.
To execute it, use the following command:
There is a `docker-compose.yml` file included that starts up the runner. The
registration of the runner will be done automatically, but you need to modify
the file to specify some parameters:
```sh
docker exec -e ARCH=<arch> -e GITLAB_REGISTER_TOKEN=<token> <container> register-runner
```
* `<token>` - The gitlab registration token (you can find it in the admin pannel
under runners)
* `<arch>` - The architecture for this runner (used as a description and tag).
* `ARCH` is added as a tag on the runner
* `GITLAB_REGISTER_TOKEN` is a token you can find under `Settings > CI / CD > Runners`
of a specific project or under `Admin > Overview > Runners`.
Then run `docker-compose up -d` and the runner should be running.
......@@ -6,3 +6,6 @@ services:
- /srv/gitlab-runner/conf:/etc/gitlab-runner
- /srv/gitlab-runner/home:/home/gitlab-runner
- /var/run/docker.sock:/var/run/docker.sock
environment:
GITLAB_REGISTRATION_TOKEN: <token>
ARCH: <arch>
#!/bin/sh
if [ ! -f /etc/gitlab-runner/config.toml ]; then
if [ -z "$GITLAB_REGISTRATION_TOKEN" ] || [ "$GITLAB_REGISTRATION_TOKEN" = '<token>' ]; then
echo "Runner is not configured. Please provide 'GITLAB_REGISTRATION_TOKEN'"
exit 1
fi
register-runner || exit $?
fi
exec gitlab-runner "$@"
#!/bin/sh
echo "-> Registering runner $ARCH"
gitlab-runner register \
--non-interactive \
--url "https://gitlab.alpinelinux.org/" \
--registration-token "$GITLAB_REGISTER_TOKEN" \
--registration-token "$GITLAB_REGISTRATION_TOKEN" \
--executor "docker" \
--docker-image alpine:latest \
--description "docker-runner ($ARCH)" \
......@@ -13,3 +15,11 @@ gitlab-runner register \
--access-level="not_protected" \
--docker-helper-image alpinelinux/gitlab-runner-helper:latest \
--docker-volumes /var/run/docker.sock:/var/run/docker.sock
status=$?
if [ $status -eq 0 ]; then
echo "-> Registration success"
else
echo "-> Something went wrong"
exit $status
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment