20260710 Docker构建固定本地基础镜像
This commit is contained in:
parent
00613afdde
commit
f3934c3bf8
@ -55,6 +55,13 @@ safe_tag_name() {
|
||||
printf '%s' "$1" | tr '/:' '--'
|
||||
}
|
||||
|
||||
local_base_image_tag() {
|
||||
local role="$1"
|
||||
local arch="$2"
|
||||
local source_image="$3"
|
||||
printf 'ours-rp-base-%s-%s:%s\n' "$role" "$arch" "$(safe_tag_name "$source_image")"
|
||||
}
|
||||
|
||||
platform_for_arch() {
|
||||
printf 'linux/%s\n' "$1"
|
||||
}
|
||||
@ -168,12 +175,29 @@ mkdir -p "$OUT_DIR"
|
||||
|
||||
target_platform="$(platform_for_arch "$TARGET_ARCH")"
|
||||
local_host_arch="$(host_arch)"
|
||||
builder_platform="$(platform_for_arch "$local_host_arch")"
|
||||
builder_source_image="$BUILDER_IMAGE"
|
||||
runtime_source_image="$RUNTIME_IMAGE"
|
||||
builder_local_image="$(local_base_image_tag builder "$local_host_arch" "$builder_source_image")"
|
||||
runtime_local_image="$(local_base_image_tag runtime "$TARGET_ARCH" "$runtime_source_image")"
|
||||
|
||||
if [[ "$INSTALL_BINFMT" == "1" && "$local_host_arch" != "$TARGET_ARCH" ]]; then
|
||||
echo "installing binfmt/qemu for $TARGET_ARCH"
|
||||
docker run --rm --privileged tonistiigi/binfmt --install "$TARGET_ARCH"
|
||||
fi
|
||||
|
||||
# Pulling through the Docker daemon uses its configured proxy. Buildx then consumes
|
||||
# these architecture-pinned local aliases without issuing separate registry metadata
|
||||
# requests for the Dockerfile FROM instructions.
|
||||
echo "pulling builder base image: $builder_source_image ($builder_platform)"
|
||||
docker pull --platform "$builder_platform" "$builder_source_image"
|
||||
docker tag "$builder_source_image" "$builder_local_image"
|
||||
echo "pulling runtime base image: $runtime_source_image ($target_platform)"
|
||||
docker pull --platform "$target_platform" "$runtime_source_image"
|
||||
docker tag "$runtime_source_image" "$runtime_local_image"
|
||||
BUILDER_IMAGE="$builder_local_image"
|
||||
RUNTIME_IMAGE="$runtime_local_image"
|
||||
|
||||
if [[ "$BUILDER_NAME" != "default" ]] && ! docker buildx inspect "$BUILDER_NAME" >/dev/null 2>&1; then
|
||||
docker buildx create --name "$BUILDER_NAME" --driver docker-container --use >/dev/null
|
||||
else
|
||||
@ -188,8 +212,10 @@ build_log="$OUT_DIR/$(safe_tag_name "$IMAGE_TAG").build.log"
|
||||
echo "building $target_platform image: $IMAGE_TAG"
|
||||
echo "repo: $REPO_ROOT"
|
||||
echo "dockerfile: $DOCKERFILE"
|
||||
echo "builder_image: $BUILDER_IMAGE"
|
||||
echo "runtime_image: $RUNTIME_IMAGE"
|
||||
echo "builder_source_image: $builder_source_image"
|
||||
echo "runtime_source_image: $runtime_source_image"
|
||||
echo "builder_local_image: $BUILDER_IMAGE"
|
||||
echo "runtime_local_image: $RUNTIME_IMAGE"
|
||||
echo "source_commit: $SOURCE_COMMIT_FULL"
|
||||
echo "source_dirty: $SOURCE_DIRTY"
|
||||
echo "build_timestamp_utc: $BUILD_TIMESTAMP_UTC"
|
||||
@ -248,8 +274,10 @@ fi
|
||||
echo "image=$IMAGE_TAG"
|
||||
echo "platform=$target_platform"
|
||||
echo "arch=$TARGET_ARCH"
|
||||
echo "builder_image=$BUILDER_IMAGE"
|
||||
echo "runtime_image=$RUNTIME_IMAGE"
|
||||
echo "builder_image=$builder_source_image"
|
||||
echo "runtime_image=$runtime_source_image"
|
||||
echo "builder_local_image=$BUILDER_IMAGE"
|
||||
echo "runtime_local_image=$RUNTIME_IMAGE"
|
||||
echo "elapsed_secs=$elapsed_secs"
|
||||
echo "metadata=$metadata_path"
|
||||
echo "tar=$tar_path"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user