github
This commit is contained in:
64
.github/workflows/deploy.yaml
vendored
Normal file
64
.github/workflows/deploy.yaml
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
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@163.com
|
||||
password: 123quant-speed
|
||||
|
||||
- name: 构建并推送 Docker 镜像
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
# 使用 Docker Hub 用户名作为镜像前缀
|
||||
tags: jeremygan2021@163.com/quant-speed-page:latest
|
||||
|
||||
- name: 部署到服务器
|
||||
uses: appleboy/ssh-action@master
|
||||
with:
|
||||
host: 121.40.192.128
|
||||
username: root
|
||||
# 建议在 GitHub Secrets 配置 SSH_PASSWORD,这里保留硬编码仅作演示
|
||||
password: 123quant-speed
|
||||
port: 22
|
||||
# 将 Docker Hub 用户名传递给 SSH 脚本
|
||||
envs: DOCKERHUB_USERNAME
|
||||
env:
|
||||
DOCKERHUB_USERNAME: jeremygan2021@163.com
|
||||
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
|
||||
Reference in New Issue
Block a user