Files
integral-shop/deploy/docker/scripts/remote-up.sh
danaisuiyuan fb76270882 feat(deploy): 完整 Docker 部署方案 — 寄卖商城 + 积分商城
新增两步独立 Docker 部署方案(czleilei240 环境):

步骤一 寄卖商城(integral-resell)
- step1-integral/docker-compose.yml:redis(Alpine自建) + houtai(webman PHP8) + h5(Nginx)
- houtai.Dockerfile:PHP 8.0 + 阿里云镜像源 + webman.bin entrypoint
- h5.Dockerfile:Nginx + configs.js 环境变量动态重写
- redis.Dockerfile:Alpine + apk 构建,绕过 DockerHub 镜像源问题
- 宿主机 bind-mount:/www/wwwroot/leileiadmin.czchunfang.com(FTP可直接更新程序)

步骤二 积分商城(single-shop-22)
- step2-single-shop/docker-compose.yml:redis + admin-api + front-api + admin-web + h5
- Java Dockerfiles:OpenJDK 17 + --add-opens Spring Boot 2.2.6 兼容

公共配置
- nginx/:四个域名宝塔 Nginx 反代配置(HTTP→HTTPS 301、SSL 终止)
- scripts/:sync-to-server.sh / deploy-step1.sh / remote-up.sh
- DOCKER_DEPLOY.md:完整部署文档

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-17 17:24:08 +08:00

93 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# =============================================================
# 远端执行 docker compose 命令
# 用法:
# ./remote-up.sh up # build + up -d
# ./remote-up.sh build # 仅 build
# ./remote-up.sh restart svc # 重启某服务
# ./remote-up.sh logs [svc] # 跟日志
# ./remote-up.sh ps # 服务状态
# ./remote-up.sh ssh # 登录到远端
# =============================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -f "$SCRIPT_DIR/server.env" ]; then
# shellcheck disable=SC1091
set -a
. "$SCRIPT_DIR/server.env"
set +a
fi
SERVER_HOST="${SERVER_HOST:?SERVER_HOST 未配置,请先 cp server.env.example server.env}"
SERVER_USER="${SERVER_USER:-root}"
SERVER_PORT="${SERVER_PORT:-22}"
REMOTE_DIR="${REMOTE_DIR:-/root/integral-shop}"
if [ -n "${SSHPASS:-}" ]; then
command -v sshpass >/dev/null 2>&1 || { echo "需要 sshpass"; exit 1; }
export SSHPASS
SSH=(sshpass -e ssh -p "$SERVER_PORT" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -t)
else
SSH=(ssh -p "$SERVER_PORT" -o StrictHostKeyChecking=no -t)
fi
run_remote() {
"${SSH[@]}" "${SERVER_USER}@${SERVER_HOST}" "cd ${REMOTE_DIR}/deploy/docker && $*"
}
cmd="${1:-up}"
shift || true
case "$cmd" in
up)
# 预检:必须存在 .env
run_remote "test -f .env && test -f integral-resell/.env" || {
cat <<EOF
[!] 远端缺少 .env 文件,请在远端执行:
ssh ${SERVER_USER}@${SERVER_HOST}
cd ${REMOTE_DIR}/deploy/docker
cp .env.example .env
vim .env
cp integral-resell/.env.template integral-resell/.env
vim integral-resell/.env
EOF
exit 1
}
run_remote "docker compose build && docker compose up -d && docker compose ps"
;;
build)
run_remote "docker compose build $*"
;;
restart)
run_remote "docker compose restart $*"
;;
logs)
run_remote "docker compose logs --tail 200 -f $*"
;;
ps|status)
run_remote "docker compose ps"
;;
down)
run_remote "docker compose down"
;;
pull)
run_remote "docker compose pull"
;;
ssh)
"${SSH[@]}" "${SERVER_USER}@${SERVER_HOST}"
;;
exec)
run_remote "docker compose exec $*"
;;
*)
echo "未知子命令: $cmd"
echo "支持: up | build | restart | logs | ps | down | pull | ssh | exec"
exit 2
;;
esac