Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add missing test case for oci_tarball#repotags #209

Merged
merged 8 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion e2e/smoke/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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")
load("@container_structure_test//:defs.bzl", "container_structure_test")

Expand All @@ -18,10 +20,15 @@ oci_image(
os = "linux",
)

tags = [
"my/image:some-tag",
"my/image:latest",
]

oci_tarball(
name = "tar",
image = ":image",
repotags = [],
repotags = tags,
)

container_structure_test(
Expand All @@ -30,3 +37,23 @@ container_structure_test(
driver = "tar",
image = ":tar",
)

genrule(
name = "tar_manifest",
srcs = [":tar"],
outs = ["manifest.json"],
cmd = "tar -xOf ./$(location :tar) manifest.json > $@",
)

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",
)
2 changes: 2 additions & 0 deletions e2e/smoke/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions oci/private/tarball.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ for LAYER in $(${YQ} ".[]" <<< $LAYERS); do
cp "${IMAGE_DIR}/blobs/${LAYER}" "${BLOBS_DIR}/${LAYER}.tar.gz"
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'/%}" \
config="blobs/${CONFIG_DIGEST}" \
repotags="${REPOTAGS}" \
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": env(config), "RepoTags": "${repotags}" | envsubst | split("%"), "Layers": env(layers) | map( "blobs/" + . + ".tar.gz") }' \
--output-format json > "${TARBALL_MANIFEST_PATH}"