|
| 1 | +--- |
| 2 | +title: "GitLab CI" |
| 3 | +description: "Demo running GitLab CI with Imageless Kubernetes" |
| 4 | +--- |
| 5 | + |
| 6 | +You can use Imageless Kubernetes in many applications where you would rely on a conventional image-based workflow. |
| 7 | + |
| 8 | +This example shows how you can use Imageless Kubernetes with GitLab CI, running jobs inside of the same Flox environment you use for development. |
| 9 | + |
| 10 | +## GitLab runner configuration |
| 11 | + |
| 12 | +To configure your GitLab runner to run Imageless Kubernetes pods, add this section to the runner's `config.toml`: |
| 13 | + |
| 14 | +```toml |
| 15 | +[[runners]] |
| 16 | + [runners.kubernetes] |
| 17 | + namespace = {% raw %}"{{ default .Release.Namespace .Values.runners.jobNamespace }}"{% endraw %} |
| 18 | + runtime_class_name = "flox" |
| 19 | + image = "flox/empty:1.0.0" |
| 20 | + pod_annotations_overwrite_allowed = '^flox\.dev.*' |
| 21 | + [runners.kubernetes.pod_annotations] |
| 22 | + "flox.dev/skip-containers" = "init-permissions,helper" |
| 23 | + "flox.dev/skip-containers-exec" = "build" |
| 24 | + "flox.dev/activate-mode" = "dev" # optional |
| 25 | +``` |
| 26 | + |
| 27 | +!!! note "Note" |
| 28 | + These options can also be passed as part of the job definition in `.gitlab-ci.yml`, see the [GitLab documentation][gitlab-k8s-docs] for more details. |
| 29 | + |
| 30 | +These settings will start all GitLab job pods using the Flox runtime, with an empty container image, and allow setting additional annotations (e.g. `flox.dev/environment`) on a per-job basis. |
| 31 | + |
| 32 | +The `flox.dev/skip-containers` and `flox.dev/skip-containers-exec` annotations are necessary to allow GitLab's init containers to get the code and job script into build container for execution. |
| 33 | + |
| 34 | +`flox.dev/activate-mode` is set to make build dependencies available to the job script. |
| 35 | + |
| 36 | +See the [configuration][config] page for more details on annotations. |
| 37 | + |
| 38 | +## GitLab job configuration |
| 39 | + |
| 40 | +Once you've configured the runner, you will need to supply each job with the desired `flox.dev/environment` annotation, which can be done in `.gitlab-ci.yml`: |
| 41 | + |
| 42 | +```yaml |
| 43 | +stages: |
| 44 | + - hello |
| 45 | + |
| 46 | +hello-job: |
| 47 | + stage: hello |
| 48 | + variables: |
| 49 | + KUBERNETES_POD_ANNOTATIONS_1: "flox.dev/environment=flox/hello" |
| 50 | + script: |
| 51 | + - hello |
| 52 | +``` |
| 53 | +
|
| 54 | +where the value of the annotation is the name of an environment from [FloxHub][floxhub]. |
| 55 | +
|
| 56 | +!!! note "Note" |
| 57 | + The `flox.dev/environment` annotation is *not* optional -- pods will fail to start if it is not supplied. |
| 58 | + |
| 59 | +## Conclusion |
| 60 | + |
| 61 | +Now, any job you target to this runner will be executed with Imageless Kubernetes. |
| 62 | + |
| 63 | +If you utilize the same Flox environment used for development, you will be able to seamlessly test with the exact same packages, regardless of what system or architecture is used. |
| 64 | + |
| 65 | +Since the CI environment doesn’t rely on a container image, updates are instant: run `flox push`, and the job will pick up the changes automatically. |
| 66 | + |
| 67 | +[gitlab-k8s-docs]: https://docs.gitlab.com/runner/executors/kubernetes/ |
| 68 | +[config]: ../config.md |
| 69 | +[floxhub]: ../../concepts/floxhub.md |
0 commit comments