Files
versions-for-swarm/build.sh

39 lines
1.7 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
REGISTRY="harbor.seahi.me/stu"
IMAGE_NAME="versions-for-swarm"
PLATFORMS="linux/amd64,linux/386,linux/arm64"
# 创建并使用支持多平台的 builder如果不存在
if ! docker buildx inspect multiplatform-builder >/dev/null 2>&1; then
docker buildx create --name multiplatform-builder --driver docker-container --bootstrap
fi
docker buildx use multiplatform-builder
echo "🚀 开始构建所有版本..."
# 并行构建所有版本
docker buildx build --platform ${PLATFORMS} --build-arg APP_VERSION=v1.0 \
-t ${REGISTRY}/${IMAGE_NAME}:v1.0 --push \
--cache-from type=registry,ref=${REGISTRY}/${IMAGE_NAME}:buildcache \
--cache-to type=registry,ref=${REGISTRY}/${IMAGE_NAME}:buildcache,mode=max . &
docker buildx build --platform ${PLATFORMS} --build-arg APP_VERSION=v2.0 \
-t ${REGISTRY}/${IMAGE_NAME}:v2.0 --push \
--cache-from type=registry,ref=${REGISTRY}/${IMAGE_NAME}:buildcache \
--cache-to type=registry,ref=${REGISTRY}/${IMAGE_NAME}:buildcache,mode=max . &
docker buildx build --platform ${PLATFORMS} --build-arg APP_VERSION=v2.1 \
-t ${REGISTRY}/${IMAGE_NAME}:v2.1 --push \
--cache-from type=registry,ref=${REGISTRY}/${IMAGE_NAME}:buildcache \
--cache-to type=registry,ref=${REGISTRY}/${IMAGE_NAME}:buildcache,mode=max . &
docker buildx build --platform ${PLATFORMS} --build-arg APP_VERSION=v3.0-buggy --build-arg BUGGY=true \
-t ${REGISTRY}/${IMAGE_NAME}:v3.0-buggy --push \
--cache-from type=registry,ref=${REGISTRY}/${IMAGE_NAME}:buildcache \
--cache-to type=registry,ref=${REGISTRY}/${IMAGE_NAME}:buildcache,mode=max . &
# 等待所有后台任务完成
wait
echo "✅ 所有版本构建完成(支持平台: ${PLATFORMS}"