From ad480be1484c0e0f46c783412ccec2d298c955b0 Mon Sep 17 00:00:00 2001 From: Sahin Yort Date: Sat, 20 Jul 2024 01:04:40 +0300 Subject: [PATCH] fix: set created property for scratch base (#655) --- e2e/assertion/wksp/MODULE.bazel | 2 +- e2e/assertion/wksp/WORKSPACE | 2 +- examples/assert.bzl | 6 +++++- examples/assertion/BUILD.bazel | 13 +++++++++++++ oci/private/image.sh | 2 +- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/e2e/assertion/wksp/MODULE.bazel b/e2e/assertion/wksp/MODULE.bazel index b8c6be45..c4acc54e 100644 --- a/e2e/assertion/wksp/MODULE.bazel +++ b/e2e/assertion/wksp/MODULE.bazel @@ -11,7 +11,7 @@ local_path_override( oci = use_extension("@rules_oci//oci:extensions.bzl", "oci") oci.pull( name = "empty_image", - digest = "sha256:e40e202a677ddddeaaf4603df278a6da42130d750622f1b1130bdafe6876a6e0", + digest = "sha256:2515b821f7cc895283a961ea6548a29f7eb340a0b8d29f79a0feb3825d31caa9", image = "http://localhost:1447/empty_image", ) use_repo(oci, "empty_image") diff --git a/e2e/assertion/wksp/WORKSPACE b/e2e/assertion/wksp/WORKSPACE index 4fdc788b..7656cbc6 100644 --- a/e2e/assertion/wksp/WORKSPACE +++ b/e2e/assertion/wksp/WORKSPACE @@ -15,7 +15,7 @@ load("@rules_oci//oci:pull.bzl", "oci_pull") oci_pull( name = "empty_image", - digest = "sha256:e40e202a677ddddeaaf4603df278a6da42130d750622f1b1130bdafe6876a6e0", + digest = "sha256:2515b821f7cc895283a961ea6548a29f7eb340a0b8d29f79a0feb3825d31caa9", image = "http://localhost:1447/empty_image", ) diff --git a/examples/assert.bzl b/examples/assert.bzl index ba4161ac..60c39d88 100644 --- a/examples/assert.bzl +++ b/examples/assert.bzl @@ -32,7 +32,8 @@ def assert_oci_config( architecture_eq = None, os_eq = None, variant_eq = None, - labels_eq = None): + labels_eq = None, + created_eq = None): "assert that an oci_image has specified config metadata according to https://github.com/opencontainers/image-spec/blob/main/config.md" pick = [] @@ -68,6 +69,9 @@ def assert_oci_config( if variant_eq: config_json["variant"] = variant_eq + if created_eq: + config_json["created"] = created_eq + pick += ["." + k for k in config_json.keys()] if len(config.keys()): diff --git a/examples/assertion/BUILD.bazel b/examples/assertion/BUILD.bazel index a79014c9..86c78326 100644 --- a/examples/assertion/BUILD.bazel +++ b/examples/assertion/BUILD.bazel @@ -385,6 +385,19 @@ sh_test( data = [":case12"], ) +# Case 14: created property should be epoch start +oci_image( + name = "case14", + architecture = "arm64", + os = "linux", +) + +assert_oci_config( + name = "test_case14", + created_eq = "1970-01-01T00:00:00Z", + image = ":case14", +) + # Case 15: Setting entrypoint resets cmd oci_image( name = "case15_base", diff --git a/oci/private/image.sh b/oci/private/image.sh index adb60e56..aff94a94 100644 --- a/oci/private/image.sh +++ b/oci/private/image.sh @@ -27,7 +27,7 @@ function base_from_scratch() { layers: [] }' | update_manifest # Create the image config when there is annotations - jq -n --argjson platform "$platform" '{config:{}, rootfs:{type: "layers", diff_ids:[]}} + $platform' | update_config >/dev/null + jq -n --argjson platform "$platform" '{created: "1970-01-01T00:00:00Z", config:{}, rootfs:{type: "layers", diff_ids:[]}} + $platform' | update_config >/dev/null } function base_from() {