CI/CD, Docker, and Kubernetes
rib runs as an ordinary unprivileged process. A job needs no Docker socket,
Docker-in-Docker, privileged container, or access to the node’s container
runtime. This applies to shell, Docker, and Kubernetes executors.
A practical build image contains the application’s compiler/runtime, rib or
cargo-rib, and pipeline tools such as cosign and the Vault CLI. The runner
caches this image through its normal container mechanism; no separate build
daemon cache has to be transferred between jobs.
Building a frontend and signing with cosign
This GitLab job assumes that frontend contains built static files, the base
image contains execenv and static-web-server, the job image contains
rib, Vault, and cosign, and Vault has the corresponding JWT role and
Transit key.
default:
tags:
- core-os
stages:
- Build
build_image_rib:
image: registry.gitlab.com/devdsk/education/rust/rib/rib:v0.1.0
stage: Build
id_tokens:
VAULT_ID_TOKEN:
aud: https://gitlab.com
variables:
VAULT_AUTH_PATH: auth/jwt/login
VAULT_AUTH_ROLE: cosign
TRANSIT_SECRET_ENGINE_PATH: cosign
VAULT_ADDR: https://vault.core-os.ru
COSIGN_KEY: hashivault://cosign
HOME: /tmp
script:
- |
IMAGE_DIGEST="$(
rib build \
--from "$CI_REGISTRY_IMAGE/frontend-base:1.0" \
--credential "$CI_REGISTRY=$CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD" \
--copy "./frontend:/frontend,chown=65532:65532" \
--entrypoint "/execenv -m error -f /frontend/config.js --exec /static-web-server -p 8787 -d /frontend -g info" \
--to "registry:$CI_REGISTRY_IMAGE/taskd-frontend:$CI_COMMIT_SHORT_SHA"
)"
- |
VAULT_TOKEN="$(
vault write --field=token "$VAULT_AUTH_PATH" \
role="$VAULT_AUTH_ROLE" \
jwt="$VAULT_ID_TOKEN"
)"
export VAULT_TOKEN
- cosign login "$CI_REGISTRY" -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD"
- >
cosign sign --tlog-upload=false
"${CI_REGISTRY_IMAGE}/taskd-frontend@${IMAGE_DIGEST}"
Progress stays visible on stderr, while IMAGE_DIGEST receives only
sha256:...; cosign signs the immutable manifest rather than a mutable tag.
There is no preliminary base pull. Because source and target use one GitLab
registry, inherited blobs can be reused or mounted without passing through the
job filesystem.
Building a Rust project through Cargo integration
Include cargo-rib in an image that already contains the Rust toolchain and
the x86_64-unknown-linux-musl target. GitLab caches the builder image, while
the Cargo registry and target use the standard CI cache.
default:
tags:
- core-os
variables:
CARGO_HOME: "$CI_PROJECT_DIR/.cargo"
stages:
- Build
cache:
key:
files:
- Cargo.lock
prefix: "$CI_COMMIT_REF_SLUG"
paths:
- .cargo/registry/index/
- .cargo/registry/cache/
- .cargo/git/db/
- target/
build_image_rib:
image: registry.gitlab.com/devdsk/education/rust/taskd/rust-builder/rust-rib:alpine3.24
stage: Build
script:
- >
cargo rib build
--credential "$CI_REGISTRY=$CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD"
--to "registry:$CI_REGISTRY_IMAGE/taskd:$CI_COMMIT_SHORT_SHA"
Image parameters live next to the source in Cargo.toml. This example passes
--to because its tag is generated by the pipeline; a fixed destination can
instead use metadata to.
[package]
name = "taskd"
version = "0.1.0"
edition = "2021"
rust-version = "1.94"
[package.metadata.rib]
artifact = "target/x86_64-unknown-linux-musl/release/taskd"
platform = "linux/amd64"
from = "scratch"
destination = "/taskd"
entrypoint = "/taskd"
workdir = "/"
user = "65532:65532"
ports = ["8080"]
creation-time = "epoch"
jobs = 4
cargo-args = [
"--release",
"--locked",
"--target", "x86_64-unknown-linux-musl",
]
cargo rib build runs Cargo, verifies the artifact, adds it last with mode
0755, and publishes the image. A scratch artifact must be statically linked
or accompanied by all runtime dependencies through copies.
Running in a Kubernetes executor
With GitLab Runner’s Kubernetes executor, these jobs require no custom
Kubernetes manifest. The runner creates an ordinary pod from the selected job
image. Configure only normal resource requests and limits, network access to
the registries and secret services, and sufficient emptyDir/ephemeral storage
for Cargo outputs, temporary layers, and archives. No host paths, Docker socket,
or privileged security context are required.