Files
market_page/.gitea/workflows/deploy.yaml
jeremygan2021 84385488ae
All checks were successful
Deploy to Server / deploy (push) Successful in 24s
小程序分销
2026-02-17 11:44:41 +08:00

48 lines
1.7 KiB
YAML
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.
name: Deploy to Server
on: [push]
jobs:
deploy:
runs-on: ubuntu
steps:
- name: Deploy using SSH
# 使用 Gitea 官方镜像源,加速国内访问
uses: https://gitea.com/actions/appleboy-ssh-action@v1.0.3
with:
host: 6.6.6.66
username: quant
password: 123quant-speed
script: |
TARGET_DIR="/home/quant/data/dev/market_page"
SUDO_PASSWORD="123quant-speed"
# 1. 切换到目标目录
echo "===== 切换到目标目录: $TARGET_DIR ====="
cd $TARGET_DIR || {
echo "错误:目录 $TARGET_DIR 不存在!"
exit 1
}
# 2. 停止并移除 Docker 容器及镜像
echo -e "\n===== 停止并清理 Docker ====="
# 合并停止容器和删除镜像的操作,避免重复执行导致"already in progress"错误
echo $SUDO_PASSWORD | sudo -S docker compose down --rmi all
# 3. 拉取 Git 最新代码
echo -e "\n===== 拉取 Git 代码 ====="
# 尝试拉取,如果失败则强制重置,增强鲁棒性
if ! git pull; then
echo "警告Git pull 失败,尝试强制同步远程代码..."
git fetch --all
# 获取当前分支名并重置
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
git reset --hard origin/$CURRENT_BRANCH
git pull
fi
# 4. 重新启动 Docker 容器
echo -e "\n===== 启动 Docker 容器 ====="
echo $SUDO_PASSWORD | sudo -S docker compose up -d
echo -e "\n===== 操作完成!====="