From bfaf4274bd791a9e219d9e69a45354db6219f8df Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Thu, 25 Jan 2024 16:26:34 -0800 Subject: [PATCH] Set `org.opencontainers.image.base.name` (and `org.opencontainers.image.base.digest`) appropriately --- .test/builds.json | 22 ++++++++++++++++++++++ .test/example-commands.sh | 4 ++++ .test/sources.json | 22 ++++++++++++++++++++++ meta.jq | 28 +++++++++++++++++++++------- sources.sh | 1 + 5 files changed, 70 insertions(+), 7 deletions(-) diff --git a/.test/builds.json b/.test/builds.json index 2109118..3efe1ec 100644 --- a/.test/builds.json +++ b/.test/builds.json @@ -93,6 +93,7 @@ "froms": [ "alpine:3.18" ], + "lastStageFrom": "alpine:3.18", "platformString": "linux/amd64", "platform": { "architecture": "amd64", @@ -190,6 +191,7 @@ "froms": [ "alpine:3.18" ], + "lastStageFrom": "alpine:3.18", "platformString": "linux/arm/v6", "platform": { "architecture": "arm", @@ -302,6 +304,7 @@ "froms": [ "alpine:3.18" ], + "lastStageFrom": "alpine:3.18", "platformString": "linux/arm/v7", "platform": { "architecture": "arm", @@ -414,6 +417,7 @@ "froms": [ "alpine:3.18" ], + "lastStageFrom": "alpine:3.18", "platformString": "linux/arm64/v8", "platform": { "architecture": "arm64", @@ -540,6 +544,7 @@ "froms": [ "docker:24-cli" ], + "lastStageFrom": "docker:24-cli", "platformString": "linux/amd64", "platform": { "architecture": "amd64", @@ -639,6 +644,7 @@ "froms": [ "docker:24-cli" ], + "lastStageFrom": "docker:24-cli", "platformString": "linux/arm/v6", "platform": { "architecture": "arm", @@ -767,6 +773,7 @@ "froms": [ "docker:24-cli" ], + "lastStageFrom": "docker:24-cli", "platformString": "linux/arm/v7", "platform": { "architecture": "arm", @@ -895,6 +902,7 @@ "froms": [ "docker:24-cli" ], + "lastStageFrom": "docker:24-cli", "platformString": "linux/arm64/v8", "platform": { "architecture": "arm64", @@ -1002,6 +1010,7 @@ "froms": [ "mcr.microsoft.com/windows/servercore:ltsc2022" ], + "lastStageFrom": "mcr.microsoft.com/windows/servercore:ltsc2022", "platformString": "windows/amd64", "platform": { "architecture": "amd64", @@ -1108,6 +1117,7 @@ "froms": [ "mcr.microsoft.com/windows/servercore:1809" ], + "lastStageFrom": "mcr.microsoft.com/windows/servercore:1809", "platformString": "windows/amd64", "platform": { "architecture": "amd64", @@ -1236,6 +1246,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/amd64", "platform": { "architecture": "amd64", @@ -1357,6 +1368,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/arm/v6", "platform": { "architecture": "arm", @@ -1493,6 +1505,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/arm64/v8", "platform": { "architecture": "arm64", @@ -1626,6 +1639,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/386", "platform": { "architecture": "386", @@ -1758,6 +1772,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/ppc64le", "platform": { "architecture": "ppc64le", @@ -1890,6 +1905,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/s390x", "platform": { "architecture": "s390x", @@ -2022,6 +2038,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/amd64", "platform": { "architecture": "amd64", @@ -2143,6 +2160,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/arm/v6", "platform": { "architecture": "arm", @@ -2279,6 +2297,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/arm64/v8", "platform": { "architecture": "arm64", @@ -2412,6 +2431,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/386", "platform": { "architecture": "386", @@ -2544,6 +2564,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/ppc64le", "platform": { "architecture": "ppc64le", @@ -2676,6 +2697,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/s390x", "platform": { "architecture": "s390x", diff --git a/.test/example-commands.sh b/.test/example-commands.sh index 4bcbaf8..ce9de70 100644 --- a/.test/example-commands.sh +++ b/.test/example-commands.sh @@ -13,11 +13,15 @@ SOURCE_DATE_EPOCH=1700741054 \ --annotation 'org.opencontainers.image.created=2023-11-23T12:04:14Z' \ --annotation 'org.opencontainers.image.version=24.0.7-cli' \ --annotation 'org.opencontainers.image.url=https://hub.docker.com/_/docker' \ + --annotation 'org.opencontainers.image.base.name=alpine:3.18' \ + --annotation 'org.opencontainers.image.base.digest=sha256:d695c3de6fcd8cfe3a6222b0358425d40adfd129a8a47c3416faff1a8aece389' \ --annotation 'manifest-descriptor:org.opencontainers.image.source=https://github.com/docker-library/docker.git#6d541d27b5dd12639e5a33a675ebca04d3837d74:24/cli' \ --annotation 'manifest-descriptor:org.opencontainers.image.revision=6d541d27b5dd12639e5a33a675ebca04d3837d74' \ --annotation 'manifest-descriptor:org.opencontainers.image.created=1970-01-01T00:00:00Z' \ --annotation 'manifest-descriptor:org.opencontainers.image.version=24.0.7-cli' \ --annotation 'manifest-descriptor:org.opencontainers.image.url=https://hub.docker.com/_/docker' \ + --annotation 'manifest-descriptor:org.opencontainers.image.base.name=alpine:3.18' \ + --annotation 'manifest-descriptor:org.opencontainers.image.base.digest=sha256:d695c3de6fcd8cfe3a6222b0358425d40adfd129a8a47c3416faff1a8aece389' \ --tag 'docker:24.0.7-cli' \ --tag 'docker:24.0-cli' \ --tag 'docker:24-cli' \ diff --git a/.test/sources.json b/.test/sources.json index 2a25c7a..d211087 100644 --- a/.test/sources.json +++ b/.test/sources.json @@ -31,6 +31,7 @@ "froms": [ "alpine:3.18" ], + "lastStageFrom": "alpine:3.18", "platformString": "linux/amd64", "platform": { "architecture": "amd64", @@ -55,6 +56,7 @@ "froms": [ "alpine:3.18" ], + "lastStageFrom": "alpine:3.18", "platformString": "linux/arm/v6", "platform": { "architecture": "arm", @@ -80,6 +82,7 @@ "froms": [ "alpine:3.18" ], + "lastStageFrom": "alpine:3.18", "platformString": "linux/arm/v7", "platform": { "architecture": "arm", @@ -105,6 +108,7 @@ "froms": [ "alpine:3.18" ], + "lastStageFrom": "alpine:3.18", "platformString": "linux/arm64/v8", "platform": { "architecture": "arm64", @@ -162,6 +166,7 @@ "froms": [ "docker:24-cli" ], + "lastStageFrom": "docker:24-cli", "platformString": "linux/amd64", "platform": { "architecture": "amd64", @@ -191,6 +196,7 @@ "froms": [ "docker:24-cli" ], + "lastStageFrom": "docker:24-cli", "platformString": "linux/arm/v6", "platform": { "architecture": "arm", @@ -221,6 +227,7 @@ "froms": [ "docker:24-cli" ], + "lastStageFrom": "docker:24-cli", "platformString": "linux/arm/v7", "platform": { "architecture": "arm", @@ -251,6 +258,7 @@ "froms": [ "docker:24-cli" ], + "lastStageFrom": "docker:24-cli", "platformString": "linux/arm64/v8", "platform": { "architecture": "arm64", @@ -304,6 +312,7 @@ "froms": [ "mcr.microsoft.com/windows/servercore:ltsc2022" ], + "lastStageFrom": "mcr.microsoft.com/windows/servercore:ltsc2022", "platformString": "windows/amd64", "platform": { "architecture": "amd64", @@ -356,6 +365,7 @@ "froms": [ "mcr.microsoft.com/windows/servercore:1809" ], + "lastStageFrom": "mcr.microsoft.com/windows/servercore:1809", "platformString": "windows/amd64", "platform": { "architecture": "amd64", @@ -398,6 +408,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/amd64", "platform": { "architecture": "amd64", @@ -425,6 +436,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/arm/v6", "platform": { "architecture": "arm", @@ -453,6 +465,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/arm64/v8", "platform": { "architecture": "arm64", @@ -481,6 +494,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/386", "platform": { "architecture": "386", @@ -508,6 +522,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/ppc64le", "platform": { "architecture": "ppc64le", @@ -535,6 +550,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/s390x", "platform": { "architecture": "s390x", @@ -581,6 +597,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/amd64", "platform": { "architecture": "amd64", @@ -608,6 +625,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/arm/v6", "platform": { "architecture": "arm", @@ -636,6 +654,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/arm64/v8", "platform": { "architecture": "arm64", @@ -664,6 +683,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/386", "platform": { "architecture": "386", @@ -691,6 +711,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/ppc64le", "platform": { "architecture": "ppc64le", @@ -718,6 +739,7 @@ "alpine:3.16", "golang:1.19-alpine3.16" ], + "lastStageFrom": "alpine:3.16", "platformString": "linux/s390x", "platform": { "architecture": "s390x", diff --git a/meta.jq b/meta.jq index 69ddb6c..71b1bb9 100644 --- a/meta.jq +++ b/meta.jq @@ -105,7 +105,21 @@ def build_annotations($buildUrl): # TODO org.opencontainers.image.vendor ? (feels leaky to put "Docker Official Images" here when this is all otherwise mostly generic) } - | with_entries(select(.value)) # strip off anything missing a value (possibly "source", "url", "version", etc) + + ( + .source.arches[.build.arch].lastStageFrom as $lastStageFrom + | if $lastStageFrom then + .build.parents[$lastStageFrom] as $lastStageDigest + | { + "org.opencontainers.image.base.name": $lastStageFrom, + } + + if $lastStageDigest then + { + "org.opencontainers.image.base.digest": .build.parents[$lastStageFrom], + } + else {} end + else {} end + ) + | with_entries(select(.value)) # strip off anything missing a value (possibly "source", "url", "version", "base.digest", etc) ; def build_annotations: build_annotations(git_build_url) @@ -183,12 +197,12 @@ def build_command: else empty end ), ( - .source.arches[].tags[], - .source.arches[].archTags[], + .source.arches[.build.arch].tags[], + .source.arches[.build.arch].archTags[], .build.img | "--tag " + @sh ), - @sh "--platform \(first(.source.arches[].platformString))", + @sh "--platform \(.source.arches[.build.arch].platformString)", ( .build.resolvedParents | to_entries[] @@ -235,12 +249,12 @@ def build_command: "DOCKER_BUILDKIT=0", "docker build", ( - .source.arches[].tags[], - .source.arches[].archTags[], + .source.arches[.build.arch].tags[], + .source.arches[.build.arch].archTags[], .build.img | "--tag " + @sh ), - @sh "--platform \(first(.source.arches[].platformString))", + @sh "--platform \(.source.arches[.build.arch].platformString)", @sh "--file \(.source.entry.File)", ($buildUrl | @sh), empty diff --git a/sources.sh b/sources.sh index c34359c..c29431c 100755 --- a/sources.sh +++ b/sources.sh @@ -65,6 +65,7 @@ bashbrew cat --build-order --format ' "tags": {{ $.Tags namespace false . | json }}, "archTags": {{ if $archNs -}} {{ $.Tags $archNs false . | json }} {{- else -}} [] {{- end }}, "froms": {{ $.ArchDockerFroms $a . | json }}, + "lastStageFrom": {{ $.ArchLastStageFrom $a . | json }}, "platformString": {{ (ociPlatform $a).String | json }}, "platform": {{ ociPlatform $a | json }}, "parents": { }