GitLab CI

Topics: GitLab, Continuous integration

GitLab CI/CD runs jobs in pipelines to build, test, and deploy software.

Deploy token

A deploy token created on the repository scope (Settings/Repository/Deploy Tokens) with the name gitlab-deploy-token will automatically be available in CI runs.

Kubernetes registry token

If Gitlab has management access to the k8s cluster, we can create the token k8s needs to pull Docker images right from the CI job:

kubectl create secret docker-registry regcred \
  --docker-server=$CI_REGISTRY \\
  --docker-username="$CI_DEPLOY_USER" \\
  --docker-password="$CI_DEPLOY_PASSWORD" \\
  --docker-email="$GITLAB_USER_EMAIL" --dry-run=true -o yaml | kubectl apply -f -

(Since kubectl create would stop working after the first CI run, we’re taking the roundabout way via dry-run and apply.)

Caching

Caching build artefacts is important to speed up CI runs.

Docker cleanup

When running a Docker-based Gitlab Runner, execute docker system prune regularly (e.g. via /etc/cron.weekly) to free up disk space.

Bookmarks