Skip to content

Gitlab Runner

Gitlab runner image based on ubi: https://quay.io/repository/openshift-examples/gitlab-runner

Docker Repository on Quay

Deploy the runner

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
oc new-project gitlab-runner

oc create sa gitlab-runner
oc adm policy add-role-to-user edit -z gitlab-runner

# Create empty secret gitlab-runner-config
oc create secret generic gitlab-runner-config \
    --from-literal=config.toml="" 

# Create secret for registration gitlab-runner-register
oc create secret generic gitlab-runner-register \
    --from-literal=REGISTRATION_TOKEN=xL6C6HEg2CFdXS3rM_BZ \
    --from-literal=CI_SERVER_URL=https://gitlab.com/ \
    --from-literal=RUNNER_EXECUTOR=kubernetes \
    --from-literal=RUNNER_TAG_LIST=ocp

Apply deployment config

 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
oc create -f - <<EOF
apiVersion: v1
kind: DeploymentConfig
metadata:
  name: gitlab-runner
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      name: gitlab-runner
      labels:
        app: gitlab-runner
    spec:
      serviceAccount: gitlab-runner
      containers:
      - name: run
        image:  quay.io/openshift-examples/gitlab-runner:latest
        command:  
          - /usr/bin/bash
          - -x
          - -c
          - |
            # Register 
            cp -v /gitlab-runner-config/config.toml $HOME/.gitlab-runner/config.toml

            gitlab-runner unregister --all-runners
            # unregister do not update config.toml if unregister fail.
            rm $HOME/.gitlab-runner/config.*

            gitlab-runner register --non-interactive

            # Update secret
            oc create secret generic gitlab-runner-config  --from-file=config.toml=$HOME/.gitlab-runner/config.toml --dry-run -o yaml | oc apply -f -

            gitlab-runner run
        volumeMounts:
        - name: gitlab-runner-config
          mountPath: "/gitlab-runner-config"
          readOnly: true
        env:
        - name: KUBERNETES_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        envFrom:
        - secretRef:
            name: gitlab-runner-register
        livenessProbe:
          exec:
            command:
            - /usr/bin/bash
            - -x
            - -c
            - |
              # gitlab-runner verify wont work with $CI_SERVER_URL
              unset CI_SERVER_URL
              gitlab-runner verify
          initialDelaySeconds: 10
          periodSeconds: 5
      volumes:
      - name: gitlab-runner-register
        secret:
          secretName: gitlab-runner-register
      - name: gitlab-runner-config
        secret:
          secretName: gitlab-runner-config
  triggers:
  - type: ConfigChange
EOF

Build gitlab-runner image

1
2
3
git clone https://github.com/rbo/openshift-examples.git
cd openshift-examples/workload/gitlab-runner/
podman build -t gitlab-runer .

Checkout the Dockerfile for more details.

Notes


Last update: April 12, 2020