AriStockAI/build-and-push.sh
fanfpy f12448c7d8 refactor(consul): 统一服务ID命名并添加部署脚本
- 移除服务ID中的"-1"后缀以保持命名一致性
- 新增build-and-push.sh和run-services.sh部署脚本
- 添加docker-compose.aliyun.yml配置文件
2025-07-17 11:24:39 +08:00

64 lines
1.7 KiB
Bash
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
set -e
# 固定版本号为latest
VERSION="latest"
REGISTRY="crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com"
NAMESPACE="testrrr"
USERNAME="2324802641zhengniannian@gmail.com"
SERVICES=("data-service" "emotion-service" "frontend" "quant-service" "recommend-service" "user-service")
# 登录阿里云Docker仓库
echo "登录阿里云Docker仓库..."
docker login --username=$USERNAME $REGISTRY
if [ $? -ne 0 ]; then
echo "登录失败,请检查用户名和密码"
exit 1
fi
# 构建并推送所有服务镜像
for service in "${SERVICES[@]}"; do
echo "\n==================== 处理 $service ===================="
SERVICE_DIR="services/$service"
IMAGE_NAME="$REGISTRY/$NAMESPACE/$service:$VERSION"
# 检查服务目录是否存在
if [ ! -d "$SERVICE_DIR" ]; then
echo "错误: 服务目录 $SERVICE_DIR 不存在"
exit 1
fi
# 前端服务需要特殊处理npm构建
if [ "$service" = "frontend" ]; then
echo "正在前端项目构建..."
cd $SERVICE_DIR
npm install
npm run build
if [ $? -ne 0 ]; then
echo "前端构建失败"
exit 1
fi
cd - > /dev/null
fi
# 构建Docker镜像
echo "正在构建镜像: $IMAGE_NAME"
docker build -t $IMAGE_NAME $SERVICE_DIR
if [ $? -ne 0 ]; then
echo "镜像构建失败"
exit 1
fi
# 推送Docker镜像
echo "正在推送镜像: $IMAGE_NAME"
docker push $IMAGE_NAME
if [ $? -ne 0 ]; then
echo "镜像推送失败"
exit 1
fi
echo "$service 处理完成"
done
echo "\n所有服务镜像构建和推送成功完成"
exit 0