Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
Merge branch '2019.11' into 2020.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins committed Dec 1, 2020
2 parents db4a4fe + 480264e commit 932ffe3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
18 changes: 17 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ stages:
- test
- deploy
- housekeeping
- housekeeping-cleanup

workflow:
rules:
Expand Down Expand Up @@ -339,4 +340,19 @@ docker_populate_cache:
- docker_populate_cache built
- docker_populate_cache test-built
- docker_populate_cache dev
allow_failure: true

docker_cleanup_images:
extends: .abstract_jobs.docker
stage: housekeeping-cleanup
script:
- docker_untag_image base-commit $CI_PIPELINE_ID-$PHP_IMAGE_TAG || true
- docker_untag_image source-commit $CI_PIPELINE_ID-$PHP_IMAGE_TAG || true
- docker_untag_image test-source-commit $CI_PIPELINE_ID-$PHP_IMAGE_TAG || true
- docker_untag_image build-commit $CI_PIPELINE_ID-$PHP_IMAGE_TAG || true
- docker_untag_image built-commit $CI_PIPELINE_ID-$PHP_IMAGE_TAG || true
- docker_untag_image test-built-commit $CI_PIPELINE_ID-$PHP_IMAGE_TAG || true
- docker_untag_image dev-commit $CI_PIPELINE_ID-$PHP_IMAGE_TAG || true
rules:
- if: $DOCKER_CLEANUP_IMAGES == "true"
when: always
- when: never
4 changes: 2 additions & 2 deletions ci/abstract_jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@
- docker:19.03.1-dind
image: $REGISTRY/docker:19.03.1
before_script:
- source ci/build.sh
- source ci/functions.sh
- export DOCKER_BUILDKIT=0
- export PROGRESS_NO_TRUNC=1 # stop docker from truncating aws image names
- login
- docker_login


# merge job for customapps
Expand Down
19 changes: 17 additions & 2 deletions ci/build.sh → ci/functions.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# defines function to be used by the ci

function login() {
if [ ! -z "${REGISTRY_USER}" ] && [ ! -z "${REGISTRY_PASSWORD}" ]; then
function docker_login() {
if [ ! -z "${REGISTRY_USER}" ] && [ ! -z "${REGISTRY_PASSWORD}" ]; then
echo docker login ...
docker login "${REGISTRY}" --username "${REGISTRY_USER}" --password "${REGISTRY_PASSWORD}"
else
Expand Down Expand Up @@ -162,4 +162,19 @@ function tag_image() {
docker pull "${FROM_IMAGE}"
docker tag "${FROM_IMAGE}" "${DESTINATION_IMAGE}"
docker push "${DESTINATION_IMAGE}"
}

function docker_untag_image() {
image=$1
tag=$2

digest=$(curl -X HEAD -I -v --user ${REGISTRY_USER}:${REGISTRY_PASSWORD} -H "Accept: application/vnd.docker.distribution.manifest.v2+json" https://${REGISTRY}/v2/${image}/manifests/${tag} | awk 'BEGIN {FS=": "}/^docker-content-digest/{print $2}' | tr -d '\r' )
if [ -z ${digest} ]; then
return 1
fi

docker pull ${REGISTRY}/cleanup-manifest:latest
docker tag ${REGISTRY}/cleanup-manifest:latest ${REGISTRY}/${image}:${tag}

curl -X DELETE -v --user ${REGISTRY_USER}:${REGISTRY_PASSWORD} https://${REGISTRY}/v2/${image}/manifests/${digest}
}

0 comments on commit 932ffe3

Please sign in to comment.