Images de base — GitLab CI
Ce guide présente un pipeline GitLab CI prêt pour la production pour un dépôt base-images.
Structure du dépôt
Section intitulée « Structure du dépôt »base-images/├── imglife.yaml # configuration imglife├── eol-data.yaml # cache EOL (géré par CI)├── README.md # rapport d'état (géré par CI)├── images/│ ├── alpine/│ │ └── Dockerfile.tmpl│ └── golang/│ └── Dockerfile.tmpl└── .gitlab-ci.ymlLe pipeline
Section intitulée « Le pipeline »workflow: rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - if: $CI_PIPELINE_SOURCE == "schedule" - if: $CI_PIPELINE_SOURCE == "web"
variables: IMGLIFE_IMAGE: registry.gitlab.com/imglife-project/imglife:latest IMGLIFE_LOG_FORMAT: text
stages: - sync - build - eol-update - status - cleanup
# ── Synchronisation des miroirs ───────────────────────────────────────────────
sync: stage: sync image: $IMGLIFE_IMAGE script: - imglife sync rules: - if: $CI_PIPELINE_SOURCE == "schedule" - if: $CI_PIPELINE_SOURCE == "web"
# ── Construction des images de base ──────────────────────────────────────────# Option A : docker:dind standard (nécessite un runner privilégié)
build-dind: stage: build image: $IMGLIFE_IMAGE services: - docker:26-dind variables: DOCKER_TLS_CERTDIR: /certs before_script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY" - docker buildx create --name imglife-builder --use --bootstrap script: - imglife build rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# Option B : BuildKit rootless (pas de runner privilégié)# Décommentez et configurez BUILDKITD_ADDR dans l'environnement du runner
# build-rootless:# stage: build# image: $IMGLIFE_IMAGE# script:# - imglife build# variables:# DOCKER_HOST: unix:///run/buildkit/buildkitd.sock# IMGLIFE_BUILDER: "" # utiliser le CLI docker par défaut# rules:# - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# Option C : output-dir + Kaniko (pas de socket Docker requis)# build-kaniko:# stage: build# image: $IMGLIFE_IMAGE# script:# - imglife build --output-dir /tmp/contexts# - |# for dir in /tmp/contexts/*/; do# [ -f "$dir/build.json" ] || continue# tag=$(jq -r .tag "$dir/build.json")# /kaniko/executor \# --context "dir://$dir" \# --destination "$tag"# done# rules:# - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# ── Mise à jour des données EOL (planification hebdomadaire recommandée) ─────
eol-update: stage: eol-update image: $IMGLIFE_IMAGE before_script: - git config user.email "ci-bot@$CI_SERVER_HOST" - git config user.name "CI Bot" - git remote set-url origin "https://oauth2:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" script: - imglife eol update - | if git diff --quiet eol-data.yaml; then echo "Données EOL inchangées." else git add eol-data.yaml git commit -m "chore(lifecycle): update EOL data [skip ci]" git push origin HEAD:$CI_DEFAULT_BRANCH fi rules: - if: $CI_PIPELINE_SOURCE == "schedule"
# ── Génération du rapport d'état ──────────────────────────────────────────────
status: stage: status image: $IMGLIFE_IMAGE before_script: - git config user.email "ci-bot@$CI_SERVER_HOST" - git config user.name "CI Bot" - git remote set-url origin "https://oauth2:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" script: - imglife status --output README.md - | if git diff --quiet README.md; then echo "Statut inchangé." else git add README.md git commit -m "chore(status): update image status report [skip ci]" git push origin HEAD:$CI_DEFAULT_BRANCH fi rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - if: $CI_PIPELINE_SOURCE == "schedule"
# ── Nettoyage ────────────────────────────────────────────────────────────────# APP_PURGE_KEEP : nombre de build records récents à conserver par projet (défaut : 3).# CLEANUP_DRY_RUN=true : simule les deux commandes sans supprimer.
cleanup: stage: cleanup image: $IMGLIFE_IMAGE variables: CLEANUP_DRY_RUN: "false" APP_PURGE_KEEP: "3" script: - | ARGS="" [ "$CLEANUP_DRY_RUN" = "true" ] && ARGS="--dry-run" imglife app purge --keep "$APP_PURGE_KEEP" $ARGS imglife cleanup $ARGS rules: - if: $CI_PIPELINE_SOURCE == "schedule" when: manual allow_failure: trueVariables CI à configurer
Section intitulée « Variables CI à configurer »Dans GitLab, allez dans Paramètres > CI/CD > Variables :
| Variable | Description | Protégée | Masquée |
|---|---|---|---|
GITLAB_TOKEN |
PAT GitLab avec scopes api, read_packages, write_packages, read_registry, write_registry |
Oui | Oui |
IMGLIFE_DOCKER_IO_USERNAME |
Identifiant Docker Hub (pour éviter le rate limiting) | Non | Non |
IMGLIFE_DOCKER_IO_PASSWORD |
Mot de passe ou token Docker Hub | Oui | Oui |
Le token de job CI (CI_JOB_TOKEN) est utilisé automatiquement pour le registry OCI. GITLAB_TOKEN est nécessaire pour les git push (commits status/EOL) et les opérations Package Registry.
imglife.yaml pour ce pipeline
Section intitulée « imglife.yaml pour ce pipeline »registry: url: https://gitlab.example.com project_id: 42
sync: entries: - source: docker.io/library/alpine tag_regex: '^3\.\d+\.\d+$' keep_last: 3 target: $CI_REGISTRY/mirrors/alpine lifecycle: product: alpine track: minor
- source: docker.io/library/golang tag_regex: '^1\.\d+\.\d+-alpine3\.\d+$' keep_last: 2 target: $CI_REGISTRY/mirrors/golang lifecycle: product: go track: minor
build: core_version: "1.0.0" registry: $CI_REGISTRY/bases platforms: [linux/amd64, linux/arm64]
images: - name: alpine folder: images/alpine type: core mirror_image: $CI_REGISTRY/mirrors/alpine mirror_tag: "3.21.3" version: "3.21.3"
- name: golang folder: images/golang type: core mirror_image: $CI_REGISTRY/mirrors/golang mirror_tag: "1.22.3-alpine3.21" version: "1.22.3-alpine3.21"
retention: keep_last: 5 max_age_days: 90
lifecycle: eol_provider: endoflife eol_target: git eol_data_file: eol-data.yaml
status: client_zone: | Le pipeline tourne tous les jours à 06:00 UTC. Contactez `#platform-images` pour toute question.Pipeline planifié
Section intitulée « Pipeline planifié »Créez une planification dans CI/CD > Schedules pour exécuter le pipeline quotidiennement ou hebdomadairement :
- Quotidien à 06:00 UTC : exécute
sync,eol-update,status - Hebdomadaire : exécute
cleanup(ou déclenchement manuel après vérification de la sortie--list)
Configuration multi-arch
Section intitulée « Configuration multi-arch »Pour les builds multi-architecture avec docker:dind, assurez-vous que votre runner GitLab a QEMU enregistré :
before_script: - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - docker buildx create --name imglife-builder --use --bootstrapOu utilisez un runner linux/arm64 dédié ajouté au builder buildx — pas besoin de QEMU.