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: add history entries for tars attribute #654

Merged
merged 2 commits into from
Jul 25, 2024
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
2 changes: 1 addition & 1 deletion e2e/assertion/wksp/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local_path_override(
oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.pull(
name = "empty_image",
digest = "sha256:2515b821f7cc895283a961ea6548a29f7eb340a0b8d29f79a0feb3825d31caa9",
digest = "sha256:814539791f475a9d74eb21fd6149849d8b5b4bb1f222185c835581ce59bc7e0a",
image = "http://localhost:1447/empty_image",
)
use_repo(oci, "empty_image")
Expand Down
2 changes: 1 addition & 1 deletion e2e/assertion/wksp/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ load("@rules_oci//oci:pull.bzl", "oci_pull")

oci_pull(
name = "empty_image",
digest = "sha256:2515b821f7cc895283a961ea6548a29f7eb340a0b8d29f79a0feb3825d31caa9",
digest = "sha256:814539791f475a9d74eb21fd6149849d8b5b4bb1f222185c835581ce59bc7e0a",
image = "http://localhost:1447/empty_image",
)

Expand Down
5 changes: 4 additions & 1 deletion examples/assert.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def assert_oci_config(
os_eq = None,
variant_eq = None,
labels_eq = None,
created_eq = None):
created_eq = None,
history_eq = None):
"assert that an oci_image has specified config metadata according to https://github.com/opencontainers/image-spec/blob/main/config.md"
pick = []

Expand Down Expand Up @@ -71,6 +72,8 @@ def assert_oci_config(

if created_eq:
config_json["created"] = created_eq
if history_eq:
config_json["history"] = history_eq

pick += ["." + k for k in config_json.keys()]

Expand Down
37 changes: 37 additions & 0 deletions examples/assertion/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,43 @@ sh_test(
data = [":case12"],
)

# Case 13: image should have history entries
tar(
name = "case13_empty_tar",
srcs = [],
)

tar(
name = "case13_empty_tar2",
srcs = [],
)

oci_image(
name = "case13",
architecture = "arm64",
os = "linux",
tars = [
":case13_empty_tar",
":case13_empty_tar2",
],
)

assert_oci_config(
name = "test_case13",
history_eq = [
{
"created": "1970-01-01T00:00:00Z",
"created_by": "bazel build //examples/assertion:case13_empty_tar",
},
{
"created": "1970-01-01T00:00:00Z",
"created_by": "bazel build //examples/assertion:case13_empty_tar2",
},
],
image = ":case13",
)


# Case 14: created property should be epoch start
oci_image(
name = "case14",
Expand Down
2 changes: 1 addition & 1 deletion examples/multi_architecture_image/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ genrule(
assert_contains(
name = "check_digest",
actual = ":hash",
expected = "sha256:9cc41e3583d5385aa6adc686c15f4e4625ec46fceabde54146add048aa95e716",
expected = "sha256:a2b8ae94672721788b67874f27cf3574fada3ccccc69f483bcb43de653573fe0",
)
19 changes: 17 additions & 2 deletions oci/private/descriptor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set -o pipefail -o errexit -o nounset
PATH="$HPATH:$PATH"
archive="$1"
output="$2"
label="$3"

digest="$(regctl digest <"$archive")"
diffid="$digest"
Expand All @@ -28,5 +29,19 @@ elif zstd -t <"$archive" 2>/dev/null; then
diffid=$(zstd --decompress --format=zstd <"$archive" | regctl digest)
fi

jq -n --arg compression "$compression" --arg diffid "$diffid" --arg digest "$digest" --argjson size "$size" \
'{digest: $digest, diffid: $diffid, compression: $compression, size: $size }' >"$output"
jq -n \
--arg compression "$compression" \
--arg diffid "$diffid" \
--arg digest "$digest" \
--argjson size "$size" \
--arg label "$label" \
'{
digest: $digest,
diffid: $diffid,
compression: $compression,
size: $size,
history: {
created: "1970-01-01T00:00:00Z",
created_by: "bazel build \($label)"
}
}' >"$output"
1 change: 1 addition & 0 deletions oci/private/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def _calculate_descriptor(ctx, idx, layer, zstd, jq, coreutils, regctl):
args = ctx.actions.args()
args.add(layer)
args.add(descriptor)
args.add(layer.owner)
thesayyn marked this conversation as resolved.
Show resolved Hide resolved
ctx.actions.run(
executable = util.maybe_wrap_launcher_for_windows(ctx, ctx.executable._descriptor_sh),
inputs = [layer],
Expand Down
4 changes: 2 additions & 2 deletions oci/private/image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function base_from_scratch() {
layers: []
}' | update_manifest
# Create the image config when there is annotations
jq -n --argjson platform "$platform" '{created: "1970-01-01T00:00:00Z", config:{}, rootfs:{type: "layers", diff_ids:[]}} + $platform' | update_config >/dev/null
jq -n --argjson platform "$platform" '{created: "1970-01-01T00:00:00Z", config:{}, history:[], rootfs:{type: "layers", diff_ids:[]}} + $platform' | update_config >/dev/null
}

function base_from() {
Expand Down Expand Up @@ -91,7 +91,7 @@ function add_layer() {
desc="$(jq --arg comp_ext "${comp_ext}" '.compression |= (if . != "" then "\($comp_ext)\(.)" end)' <<< "$desc")"

new_config_digest=$(
get_config | jq --argjson desc "$desc" '.rootfs.diff_ids += [$desc.diffid]' | update_config
get_config | jq --argjson desc "$desc" '.rootfs.diff_ids += [$desc.diffid] | .history += [$desc.history]' | update_config
)

get_manifest |
Expand Down
Loading