From 37eb951c89c2a65a42ef48c4c0a442dbb7ebdfb4 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Fri, 28 Dec 2018 19:51:48 -0500 Subject: [PATCH] remove clean registry Signed-off-by: Jess Frazelle --- clean-registry/Dockerfile | 15 ------- clean-registry/clean-registry | 74 ----------------------------------- 2 files changed, 89 deletions(-) delete mode 100644 clean-registry/Dockerfile delete mode 100755 clean-registry/clean-registry diff --git a/clean-registry/Dockerfile b/clean-registry/Dockerfile deleted file mode 100644 index 20d017a..0000000 --- a/clean-registry/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM r.j3ss.co/reg as reg -FROM jess/gcloud - -RUN apk add --no-cache \ - ca-certificates \ - bash \ - jq \ - parallel - -WORKDIR /root - -COPY clean-registry /usr/bin/clean-registry -COPY --from=reg /usr/bin/reg /usr/bin/reg - -ENTRYPOINT ["clean-registry"] diff --git a/clean-registry/clean-registry b/clean-registry/clean-registry deleted file mode 100755 index 7b9884a..0000000 --- a/clean-registry/clean-registry +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash -############################################################################## -# clean-registry -# ----------- -# Deletes old registry blobs that are not used in the latest version of the tag. -# This script assumes your registry is hosted on Google Cloud Storage. -# -# Usage: -# clean-registry -# -# :authors: Jess Frazelle, @jessfraz -# :date: 20 September 2016 -# :version: 0.0.1 -############################################################################## -set -e -set -o pipefail - -REPO_URL="${REPO_URL:-r.j3ss.co}" -BUCKET_PREFIX="gs://${REPO_URL}/docker/registry/v2" -JOBS=${JOBS:-10} - -# get the repos -mapfile -t repos < <(gsutil ls "${BUCKET_PREFIX}/repositories/" | awk -F"/" '{print $(NF-1)}') - -for repo in "${repos[@]}"; do - # get the tags - mapfile -t tags < <(gsutil ls "${BUCKET_PREFIX}/repositories/${repo}/_manifests/tags/" | awk -F"/" '{print $(NF-1)}') - - for tag in "${tags[@]}"; do - echo "repo: $repo | tag: $tag" - - # get the latest index for the tag - current=$(gsutil cat "${BUCKET_PREFIX}/repositories/${repo}/_manifests/tags/${tag}/current/link" || true) - if [[ "$current" == "true" ]]; then - # continue the loop since we cannot cat - continue - fi - # split on : since the link comes back as: - # sha256:97bf033cf680a2fe49a6f0df40ac76dba97bc71745aeb06018dbf9df5de74bd6 - ha=${current%:*} - id=${current#*:} - - # get the manifest - manifest=$(gsutil cat "${BUCKET_PREFIX}/blobs/sha256/${id:0:2}/${id}/data" || true) - if [[ "$manifest" == "true" ]]; then - # continue the loop since we cannot cat - continue - fi - manifest_media_type=$(echo "${manifest}" | jq -r '.mediaType') - echo "media-type: $manifest_media_type" - - - if [ "${manifest_media_type}" == "application/vnd.docker.distribution.manifest.list.v2+json" ] ; then - # we have a manifest list and fetch the referenced manifests - mapfile -t additional_manifests < <(echo "${manifest}" | jq -r '.["manifests"] | .[].digest' | cut -d: -f2) - - echo "additional_manifests: ${additional_manifests[*]}" - fi - - echo "repo: $repo | tag: $tag | current: ${ha}:${id}" - - # get the shas - mapfile -t shas < <(gsutil ls "${BUCKET_PREFIX}/repositories/${repo}/_manifests/tags/${tag}/index/${ha}/" | awk -F"/" '{print $(NF-1)}') - - # remove the current sha - shas=( "${shas[@]/$id}" ) - - # shellcheck disable=SC2199 - if [[ "${shas[@]}" != "" ]] && [[ ! -z "${shas[@]}" ]]; then - echo "[to be removed]: ${shas[*]}" - #parallel -j"${JOBS}" reg rm "${REPO_URL}/${repo}@${ha}:{1}" ::: "${shas[@]}" || true - fi - done -done