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 2aa025cf authored by Christophe Chaudier's avatar Christophe Chaudier :rocket:
Browse files

feat: autoclean tmp container image on MR

parent 6bf76dd0
No related branches found
No related tags found
No related merge requests found
...@@ -15,3 +15,56 @@ ...@@ -15,3 +15,56 @@
container:build: container:build:
extends: .container:build extends: .container:build
stage: package stage: package
# Purge of tempory images
# docs :
# - 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
#
# This job prune the container's tmp images
# - merge trigger : delete all images of the merged branch
container:purge:
extends: .base_tpl
image: buildpack-deps:buster-curl
stage: clean
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables:
REG_SHA256: ade837fc5224acd8c34732bf54a94f579b47851cc6a7fd5899a98386b782e228
REG_VERSION: 0.16.1
REG_OPTS: "-d --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: |
if (echo ${CI_COMMIT_TITLE} | grep "Merge branch '.*' into 'master'"); then
echo "It's a merge commit \o/"
SOURCE_BRANCH=$(echo $CI_COMMIT_TITLE | cut -d "'" -f 2)
echo "Source branch of the merge ${SOURCE_BRANCH}"
# Namespace
container_namespace="${CI_PROJECT_PATH}/branch-${SOURCE_BRANCH//\//_}"
# Image Name
if [[ -n "${IMAGE_NAME}" ]]; then
container_image_name="/${IMAGE_NAME}"
else
container_image_name=""
fi
full_image_name=${container_namespace}${container_image_name}
# Clean Repository
echo "🧹 Clean tmp images"
echo " 🏭 registry : ${CI_REGISTRY}"
echo " 📦 name : ${full_image_name}"
for tag in $(reg tags ${REG_OPTS} ${full_image_name}); do
echo " 🏷️ tags : ${tag}"
reg rm ${REG_OPTS} ${full_image_name}:${tag}
done
else
echo "Nothing to purge in the GitLab container registry !"
fi
...@@ -6,6 +6,7 @@ stages: ...@@ -6,6 +6,7 @@ stages:
- test - test
- delivery - delivery
- deploy - deploy
- clean
variables: variables:
working_directory: "${CI_PROJECT_DIR}" working_directory: "${CI_PROJECT_DIR}"
...@@ -17,6 +18,9 @@ variables: ...@@ -17,6 +18,9 @@ variables:
JAVA_VERSION: "11" JAVA_VERSION: "11"
JDK_TYPE: "openjdk" JDK_TYPE: "openjdk"
CONTAINER_CACHE_TTL: 6h CONTAINER_CACHE_TTL: 6h
CI_DEBUG_TRACE: "false"
# true for activate CI debug tracing
# /!\ removed soon /!\ # /!\ removed soon /!\
......
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