Resources
- GitLab Runner Docs
- Docs on various GitLab Runner Executors
- GitLab CI Pipeline Configuration Docs
- Predefined Environment Variables for builds
Setting up your own personal GitLab Runner
To help you get up and running with GitLab CI, the following steps can be followed to help you set up a GitLab Runner on your own personal device. Note that this runner should not be used to support actual team builds, but can be a great way to experiment how to work with builds.
Create a new GitLab repo in your own personal namespace. Name it
gitlab-runner-demo
.If you don’t see the CI/CD menu in the left-hand nav, enable Pipeline support for the repo.
- Go into Settings -> General.
- In the Visibility, project features, permissions section, enable Pipelines.
- Click Save changes
- Verify that the “CI/CD” menu option now appears.
Go into Settings -> CI/CD and expand the “Runners” section. We will need values from this in the next steps.
Register your runner!
Run the following command to start the registration process.
docker container run --rm -ti \ -v ${PWD}:/etc/gitlab-runner \ gitlab/gitlab-runner register
For the “gitlab-ci coordinator URL”, enter the URL in the instructions. (https://code.vt.edu)
For the “gitlab-ci token for this runner”, enter the registration token displayed on the settings page.
For a runner description, enter something like “[Your Name]’s Personal Runner”. This will be used in the GitLab interface, so should be a name you’d recognize.
For tags, you can leave this empty for now. Tags allow you to target specific runners for specific jobs.
For the executor, enter “docker”.
For the default image, you can really put anything, as we will be specifying the exact image in each stage of our builds. I typically use “docker:stable”.
Refresh the repo’s settings page and make sure your new runner shows up on the project. Most likely, it will show us activated, but that it has not connected yet.
If you look in the directory you ran your registration, you should see a
config.toml
file. We’re going to modify it to not run builds “Docker-in-Docker”, but directly on the host. When builds start, each job will run in a separate container. We need to mount the Docker socket into the container to let it talk to the engine on the host.- In the
runners.docker
section, modify thevolumes
to have the value["/cache","/var/run/docker.sock:/var/run/docker.sock"]
. This is something we’re doing for only our local/test and shouldn’t be done for real pipelines (where you should use Docker-in-Docker).
- In the
Now, let’s start up our runner! After a few seconds, you should see a green ball next to your now-running runner!
docker run -d \ -v ${PWD}:/etc/gitlab-runner \ -v /var/run/docker.sock:/var/run/docker.sock \ gitlab/gitlab-runner
Let’s create some files and a simple build!
Create a basic
index.html
file with some “Hello world” textCreate a Dockerfile with the following:
FROM nginx:alpine COPY index.html /usr/share/nginx/html
Create a
.gitlab-ci.yml
file with the following:stages: - build build: stage: build image: docker script: - docker build -t my-first-nginx-app .
Once you commit this, you should see a build kick off!
Back on your machine, start your app!
docker run -dp 80:80 my-first-nginx-app
And open your browser to http://localhost!