GitLab CI/CD
Table of Content
GitLab CI/CD¶
[[GitLab CI/CD]]
https://docs.gitlab.com/ee/ci/
CI/CD is a continuous method of software development, where you continuously build, test, deploy, and monitor iterative code changes.
This iterative process helps reduce the chance that you develop new code based on buggy or failed previous versions. GitLab CI/CD can catch bugs early in the development cycle, and help ensure that all the code deployed to production complies with your established code standards.
I have self-managed GitLab running in my environment, so what I need to use GitLab CI/CD are:
- GitLab server
- GitLab Runner registered to the GitLab
- GitLab project with GitLab Runner assigned
./.gitlab-ci.yaml
file in the project
[[GitLab Runner]] instances are workers periodically checking in with GitLab to look for jobs to do, and whenever a GitLab project gets a new push and there is a job recipe file ./.gitlab-ci.yaml
file, a runner instance takes it and does the work.
As also mentioned in MkDocs section, this site is generated and uploaded by GitLab CI/CD.
GitLab Runner¶
[[GitLab Runner]]
https://docs.gitlab.com/runner/
See [[building-home-lab-part-6]] for the deployment to Kubernetes cluster using Flux (GitOps) and helm.
building image¶
Use kaniko to build container images.
https://github.com/GoogleContainerTools/kaniko
kaniko is a tool to build container images from a Dockerfile, inside a container or Kubernetes cluster.
latest release¶
Go to the repository or run below to check the latest available version.
example .gitlab-ci.yml¶
variables:
KANIKO_CACHE_DIR: "/cache"
KANIKO_VERSION: "v1.22.0-debug"
VERSION: "0.1.1"
cache:
key: "$CI_COMMIT_REF_SLUG"
paths:
- "$KANIKO_CACHE_DIR"
stages:
- build
build:
stage: build
retry: 2
image:
name: $HARBOR_HOST/cache-gcrio/kaniko-project/executor:$KANIKO_VERSION
entrypoint: [""]
script:
- echo "{\"auths\":{\"$HARBOR_HOST\":{\"auth\":\"$(echo -n ${HARBOR_USERNAME}:${HARBOR_PASSWORD} | base64)\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor
--build-arg "HARBOR_HOST=$HARBOR_HOST"
--cache
--cache-dir /cache
--cache-copy-layers
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/build/Dockerfile"
--destination "${HARBOR_HOST}/${HARBOR_PROJECT}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}:${VERSION}"