Files
dokku-ui/build_and_push.sh
2025-10-17 01:13:24 +08:00

58 lines
1.4 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
# Docker amd64 镜像构建脚本
# 使用方法:
# ./build_amd64.sh # 仅构建
# ./build_amd64.sh push # 构建并推送
set -e
# 配置变量
IMAGE_NAME="shokku"
REGISTRY="ccr.ccs.tencentyun.com"
NAMESPACE="miaogai"
DOCKERFILE="Dockerfile"
BUILD_CONTEXT="."
# 参数处理
PUSH=${1:-"false"}
TAG=${2:-"latest"}
# 完整的镜像地址
FULL_IMAGE_NAME="${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}:${TAG}"
echo "=== Docker amd64 镜像构建 ==="
echo "镜像名称: ${FULL_IMAGE_NAME}"
# 检查 Docker
if ! command -v docker &> /dev/null; then
echo "错误: 未找到 Docker"
exit 1
fi
# 构建镜像
echo "开始构建 amd64 镜像..."
docker build --platform linux/amd64 -t ${IMAGE_NAME}:${TAG} -f ${DOCKERFILE} ${BUILD_CONTEXT}
# 标记镜像
docker tag ${IMAGE_NAME}:${TAG} ${FULL_IMAGE_NAME}
# 推送逻辑
if [ "$PUSH" = "push" ]; then
echo "登录到镜像仓库..."
if [ -n "$DOCKER_REGISTRY_USER" ] && [ -n "$DOCKER_REGISTRY_PASSWORD" ]; then
echo "$DOCKER_REGISTRY_PASSWORD" | docker login ${REGISTRY} --username "$DOCKER_REGISTRY_USER" --password-stdin
else
docker login ${REGISTRY}
fi
echo "推送镜像..."
docker push ${FULL_IMAGE_NAME}
echo "✅ amd64 镜像推送完成: ${FULL_IMAGE_NAME}"
else
echo "✅ amd64 镜像构建完成"
echo " 使用 '$0 push' 来推送镜像"
fi
echo "=== 完成 ==="