Convert Docker registry cleanup job to manual mode

We no longer want to build periodically CCP Docker images with BUILD_NUMBER
as tag so we don't need automatic purge of old tags.
But sometimes it's useful to manually remove some unwanted tags.
This job is now meant to be run manually and accepts a parameter from
Jenkins web-ui which allows for selecting which tags should be deleted
(by regular expression).

Change-Id: I43b35e8cc8ba17fe22ba8014065938d32286c600
This commit is contained in:
Marek Zawadzki 2016-09-29 11:02:50 +02:00
parent 62df710fc8
commit 95e0fcbab0
3 changed files with 12 additions and 8 deletions

View File

@ -7,13 +7,14 @@
# CONFIGURATION:
######################################################
: ${LEAVE_LAST_RECENT_TAGS:="6"}
: ${DOCKER_NAMESPACE:="mcp"}
: ${DOCKER_REGISTRY:="registry.mcp.fuel-infra.org"}
REGISTRY_MANAGER="registry-manage --host ${DOCKER_REGISTRY}"
TAG_REGEXP=${PARAM_TAG_REGEXP}
[[ ! ${LEAVE_LAST_RECENT_TAGS} =~ ^[0-9]+$ ]] && exit 1
# List all tags for all images, select and delete tags matching TAG_REGEXP:
#
# Sample output from registry-manage tool:
# "list" subcommand:
# mcp/base
@ -29,7 +30,8 @@ REGISTRY_MANAGER="registry-manage --host ${DOCKER_REGISTRY}"
# new
for image in `${REGISTRY_MANAGER} list | grep "^${DOCKER_NAMESPACE}/"`; do
${REGISTRY_MANAGER} list-tags ${image} | \
grep "^[0-9]\+$" | sort -rn | tail -n +`expr ${LEAVE_LAST_RECENT_TAGS} + 1` | \
awk -v REGISTRY_MANAGER="${REGISTRY_MANAGER}" -v image=${image} \
'$1 ~ /^[0-9]+$/ {exit system(REGISTRY_MANAGER" delete "image":"$1);}'
grep "${TAG_REGEXP}" | \
awk -v REGISTRY_MANAGER="${REGISTRY_MANAGER}" -v image="${image}" \
-v TAG_REGEXP="${TAG_REGEXP}" \
'$1 ~ TAG_REGEXP {exit system(REGISTRY_MANAGER" delete "image":"$1);}'
done

View File

@ -46,12 +46,15 @@
- job-template:
name: mcp-clean-docker-registry
description: |
Remove old tags from MCP Docker registry.
Manual job for removing selected tags from MCP Docker registry.
node: standard
parameters:
- text:
name: PARAM_TAG_REGEXP
description: "Tag (regexp) to delete for all images in mcp namespace"
builders:
- inject:
properties-content: |
LEAVE_LAST_RECENT_TAGS=6
DOCKER_REGISTRY=registry.mcp.fuel-infra.org
DOCKER_NAMESPACE=mcp
- shell:

View File

@ -132,4 +132,3 @@ projects:
- update-jenkins-jobs
periodic:
- 'mcp-build-images-smoke'
- 'mcp-clean-docker-registry'