Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit e1d269ba authored by Christophe Chaudier's avatar Christophe Chaudier :rocket:
Browse files

Merge branch '88-fix-container-clean' into 'master'

Resolve "fix container clean"

Closes #88

See merge request lydra/gitlab-ci-templates!64
parents 48bd83c9 320315a2
No related branches found
No related tags found
No related merge requests found
Pipeline #47602 failed
...@@ -24,32 +24,26 @@ container:build: ...@@ -24,32 +24,26 @@ container:build:
# docs : # docs :
# - https://docs.gitlab.com/ee/user/packages/container_registry/#delete-images # - https://docs.gitlab.com/ee/user/packages/container_registry/#delete-images
# - https://docs.gitlab.com/ee/user/packages/container_registry/#delete-images-using-gitlab-cicd # - https://docs.gitlab.com/ee/user/packages/container_registry/#delete-images-using-gitlab-cicd
# - https://github.com/genuinetools/reg # - https://github.com/google/go-containerregistry/blob/main/cmd/crane/doc/crane.md
# #
# This job prune the container's tmp images # This job prune the container's tmp images
# - merge trigger : delete all images of the merged branch # - merge trigger : delete all images of the merged branch
container:purge: container:purge:
extends: .base_tpl extends: .base_tpl
image: buildpack-deps:buster-curl image:
name: gcr.io/go-containerregistry/crane:debug
entrypoint: [""]
stage: clean stage: clean
rules: rules:
- if: $CI_COMMIT_TAG - if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables:
REG_SHA256: ade837fc5224acd8c34732bf54a94f579b47851cc6a7fd5899a98386b782e228
REG_VERSION: 0.16.1
REG_OPTS: "--insecure --auth-url ${CI_REGISTRY} -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD}"
before_script:
- >
curl --fail --show-error
--location "https://github.com/genuinetools/reg/releases/download/v$REG_VERSION/reg-linux-amd64"
--output /usr/local/bin/reg
- echo "$REG_SHA256 /usr/local/bin/reg" | sha256sum -c -
- chmod a+x /usr/local/bin/reg
- cd ${working_directory}
script: | script: |
set -e
echo "Authenticating with the container registry..."
crane auth login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
clean_images=false clean_images=false
if [[ -n "${CI_COMMIT_TAG}" ]]; then if [[ -n "${CI_COMMIT_TAG}" ]]; then
...@@ -81,9 +75,10 @@ container:purge: ...@@ -81,9 +75,10 @@ container:purge:
echo "🧹 Clean tmp images" echo "🧹 Clean tmp images"
echo " 🏭 registry : ${CI_REGISTRY}" echo " 🏭 registry : ${CI_REGISTRY}"
echo " 📦 name : ${full_image_name}" echo " 📦 name : ${full_image_name}"
for tag in $(reg tags ${REG_OPTS} ${full_image_name} | grep ${container_base_tag}); do
for tag in $(crane ls ${full_image_name} | grep ${container_base_tag}); do
echo " 🏷️ tags : ${tag}" echo " 🏷️ tags : ${tag}"
reg rm ${REG_OPTS} ${full_image_name}:${tag} crane delete ${CI_REGISTRY}/${full_image_name}:${tag}
done done
else else
echo "Nothing to purge in the GitLab container registry !" echo "Nothing to purge in the GitLab container registry !"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment