CI/CD Advanced Play

1. Using the host maven repository

Each time the build is in a separate container, maven needs to download the dependent jar from the maven repository again. This is actually not necessary.

We can use docker’s volume to share .m2 files among multiple containers.

In addition, each time the runner will pull the dependent image on the docker hub, this is not necessary too.

From this we need to make some changes, to open the /srv/gitlab-runner/config/config.toml file. Add the maven .m2 directory to volumes and add mirror pull rules, as follows

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
concurrent = 1
check_interval = 0

[[runners]]
name = "docker-runner"
url = "https://your_gitlab_ip/"
token = "xxxxxxxxxxxxxxxxxxxxxxx"
executor = "docker"
environment = ["HTTPS_PROXY=http://your_proxy_ip:port", "HTTP_PROXY=http://your_proxy_ip:port", "NO_PROXY=localhost,127.0.0.0"]
[runners.docker]
tls_verify = false
image = "docker"
privileged = true
disable_cache = false
shm_size = 0
volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock", "/usr/.m2:/root/.m2"]
pull_policy = "if-not-present"
[runners.cache]

Restart runner

1
docker restart gitlab-runner

2. Install Kubernetes

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

Kubernetes relies on the etcd service to maintain the status of all primary nodes.

2.1. Start the Etcd service

1
docker run --net=host -d gcr.io/google_containers/etcd:v2.3.8 /usr/local/bin/etcd --addr=127.0.0.1:4001 --bind-addr=0.0.0.0:4001 --data-dir=/var/etcd/data

2.2. Start the master node (kubelet)

1
docker run --net=host -d -v /var/run/docker.sock:/var/run/docker.sock  gcr.io/google_containers/hyperkube:latest /hyperkube kubelet --api_servers=http://localhost:8080 --v=2 --address=0.0.0.0 --enable_server --hostname_override=127.0.0.1 --config=/etc/kubernetes/manifests

2.3. Start Service Agent

1
docker run -d --net=host --privileged gcr.io/google_containers/hyperkube:latest /hyperkube proxy --master

3. Configuration of your jobs with .gitlab-ci.yml

See https://docs.gitlab.com/ee/ci/yaml/

4. Start with gitlab CI/CD

Push the modified code to gitlab and see the build process in the project’s pipeline.

5. Dockerfile

TODO

6. Package the project into a Docker image

To be continued…

咕咕咕