Add DevOps release and deployment configuration
Some checks failed
Build and Deploy / test-backend (push) Has been cancelled
Build and Deploy / build-backend (push) Has been cancelled
Build and Deploy / build-admin (push) Has been cancelled
Deploy to Production / build-backend (push) Has been cancelled
Deploy to Production / deploy (push) Has been cancelled
Some checks failed
Build and Deploy / test-backend (push) Has been cancelled
Build and Deploy / build-backend (push) Has been cancelled
Build and Deploy / build-admin (push) Has been cancelled
Deploy to Production / build-backend (push) Has been cancelled
Deploy to Production / deploy (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
64
scripts/build_and_push.sh
Normal file
64
scripts/build_and_push.sh
Normal file
@@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
# 构建并推送 Docker 镜像到私有 Registry
|
||||
# 用途:构建 backend、admin、nginx 镜像并推送到 registry.667788.cool
|
||||
# 使用: ./scripts/build_and_push.sh [TAG]
|
||||
# 示例: ./scripts/build_and_push.sh v1.0.0
|
||||
|
||||
set -e
|
||||
|
||||
TAG=${1:-latest}
|
||||
REGISTRY="registry.667788.cool"
|
||||
|
||||
echo "=== 构建并推送 Docker 镜像 ==="
|
||||
echo ""
|
||||
echo "Registry: $REGISTRY"
|
||||
echo "Tag: $TAG"
|
||||
echo ""
|
||||
|
||||
# 检查 docker compose 命令
|
||||
if command -v docker-compose &> /dev/null; then
|
||||
DOCKER_COMPOSE_CMD="docker-compose"
|
||||
elif docker compose version &> /dev/null; then
|
||||
DOCKER_COMPOSE_CMD="docker compose"
|
||||
else
|
||||
echo "错误: 未找到 docker-compose 或 docker compose 命令"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 登录 registry
|
||||
echo "1. 登录 registry..."
|
||||
if ! docker login $REGISTRY; then
|
||||
echo "✗ 登录失败,请检查凭据"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ 登录成功"
|
||||
echo ""
|
||||
|
||||
# 构建镜像
|
||||
echo "2. 构建镜像..."
|
||||
export TAG=$TAG
|
||||
$DOCKER_COMPOSE_CMD -f docker-compose.release.yml build
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "✗ 构建失败"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ 构建成功"
|
||||
echo ""
|
||||
|
||||
# 推送镜像
|
||||
echo "3. 推送镜像..."
|
||||
$DOCKER_COMPOSE_CMD -f docker-compose.release.yml push
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "✗ 推送失败"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ 推送成功"
|
||||
echo ""
|
||||
|
||||
echo "=== 完成 ✅ ==="
|
||||
echo ""
|
||||
echo "镜像已推送到:"
|
||||
echo " - $REGISTRY/wecom-backend:$TAG"
|
||||
echo " - $REGISTRY/wecom-admin:$TAG"
|
||||
echo " - $REGISTRY/wecom-nginx:$TAG"
|
||||
echo ""
|
||||
Reference in New Issue
Block a user