remote-task-excutor-cli/build-server-image.sh

72 lines
1.7 KiB
Bash
Executable File
Raw 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
# 构建和推送 server 镜像的脚本
set -e
# 配置变量
IMAGE_NAME="remote-task-executor-server"
IMAGE_TAG="${1:-latest}"
REGISTRY="172.20.32.159/pipeline-service"
FULL_IMAGE_NAME="${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}"
# 颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}构建 Server 镜像${NC}"
echo -e "${GREEN}========================================${NC}"
echo -e "镜像名称: ${YELLOW}${FULL_IMAGE_NAME}${NC}"
echo ""
# 检查 Dockerfile 是否存在
if [ ! -f "Dockerfile.server" ]; then
echo -e "${RED}错误: Dockerfile.server 不存在${NC}"
exit 1
fi
# 构建镜像
echo -e "${GREEN}[1/3] 构建 Docker 镜像...${NC}"
docker build -f Dockerfile.server -t ${FULL_IMAGE_NAME} .
if [ $? -ne 0 ]; then
echo -e "${RED}构建失败${NC}"
exit 1
fi
echo -e "${GREEN}构建成功${NC}"
echo ""
# 标记为 latest如果指定了其他 tag
if [ "${IMAGE_TAG}" != "latest" ]; then
echo -e "${GREEN}[2/3] 标记为 latest...${NC}"
docker tag ${FULL_IMAGE_NAME} ${REGISTRY}/${IMAGE_NAME}:latest
echo -e "${GREEN}标记成功${NC}"
echo ""
fi
# 推送镜像
echo -e "${GREEN}[3/3] 推送镜像到仓库...${NC}"
docker push ${FULL_IMAGE_NAME}
if [ $? -ne 0 ]; then
echo -e "${RED}推送失败${NC}"
exit 1
fi
if [ "${IMAGE_TAG}" != "latest" ]; then
docker push ${REGISTRY}/${IMAGE_NAME}:latest
fi
echo -e "${GREEN}推送成功${NC}"
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}构建完成!${NC}"
echo -e "${GREEN}镜像: ${FULL_IMAGE_NAME}${NC}"
echo -e "${GREEN}========================================${NC}"