From 50bb6b83ea3f56da78a6c655e56a9b88605d2eca Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Tue, 24 Oct 2023 18:17:41 +0200 Subject: [PATCH] refactor: simplify repotags processing (#401) --- oci/private/tarball.sh.tpl | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/oci/private/tarball.sh.tpl b/oci/private/tarball.sh.tpl index dff94b6d..9bbc3788 100644 --- a/oci/private/tarball.sh.tpl +++ b/oci/private/tarball.sh.tpl @@ -6,7 +6,7 @@ readonly YQ="{{yq}}" readonly IMAGE_DIR="{{image_dir}}" readonly BLOBS_DIR="${STAGING_DIR}/blobs" readonly TARBALL_PATH="{{tarball_path}}" -readonly TAGS_FILE="{{tags}}" +readonly REPOTAGS=($(cat "{{tags}}")) MANIFEST_DIGEST=$(${YQ} eval '.manifests[0].digest | sub(":"; "/")' "${IMAGE_DIR}/index.json" | tr -d '"') MANIFEST_BLOB_PATH="${IMAGE_DIR}/blobs/${MANIFEST_DIGEST}" @@ -23,15 +23,11 @@ for LAYER in $(${YQ} ".[]" <<< $LAYERS); do cp -f "${IMAGE_DIR}/blobs/${LAYER}" "${BLOBS_DIR}/${LAYER}.tar.gz" done -# Replace newlines (unix or windows line endings) with % character. -# We can't pass newlines to yq due to https://github.com/mikefarah/yq/issues/1430 and -# we can't update YQ at the moment because structure_test depends on a specific version: -# see https://github.com/bazel-contrib/rules_oci/issues/212 -repo_tags="$(tr -d '\r' < "${TAGS_FILE}" | tr '\n' '%')" \ +repo_tags="${REPOTAGS[@]}" \ config="blobs/${CONFIG_DIGEST}" \ layers="${LAYERS}" \ "${YQ}" eval \ - --null-input '.[0] = {"Config": env(config), "RepoTags": "${repo_tags}" | envsubst | split("%") | map(select(. != "")) , "Layers": env(layers) | map( "blobs/" + . + ".tar.gz") }' \ + --null-input '.[0] = {"Config": env(config), "RepoTags": "${repo_tags}" | envsubst | split(" ") | map(select(. != "")) , "Layers": env(layers) | map( "blobs/" + . + ".tar.gz") }' \ --output-format json > "${STAGING_DIR}/manifest.json" # TODO: https://github.com/bazel-contrib/rules_oci/issues/217