Files
jeremygan2021 086943f0d5 new
2026-02-13 21:20:34 +08:00

65 lines
1.8 KiB
YAML
Raw Permalink 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: 构建并部署 (Docker Hub)
on:
push:
branches:
- main
- master
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 设置 Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 登录到 Docker Hub
uses: docker/login-action@v3
with:
username: jeremygan2021
password: 123quant-speed
- name: 构建并推送 Docker 镜像
uses: docker/build-push-action@v5
with:
context: .
push: true
# 使用 Docker Hub 用户名作为镜像前缀
tags: jeremygan2021/quant-speed-page:latest
- name: 部署到服务器
uses: appleboy/ssh-action@master
env:
DOCKERHUB_USERNAME: jeremygan2021
with:
host: 121.40.192.128
username: root
# 建议在 GitHub Secrets 配置 SSH_PASSWORD这里保留硬编码仅作演示
password: 123quant-speed
port: 22
# 将 Docker Hub 用户名传递给 SSH 脚本
envs: DOCKERHUB_USERNAME
script: |
# 停止并删除旧容器
docker stop quant-speed-page || true
docker rm quant-speed-page || true
# 拉取最新镜像 (从 Docker Hub)
docker pull $DOCKERHUB_USERNAME/quant-speed-page:latest
# 启动新容器
docker run -d \
--name quant-speed-page \
--restart unless-stopped \
--log-opt max-size=10m \
--log-opt max-file=3 \
-p 3000:80 \
$DOCKERHUB_USERNAME/quant-speed-page:latest
# 清理无用的旧镜像
docker image prune -f