World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[MINOR] feat(docker): write OCI image source labels (#13611)
Danhua Wang441ced84c0c5
diff --git a/dev/docker/build-docker.sh b/dev/docker/build-docker.shindex 2df3052371..3b7b1499a8 100755--- a/dev/docker/build-docker.sh+++ b/dev/docker/build-docker.sh@@ -132,8 +132,8 @@ elif [ "${component_type}" == "trino-connectors" ] || \exit 1fiecho "INFO : IMAGE_VERSION=${image_version} (from gradle.properties)"- # Build the connector jars, stage them under packages/, and stage each- # artifact's own LICENSE/NOTICE under licenses/ (done by the dependency script).+ # Build the connector jars, stage them under packages/, and copy the+ # repository-root LICENSE/NOTICE into licenses/ (done by the dependency script).. "${script_dir}/${component_type}/${component_type}-dependency.sh"build_args="--build-arg IMAGE_VERSION=${image_version}"else@@ -144,6 +144,30 @@ fibuild_args="${build_args} --build-arg IMAGE_NAME=${image_name} --build-arg TAG_NAME=${tag_name}"+# Standard OCI labels so a published image points at the commit it was built+# from. Callers may set OCI_IMAGE_VERSION, OCI_IMAGE_REVISION, and+# OCI_IMAGE_SOURCE. When unset, version is the image tag, revision is this+# checkout, and source is apache/gravitino.+#+# Keep these as a Bash array and expand with "${oci_labels[@]}" so values that+# contain whitespace (for example OCI_IMAGE_VERSION='2.0 custom') stay one+# --label argument instead of splitting into extra buildx positionals.+oci_version="${OCI_IMAGE_VERSION:-${tag_name:-}}"+oci_revision="${OCI_IMAGE_REVISION:-}"+if [ -z "${oci_revision}" ]; then+ oci_revision="$(git -C "${script_dir}" rev-parse HEAD 2>/dev/null || true)"+fi+oci_source="${OCI_IMAGE_SOURCE:-https://github.com/apache/gravitino}"+oci_labels=()+if [ -n "${oci_version}" ] && [ -n "${oci_revision}" ]; then+ oci_labels=(+ --label "org.opencontainers.image.version=${oci_version}"+ --label "org.opencontainers.image.revision=${oci_revision}"+ --label "org.opencontainers.image.source=${oci_source}"+ )+ echo "INFO : OCI labels version=${oci_version} revision=${oci_revision} source=${oci_source}"+fi+# Create multi-arch builderBUILDER_NAME="gravitino-builder"builders=$(docker buildx ls)@@ -157,14 +181,14 @@ ficd ${script_dir}/${component_type}if [[ "${platform_type}" == "all" ]]; thenif [ ${build_latest} -eq 1 ]; then- docker buildx build --builder ${BUILDER_NAME} --no-cache --pull --platform=linux/amd64,linux/arm64 ${build_args} --push --progress plain -f Dockerfile -t ${image_name}:latest -t ${image_name}:${tag_name} .+ docker buildx build --builder ${BUILDER_NAME} --no-cache --pull --platform=linux/amd64,linux/arm64 ${build_args} "${oci_labels[@]}" --push --progress plain -f Dockerfile -t ${image_name}:latest -t ${image_name}:${tag_name} .else- docker buildx build --builder ${BUILDER_NAME} --no-cache --pull --platform=linux/amd64,linux/arm64 ${build_args} --push --progress plain -f Dockerfile -t ${image_name}:${tag_name} .+ docker buildx build --builder ${BUILDER_NAME} --no-cache --pull --platform=linux/amd64,linux/arm64 ${build_args} "${oci_labels[@]}" --push --progress plain -f Dockerfile -t ${image_name}:${tag_name} .fielseif [ ${build_latest} -eq 1 ]; then- docker buildx build --builder ${BUILDER_NAME} --no-cache --pull --platform=${platform_type} ${build_args} --output type=docker --progress plain -f Dockerfile -t ${image_name}:latest -t ${image_name}:${tag_name} .+ docker buildx build --builder ${BUILDER_NAME} --no-cache --pull --platform=${platform_type} ${build_args} "${oci_labels[@]}" --output type=docker --progress plain -f Dockerfile -t ${image_name}:latest -t ${image_name}:${tag_name} .else- docker buildx build --builder ${BUILDER_NAME} --no-cache --pull --platform=${platform_type} ${build_args} --output type=docker --progress plain -f Dockerfile -t ${image_name}:${tag_name} .+ docker buildx build --builder ${BUILDER_NAME} --no-cache --pull --platform=${platform_type} ${build_args} "${oci_labels[@]}" --output type=docker --progress plain -f Dockerfile -t ${image_name}:${tag_name} .fifidiff --git a/dev/docker/test-oci-labels.sh b/dev/docker/test-oci-labels.shnew file mode 100644index 0000000000..7461beb919--- /dev/null+++ b/dev/docker/test-oci-labels.sh@@ -0,0 +1,80 @@+#!/usr/bin/env bash+#+# Licensed to the Apache Software Foundation (ASF) under one+# or more contributor license agreements. See the NOTICE file+# distributed with this work for additional information+# regarding copyright ownership. The ASF licenses this file+# to you under the Apache License, Version 2.0 (the+# "License"); you may not use this file except in compliance+# with the License. You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing,+# software distributed under the License is distributed on an+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+# KIND, either express or implied. See the License for the+# specific language governing permissions and limitations+# under the License.+#++# Regression check for OCI label argv preservation in build-docker.sh.+# A whitespace-containing OCI_IMAGE_VERSION must remain one --label value.+set -euo pipefail++script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"+build_docker="${script_dir}/build-docker.sh"++if ! grep -F 'oci_labels=(' "${build_docker}" >/dev/null; then+ echo "ERROR: build-docker.sh must store OCI labels in a Bash array (oci_labels=())" >&2+ exit 1+fi+if ! grep -F '"${oci_labels[@]}"' "${build_docker}" >/dev/null; then+ echo "ERROR: build-docker.sh must expand OCI labels as \"\${oci_labels[@]}\"" >&2+ exit 1+fi+if grep -E '\$\{oci_labels\}([^[@]|$)' "${build_docker}" >/dev/null; then+ echo "ERROR: build-docker.sh still expands \${oci_labels} as a string" >&2+ exit 1+fi++# Mirror the construction in build-docker.sh and assert argv slots.+oci_version='2.0 custom'+oci_revision='deadbeef'+oci_source='https://github.com/apache/gravitino'+oci_labels=(+ --label "org.opencontainers.image.version=${oci_version}"+ --label "org.opencontainers.image.revision=${oci_revision}"+ --label "org.opencontainers.image.source=${oci_source}"+)++set -- "${oci_labels[@]}"+if [ "$#" -ne 6 ]; then+ echo "ERROR: expected 6 argv slots for three --label pairs, got $#" >&2+ printf ' arg: %q\n' "$@" >&2+ exit 1+fi+if [ "$2" != "org.opencontainers.image.version=2.0 custom" ]; then+ echo "ERROR: version label was split or altered: $2" >&2+ exit 1+fi+if [ "$4" != "org.opencontainers.image.revision=deadbeef" ]; then+ echo "ERROR: revision label was altered: $4" >&2+ exit 1+fi+if [ "$6" != "org.opencontainers.image.source=https://github.com/apache/gravitino" ]; then+ echo "ERROR: source label was altered: $6" >&2+ exit 1+fi++# Contrast: unquoted string expansion (the old bug) splits on whitespace.+old_style="--label org.opencontainers.image.version=${oci_version} --label org.opencontainers.image.revision=${oci_revision}"+# shellcheck disable=SC2086+set -- ${old_style}+if [ "$#" -le 4 ]; then+ echo "ERROR: expected old-style unquoted expansion to split on whitespace (got $# args)" >&2+ exit 1+fi++echo "OK: OCI label array preserves whitespace-containing values as one argument"+exit 0