Lead-up steps: DevOps GitLab CICD Practice 1 — GitLab Deployment

The official documentation

The document address

Although there are official guidelines, I feel that the guidelines are not clear enough, leading to frequent failures in initial configuration

Run GitLab Runner in a container

This is how you can run GitLab Runner inside a Docker container.

General GitLab Runner Docker image usage

GitLab Runner Docker images (based on Ubuntu or Alpine Linux) are designed as wrappers around the standard gitlab-runner command, like if GitLab Runner was installed directly on the host.

The general rule is that every GitLab Runner command that normally would be executed as:

gitlab-runner [Runner commandand options... ]Copy the code

can be executed with:

docker run [chosen docker options...]  gitlab/gitlab-runner [Runnercommandand options... ]Copy the code

For example, getting the top-level help information for GitLab Runner command could be executed as:

docker run --rm -t -i gitlab/gitlab-runner --help

NAME:
   gitlab-runner - a GitLab Runner

USAGE:
   gitlab-runner [global options] command [commandoptions] [arguments...] VERSION: 10.7.0 c273476 (7) (...).Copy the code

In short, the gitlab-runner part of the command is replaced with docker run [docker options] gitlab/gitlab-runner, While the rest of Runner’s command stays as it is described in the register. The only difference is that the gitlab-runner command is executed inside of a Docker container.

Docker image installation and configuration

  1. Install Docker first:

     curl -sSL https://get.docker.com/ | sh
    Copy the code
  2. You need to mount a config volume into the gitlab-runner container to be used for configs and other resources:

     docker run -d --name gitlab-runner --restart always \
       -v /srv/gitlab-runner/config:/etc/gitlab-runner \
       -v /var/run/docker.sock:/var/run/docker.sock \
       gitlab/gitlab-runner:latest
    Copy the code

    Tip: On macOS, use /Users/Shared instead of /srv.

    Or, you can use a config container to mount your custom data volume:

     docker run -d --name gitlab-runner-config \
         -v /etc/gitlab-runner \
         busybox:latest \
         /bin/true
    Copy the code

    And then, run the Runner:

     docker run -d --name gitlab-runner --restart always \
         -v /var/run/docker.sock:/var/run/docker.sock \
         --volumes-from gitlab-runner-config \
         gitlab/gitlab-runner:latest
    Copy the code
  3. Register the runner you just launched by following the instructions in the Docker section of Registering Runners. The runner won’t pick up any jobs until it’s registered.

Installation steps

Obtain the Gitlab Runner secret key

It can be obtained through the Gitlab administrator account, or it can be configured by each user

  • Common users view the secret key

Go to the Settings of any repository and view the CICD configuration

Ready to register a dedicated Runner token

  • The administrator views the token

Enter the general Settings page and configure the global Runner token

Runner registered

Because Runner generally runs complex construction and packaging tasks, it is recommended to configure it in the machine room with higher performance and bandwidth

Prepare the Docker environment

$ curl -sSL https://get.docker.com/ | sh
$ systemctl start docker
Copy the code

registered

Registered Runner types can be selected as needed

Also, for ease of configuration, use single-line registration and turn off interaction

Single line registration of official documents

Command description:

  • -vThe purpose of mounting is to persist the registered configuration file for running the container
  • --rmSpecifies that stopped containers are automatically deleted after the container finishes running
  • -itYou can use the interactive command line interface to view the registration result
$ docker run --rm -it \ -v /www/wwwroot/gitlab/srv/gitlab-runner/config:/etc/gitlab-runner \ Gitlab/gitlab-Runner :alpine-v11.8.0 register \ --non-interactive \ --executor"docker" \
  --docker-image docker:stable \
  --url "Gitlab URL" \
  --registration-token "Token" \
  --description "Description" \
  --tag-list "Tag 1, tag 2" \
  --run-untagged \
  --docker-privileged \
  --locked="false"
Copy the code

Registration Success Message

The admin panel shows that the new Runner has been registered

Runner starts

Mount local configuration information and start Runner

$ docker run -d--name gitlab-runner --restart always \ -v /www/wwwroot/gitlab/srv/gitlab-runner/config:/etc/gitlab-runner \ -v The/var/run/docker. The sock: / var/run/docker. The sock \ gitlab/gitlab - runner: alpine - v11.8.0Copy the code

At this time, it can be seen that Runner has maintained contact with Gitlab