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

fix(bazel): don't give absolute path for images #347

Merged
merged 2 commits into from
May 4, 2023
Merged
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
16 changes: 8 additions & 8 deletions bazel/container_structure_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,30 @@ CMD = """\

readonly st=$(rlocation {st_path})
readonly yq=$(rlocation {yq_path})
readonly image=$(rlocation {image_path})

# When the image points to a folder, we can read the index.json file inside
if [[ -d "$image" ]]; then
readonly DIGEST=$("$yq" eval '.manifests[0].digest | sub(":"; "-")' "${{image}}/index.json")
if [[ -d "{image_path}" ]]; then
readonly DIGEST=$("$yq" eval '.manifests[0].digest | sub(":"; "-")' "{image_path}/index.json")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah oops! Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated question; the newest version of yq requires -oj to suppress the default output warning and -r to restore the output raw which was the default in the previous version. can we also add those to yq call here to allow future versions of yq to be used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add in a separate PR. We need some test coverage for this branch as well.

exec "$st" test {fixed_args} --default-image-tag "registry.structure_test.oci.local/image:$DIGEST" $@
else
exec "$st" test {fixed_args} $@
fi

exec "$st" test {fixed_args} $@
"""

def _structure_test_impl(ctx):
fixed_args = ["--driver", ctx.attr.driver]
test_bin = ctx.toolchains["@container_structure_test//bazel:structure_test_toolchain_type"].st_info.binary
yq_bin = ctx.toolchains["@aspect_bazel_lib//lib:yq_toolchain_type"].yqinfo.bin

image_path = to_rlocation_path(ctx, ctx.file.image)
image_path = ctx.file.image.short_path
# Prefer to use a tarball if we are given one, as it works with more 'driver' types.
if image_path.endswith(".tar"):
fixed_args.extend(["--image", "$(rlocation %s)" % image_path])
fixed_args.extend(["--image", image_path])
else:
# https://github.com/GoogleContainerTools/container-structure-test/blob/5e347b66fcd06325e3caac75ef7dc999f1a9b614/cmd/container-structure-test/app/cmd/test.go#L110
if ctx.attr.driver != "docker":
fail("when the 'driver' attribute is not 'docker', then the image must be a .tar file")
fixed_args.extend(["--image-from-oci-layout", "$(rlocation %s)" % image_path])
fixed_args.extend(["--image-from-oci-layout", image_path])
fixed_args.extend(["--default-image-tag", "registry.structure_test.oci.local/image:$DIGEST"])

for arg in ctx.files.configs:
Expand Down