Skip to content

Commit 8fffed3

Browse files
authored
feat(packages): add OCI metadata labels (#899)
## Summary - add OCI standard labels to package artifacts and image builds - propagate component name and default license into build context ## Testing - ./.github/scripts/ci.sh Refs #493
1 parent f5a0b1f commit 8fffed3

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

packages/scripts/build-package-artifacts.sh.tmpl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,20 @@ function prepare_artifact_config() {
245245
local save_file="$1"
246246
247247
:> "$save_file"
248-
yq -p json -o json -i '.["org.opencontainers.image.version"] = "{{ .version }}"' "$save_file"
249-
yq -p json -o json -i '.["net.pingcap.tibuild.os"] = "{{ .os }}"' "$save_file"
250-
yq -p json -o json -i '.["net.pingcap.tibuild.architecture"] = "{{ .arch }}"' "$save_file"
251-
yq -p json -o json -i '.["net.pingcap.tibuild.profile"] = "{{ .profile }}"' "$save_file"
252-
yq -p json -o json -i '.["net.pingcap.tibuild.git-sha"] = "{{ .git.sha }}"' "$save_file"
253-
yq -p json -o json -i '.["net.pingcap.tibuild.tiup"] = []' "$save_file"
248+
# Inject OCI standard metadata labels and PingCAP build labels.
249+
yq -p json -o json -i '
250+
.["org.opencontainers.image.version"] = "{{ .version }}" |
251+
.["org.opencontainers.image.title"] = "{{ .component }}" |
252+
.["org.opencontainers.image.licenses"] = "{{ .license | default "Apache-2.0" }}" |
253+
.["org.opencontainers.image.source"] = "{{ .git.url }}" |
254+
.["org.opencontainers.image.ref.name"] = "{{ .git.ref }}" |
255+
.["org.opencontainers.image.revision"] = "{{ .git.sha }}" |
256+
.["net.pingcap.tibuild.os"] = "{{ .os }}" |
257+
.["net.pingcap.tibuild.architecture"] = "{{ .arch }}" |
258+
.["net.pingcap.tibuild.profile"] = "{{ .profile }}" |
259+
.["net.pingcap.tibuild.git-sha"] = "{{ .git.sha }}" |
260+
.["net.pingcap.tibuild.tiup"] = []
261+
' "$save_file"
254262
255263
{{- if has (coll.Slice "release" "next-gen") .profile }}
256264
{{- range (.artifacts | jq `map(select((.type == "file" or .type == null) and .if != false and .tiup != null))`) }}

packages/scripts/build-package-images.sh.tmpl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,19 @@ build_and_push_images() {
150150

151151
################# build and push image ################
152152
tag="{{ index $tags 0 }}"
153-
kaniko_global_options="--cleanup --cache=false --label net.pingcap.tibuild.new=yes --label net.pingcap.tibuild.git-sha={{.git.sha}}"
153+
# Inject OCI standard metadata labels and PingCAP build labels.
154+
kaniko_global_options="--cleanup --cache=false"
155+
kaniko_global_options="$kaniko_global_options --label net.pingcap.tibuild.new=yes"
156+
{{ if .git.sha }}
157+
kaniko_global_options="$kaniko_global_options --label net.pingcap.tibuild.git-sha={{ .git.sha }}"
158+
{{ end }}
159+
kaniko_global_options="$kaniko_global_options --label org.opencontainers.image.title={{ .component }}"
160+
kaniko_global_options="$kaniko_global_options --label org.opencontainers.image.licenses={{ .license | default "Apache-2.0" }}"
161+
kaniko_global_options="$kaniko_global_options --label org.opencontainers.image.source={{ .git.url }}"
162+
kaniko_global_options="$kaniko_global_options --label org.opencontainers.image.ref.name={{ .git.ref }}"
163+
{{ if .git.sha }}
164+
kaniko_global_options="$kaniko_global_options --label org.opencontainers.image.revision={{ .git.sha }}"
165+
{{ end }}
154166
:> "$digests_file"
155167
{{ range (.artifacts | jq `map(select(.type == "image" and .if != false))`) }}
156168
# >>>>>>>>>>>>>>>> image: {{ .name }} >>>>>>>>>>>>>>>>

packages/scripts/gen-package-artifacts-with-config.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@ function main() {
4848
echo "❌ No package routes matched for the target($target_info)." >&2
4949
exit 1
5050
fi
51-
yq ".routers[0].git = .git" release-package.yaml | yq ".routers[0]" >release-router.yaml
51+
yq ".routers[0].git = .git | .routers[0].license = .license" release-package.yaml | yq ".routers[0]" >release-router.yaml
5252

5353
# generate package build script
54-
yq -i ".os = \"$os\"" release-router.yaml
55-
yq -i ".arch = \"$arch\"" release-router.yaml
56-
yq -i ".profile = \"$profile\"" release-router.yaml
57-
yq -i ".version = \"$version\"" release-router.yaml
54+
yq -i "
55+
.component = \"$component\" |
56+
.license = (.license // \"Apache-2.0\") |
57+
.os = \"$os\" |
58+
.arch = \"$arch\" |
59+
.profile = \"$profile\" |
60+
.version = \"$version\"
61+
" release-router.yaml
5862
yq -i ".steps = .steps[.profile]" release-router.yaml
5963
yq -i ".steps = (.steps | map(select(.os == null or .os == \"$os\")))" release-router.yaml
6064
yq -i ".steps = (.steps | map(select(.arch == null or .arch == \"$arch\")))" release-router.yaml

packages/scripts/gen-package-images-with-config.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@ function main() {
5454
echo "❌ No package routes matched for the target($target_info)."
5555
exit 1
5656
fi
57-
yq ".routers[0].git = .git" release-package.yaml | yq ".routers[0]" >release-router.yaml
57+
yq ".routers[0].git = .git | .routers[0].license = .license" release-package.yaml | yq ".routers[0]" >release-router.yaml
5858

5959
# generate package build script
60-
yq -i ".os = \"$os\"" release-router.yaml
61-
yq -i ".arch = \"$arch\"" release-router.yaml
62-
yq -i ".profile = \"$profile\"" release-router.yaml
60+
yq -i "
61+
.component = \"$component\" |
62+
.license = (.license // \"Apache-2.0\") |
63+
.os = \"$os\" |
64+
.arch = \"$arch\" |
65+
.profile = \"$profile\"
66+
" release-router.yaml
6367
yq -i ".steps = .steps[.profile]" release-router.yaml
6468
yq -i ".steps = (.steps | map(select(.os == null or .os == \"$os\")))" release-router.yaml
6569
yq -i ".steps = (.steps | map(select(.arch == null or .arch == \"$arch\")))" release-router.yaml

0 commit comments

Comments
 (0)