From 2a345dc0508f3148f3f0de0e768655a7f7244ac6 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Tue, 2 May 2023 17:37:35 -0700 Subject: [PATCH 1/7] Add missing test case for oci_tarball#repotags --- e2e/smoke/BUILD.bazel | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/e2e/smoke/BUILD.bazel b/e2e/smoke/BUILD.bazel index 65a632ca..9813b537 100644 --- a/e2e/smoke/BUILD.bazel +++ b/e2e/smoke/BUILD.bazel @@ -1,3 +1,5 @@ +load("@aspect_bazel_lib//lib:testing.bzl", "assert_json_matches") +load("@bazel_skylib//rules:write_file.bzl", "write_file") load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball", "structure_test") oci_image( @@ -17,10 +19,15 @@ oci_image( os = "linux", ) +tags = [ + "my/image:some-tag", + "my/image:latest", +] + oci_tarball( name = "tar", image = ":image", - repotags = [], + repotags = tags, ) structure_test( @@ -29,3 +36,22 @@ structure_test( driver = "tar", image = ":tar", ) + +filegroup( + name = "tar_manifest", + srcs = [":tar"], + output_group = "manifest", +) + +write_file( + name = "expected_RepoTags", + out = "expected_RepoTags.json", + content = [str(tags)], +) + +assert_json_matches( + name = "check_tags", + file1 = ":tar_manifest", + file2 = ":expected_RepoTags", + filter1 = ".[0].RepoTags", +) From d603718d2377339a64c6c69bc6196ca47a83c435 Mon Sep 17 00:00:00 2001 From: thesayyn Date: Wed, 3 May 2023 15:21:03 -0700 Subject: [PATCH 2/7] make it genrule --- e2e/smoke/BUILD.bazel | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/e2e/smoke/BUILD.bazel b/e2e/smoke/BUILD.bazel index f3029446..4f04983b 100644 --- a/e2e/smoke/BUILD.bazel +++ b/e2e/smoke/BUILD.bazel @@ -38,10 +38,11 @@ container_structure_test( image = ":tar", ) -filegroup( +genrule( name = "tar_manifest", srcs = [":tar"], - output_group = "manifest", + outs = ["manifest.json"], + cmd = "tar -xOzf ./$(location :tar) ./manifest.json > $@" ) write_file( From 95a918795bcb5f4575e32a9f5d86c88704fcbff5 Mon Sep 17 00:00:00 2001 From: thesayyn Date: Wed, 3 May 2023 15:47:40 -0700 Subject: [PATCH 3/7] change delimiter --- oci/private/tarball.sh.tpl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/oci/private/tarball.sh.tpl b/oci/private/tarball.sh.tpl index 7b0f8f2d..372bf188 100644 --- a/oci/private/tarball.sh.tpl +++ b/oci/private/tarball.sh.tpl @@ -25,8 +25,10 @@ for LAYER in $(${YQ} ".[]" <<< $LAYERS); do done config="blobs/${CONFIG_DIGEST}" \ -repotags="${REPOTAGS}" \ +# TODO: can't use \n 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 +repotags="${REPOTAGS/$'\n'/\%}" \ layers="${LAYERS}" \ "${YQ}" eval \ - --null-input '.[0] = {"Config": strenv(config), "RepoTags": strenv(repotags) | split("\n"), "Layers": env(layers) | map( "blobs/" + . + ".tar.gz") }' \ + --null-input '.[0] = {"Config": strenv(config), "RepoTags": "${repotags}" | envsubst | split("\%"), "Layers": env(layers) | map( "blobs/" + . + ".tar.gz") }' \ --output-format json > "${TARBALL_MANIFEST_PATH}" From e4ea6c8e3169142e0390f499587879d5a293d88e Mon Sep 17 00:00:00 2001 From: thesayyn Date: Wed, 3 May 2023 15:51:19 -0700 Subject: [PATCH 4/7] fix --- e2e/smoke/BUILD.bazel | 2 +- oci/private/tarball.sh.tpl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/e2e/smoke/BUILD.bazel b/e2e/smoke/BUILD.bazel index 4f04983b..82d6ce5f 100644 --- a/e2e/smoke/BUILD.bazel +++ b/e2e/smoke/BUILD.bazel @@ -42,7 +42,7 @@ genrule( name = "tar_manifest", srcs = [":tar"], outs = ["manifest.json"], - cmd = "tar -xOzf ./$(location :tar) ./manifest.json > $@" + cmd = "tar -xOf ./$(location :tar) ./manifest.json > $@", ) write_file( diff --git a/oci/private/tarball.sh.tpl b/oci/private/tarball.sh.tpl index 372bf188..9ab9e544 100644 --- a/oci/private/tarball.sh.tpl +++ b/oci/private/tarball.sh.tpl @@ -25,7 +25,8 @@ for LAYER in $(${YQ} ".[]" <<< $LAYERS); do done config="blobs/${CONFIG_DIGEST}" \ -# TODO: can't use \n due to https://github.com/mikefarah/yq/issues/1430 and +# TODO: https://github.com/bazel-contrib/rules_oci/issues/212 +# we can't use \n 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 repotags="${REPOTAGS/$'\n'/\%}" \ layers="${LAYERS}" \ From cf687bdb2cd781a4dd7cfcadc00b873e1b885d13 Mon Sep 17 00:00:00 2001 From: thesayyn Date: Wed, 3 May 2023 16:01:45 -0700 Subject: [PATCH 5/7] fix --- oci/private/tarball.sh.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oci/private/tarball.sh.tpl b/oci/private/tarball.sh.tpl index 9ab9e544..8431586b 100644 --- a/oci/private/tarball.sh.tpl +++ b/oci/private/tarball.sh.tpl @@ -24,12 +24,12 @@ for LAYER in $(${YQ} ".[]" <<< $LAYERS); do cp "${IMAGE_DIR}/blobs/${LAYER}" "${BLOBS_DIR}/${LAYER}.tar.gz" done -config="blobs/${CONFIG_DIGEST}" \ # TODO: https://github.com/bazel-contrib/rules_oci/issues/212 # we can't use \n 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 repotags="${REPOTAGS/$'\n'/\%}" \ +config="blobs/${CONFIG_DIGEST}" \ layers="${LAYERS}" \ "${YQ}" eval \ - --null-input '.[0] = {"Config": strenv(config), "RepoTags": "${repotags}" | envsubst | split("\%"), "Layers": env(layers) | map( "blobs/" + . + ".tar.gz") }' \ + --null-input '.[0] = {"Config": env(config), "RepoTags": "${repotags}" | envsubst | split("\%"), "Layers": env(layers) | map( "blobs/" + . + ".tar.gz") }' \ --output-format json > "${TARBALL_MANIFEST_PATH}" From cd50554dd5228b75173bacf6215fc27249c52c8b Mon Sep 17 00:00:00 2001 From: thesayyn Date: Wed, 3 May 2023 16:12:45 -0700 Subject: [PATCH 6/7] fix bzlmod --- e2e/smoke/MODULE.bazel | 2 ++ 1 file changed, 2 insertions(+) diff --git a/e2e/smoke/MODULE.bazel b/e2e/smoke/MODULE.bazel index db1d6763..e21490ee 100644 --- a/e2e/smoke/MODULE.bazel +++ b/e2e/smoke/MODULE.bazel @@ -2,6 +2,8 @@ bazel_dep(name = "container_structure_test", dev_dependency = True, version = "1.15.0") bazel_dep(name = "rules_oci", dev_dependency = True, version = "0.0.0") bazel_dep(name = "platforms", version = "0.0.5") +bazel_dep(name = "aspect_bazel_lib", version = "1.25.0") +bazel_dep(name = "bazel_skylib", version = "1.1.1") local_path_override( module_name = "rules_oci", From 25df8518e7c11cec817d081b4349c2b89499dcae Mon Sep 17 00:00:00 2001 From: thesayyn Date: Wed, 3 May 2023 16:14:36 -0700 Subject: [PATCH 7/7] fix tar --- e2e/smoke/BUILD.bazel | 2 +- oci/private/tarball.sh.tpl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/smoke/BUILD.bazel b/e2e/smoke/BUILD.bazel index 82d6ce5f..9ba6d035 100644 --- a/e2e/smoke/BUILD.bazel +++ b/e2e/smoke/BUILD.bazel @@ -42,7 +42,7 @@ genrule( name = "tar_manifest", srcs = [":tar"], outs = ["manifest.json"], - cmd = "tar -xOf ./$(location :tar) ./manifest.json > $@", + cmd = "tar -xOf ./$(location :tar) manifest.json > $@", ) write_file( diff --git a/oci/private/tarball.sh.tpl b/oci/private/tarball.sh.tpl index 8431586b..425756d8 100644 --- a/oci/private/tarball.sh.tpl +++ b/oci/private/tarball.sh.tpl @@ -27,9 +27,9 @@ done # TODO: https://github.com/bazel-contrib/rules_oci/issues/212 # we can't use \n 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 -repotags="${REPOTAGS/$'\n'/\%}" \ +repotags="${REPOTAGS/$'\n'/%}" \ config="blobs/${CONFIG_DIGEST}" \ layers="${LAYERS}" \ "${YQ}" eval \ - --null-input '.[0] = {"Config": env(config), "RepoTags": "${repotags}" | envsubst | split("\%"), "Layers": env(layers) | map( "blobs/" + . + ".tar.gz") }' \ + --null-input '.[0] = {"Config": env(config), "RepoTags": "${repotags}" | envsubst | split("%"), "Layers": env(layers) | map( "blobs/" + . + ".tar.gz") }' \ --output-format json > "${TARBALL_MANIFEST_PATH}"