Skip to content

Commit

Permalink
use prune
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Nov 29, 2023
1 parent c59f256 commit 125c19c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
24 changes: 1 addition & 23 deletions oci/private/image.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,6 @@ EOF
cat "${refs}"
}

# removes unreferenced blobs from oci-layout and normalizes index.json
function gc() {
local ref="$1"
local digest=$("${CRANE}" digest "${ref}")
local blobs=($("${CRANE}" manifest "${ref}" | "${JQ}" -r --arg digest "$digest" '([.layers[].digest] + [.config.digest, $digest]) | flatten | .[]'))
for blob_dir in ${STORAGE_DIR}/blobs/* ; do
local algo="$(basename ${blob_dir})"
for blob_path in ${blob_dir}/* ; do
local blob_digest="$(basename ${blob_path})"
local hash="${algo}:${blob_digest}"
if ! [[ "${blobs[@]}" =~ "$hash" ]]; then
rm $blob_path
fi
done
done
mv "${STORAGE_DIR}/index.json" "${STORAGE_DIR}/temp.json"
"${JQ}" --arg digest "$digest" '.manifests |= [map(select(.digest == $digest and .annotations == null))[0]]' "${STORAGE_DIR}/temp.json" > "${STORAGE_DIR}/index.json"
rm "${STORAGE_DIR}/temp.json"
}

# this will redirect stderr(2) to stderr file.
{
source "${REGISTRY_LAUNCHER}"
Expand Down Expand Up @@ -178,9 +158,7 @@ if [ ${#ENV_EXPANSIONS[@]} -ne 0 ]; then
fi

if [ -n "$OUTPUT" ]; then

"${CRANE}" pull "${REF}" "./${OUTPUT}" --format=oci
gc "${REF}"
"${CRANE}" pull "${REF}" "./${OUTPUT}" --format=oci --prune
stop_registry "${STORAGE_DIR}"
fi

Expand Down
2 changes: 1 addition & 1 deletion oci/private/registry/zot_launcher.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ EOF

function stop_registry() {
local storage_dir="$1"
rm -r "${storage_dir}/.uploads"
rm -rf "${storage_dir}/.uploads"
rm -r "${storage_dir}/config.json"
}

0 comments on commit 125c19c

Please sign in to comment.