Files
userbase/deploy/deploy.sh
T

41 lines
1.4 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.
#!/usr/bin/env bash
# 一键部署:上传编排文件 -> SSH 到服务器拉取镜像并启动
# 用法: ./deploy.sh [app_tag] [front_tag]
# 前置环境变量: DEPLOY_HOST, SSHPASS(可选 ACR_NAMESPACE / DEPLOY_USER / REMOTE_DIR)
# 注:服务器需已 docker login registry.cn-hangzhou.aliyuncs.com
set -euo pipefail
APP_VERSION="${1:-${APP_VERSION:-userbase-v1.0}}"
FRONT_VERSION="${2:-${FRONT_VERSION:-userbase-front-v1.0}}"
HOST="${DEPLOY_HOST:?请设置 DEPLOY_HOST}"
PORT="${DEPLOY_PORT:-22}"
USER="${DEPLOY_USER:-yunhai}"
REMOTE_DIR="${REMOTE_DIR:-/opt/docker/userbase}"
NAMESPACE="${ACR_NAMESPACE:-damaomi_docker}"
REGISTRY="${ACR_REGISTRY:-registry.cn-hangzhou.aliyuncs.com}"
PY="${PYTHON_BIN:-python3}"
cd "$(dirname "$0")"
echo "== 1/2 上传 compose 到 $HOST:$REMOTE_DIR =="
"$PY" upload.py "$HOST" "$PORT" "$USER" \
docker-compose.userbase.yml "$REMOTE_DIR/docker-compose.userbase.yml"
echo "== 2/2 远端拉取镜像并启动 =="
"$PY" remote_run.py "$HOST" "$PORT" "$USER" <<EOF
set -e
mkdir -p "$REMOTE_DIR/upload-data"
cd "$REMOTE_DIR"
cat > .env <<ENV
ACR_REGISTRY=$REGISTRY
ACR_NAMESPACE=$NAMESPACE
APP_VERSION=$APP_VERSION
FRONT_VERSION=$FRONT_VERSION
ENV
docker compose -f docker-compose.userbase.yml pull
docker compose -f docker-compose.userbase.yml up -d
docker image prune -f
docker ps --filter name=userbase --format "table {{.Names}}\t{{.Status}}"
echo DEPLOY_OK
EOF