Deploy gitlab-runner

Here is based on helm deployment, reference: https://gitlab.com/gitlab-org/charts/gitlab-runner.git

1
helm install --namespace gitlab-managed-apps --name k8s-gitlab-runner -f values.yaml

Note: the values.yaml file needs to be set to privileged: true

Build a basic image (docker in docker)

Dockerfile file content:

1
2
3
4
5
6
7
FROM docker:19.03.1-dind
WORKDIR /opt
RUN echo "nameserver 114.114.114.114" >> /etc/resolv.conf
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk update
RUN apk upgrade
RUN apk add g++ gcc make docker docker-compose git

Build the image and push it to harbor

1
2
docker build -t registry.test.cn/devops/docker-tool:19.03.1 .
docker push registry.test.cn/devops/docker-tool:19.03.1

Gitlab-CI test

The contents of the .gitlab-ci.yml file are as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
image: registry.test.cn/devops/docker-tool:19.03.1

variables:
REPO_NAME: gitlab.test.cn/xxx/xxxx
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""

before_script:
- mkdir -p $GOPATH/src/$(dirname $REPO_NAME)
- ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME
- cd $GOPATH/src/$REPO_NAME

stages:
- deploy

deploy:
tags:
- k8s-gitlab-runner #Specify runner
only:
- tags
stage: deploy
services:
- registry.test.cn/devops/docker-tool:19.03.1
script:
- export DOCKER_HOST='tcp://localhost:2375'
- docker login -u "$Harbor_bce_user" -p "$Harbor_ecs_passwd" $Harbor_ecs_address #Set unified variables in gitlab background
- make deploy VERSION=$CI_COMMIT_REF_NAME #Build image according to git tag