villebro commented on code in PR #44250:
URL: https://github.com/apache/superset/pull/44250#discussion_r4030571625


##########
scripts/docker-build-extra-flags.sh:
##########
@@ -31,18 +31,41 @@
 # appending PY_VER here would override supersetbot's pin and silently make
 # "py311"/"py312" build the exact same image as "lean". Every other preset
 # gets the override so its build lands on the Dockerfile's own supported
-# Python version.
+# Python version. Those presets also point buildx at a matching cache tag so
+# local and CI builds can pull cache layers for the same base image they build.
 #
-# Usage: docker-build-extra-flags.sh <build_preset> <image_tag>
+# Usage: docker-build-extra-flags.sh <build_preset> [image_tag]
 
 set -euo pipefail
 
-BUILD_PRESET="${1:?usage: docker-build-extra-flags.sh <build_preset> 
<image_tag>}"
-IMAGE_TAG="${2:?usage: docker-build-extra-flags.sh <build_preset> <image_tag>}"
+BUILD_PRESET="${1:?usage: docker-build-extra-flags.sh <build_preset> 
[image_tag]}"
+IMAGE_TAG="${2:-}"
+DEFAULT_PY_VER="$(sed -n 's/^ARG PY_VER=//p' Dockerfile | head -n 1)"
+if [ -z "$DEFAULT_PY_VER" ]; then
+  echo "Could not determine the default PY_VER from Dockerfile" >&2
+  exit 1
+fi
+
+EXTRA_FLAGS="--build-arg INCLUDE_CHROMIUM=false"
+if [ -n "$IMAGE_TAG" ]; then
+  EXTRA_FLAGS="$EXTRA_FLAGS --tag $IMAGE_TAG"
+fi
+case "$BUILD_PRESET" in
+  py311)
+    CACHE_REF="apache/superset-cache:3.11-slim-bookworm"
+    ;;
+  py312)
+    CACHE_REF="apache/superset-cache:3.12-slim-bookworm"
+    ;;
+  *)
+    CACHE_REF="apache/superset-cache:${DEFAULT_PY_VER}"
+    EXTRA_FLAGS="--build-arg PY_VER=$DEFAULT_PY_VER $EXTRA_FLAGS"
+    ;;
+esac
 
-EXTRA_FLAGS="--build-arg INCLUDE_CHROMIUM=false --tag $IMAGE_TAG"
-if [ "$BUILD_PRESET" != "py311" ] && [ "$BUILD_PRESET" != "py312" ]; then
-  EXTRA_FLAGS="--build-arg PY_VER=3.11.14-slim-trixie $EXTRA_FLAGS"
+EXTRA_FLAGS="--cache-from=type=registry,ref=$CACHE_REF $EXTRA_FLAGS"
+if [ "${PUBLISH_DOCKER_CACHE:-}" = "true" ] && [ -n "${DOCKERHUB_TOKEN:-}" ]; 
then
+  EXTRA_FLAGS="--cache-to=type=registry,mode=max,ref=$CACHE_REF $EXTRA_FLAGS"
 fi

Review Comment:
   Fixed in 258ee7ae13. dev and lean now export to preset-specific cache refs; 
superset keeps the existing ref used by Compose. The docker command check 
asserts the new refs.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to