-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (62 loc) · 2.42 KB
/
Copy pathdeploy.yml
File metadata and controls
69 lines (62 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: 企业级部署
on:
workflow_dispatch:
inputs:
environment:
description: "部署环境(dev/staging/prod)"
required: true
default: "dev"
type: choice
options:
- dev
- staging
- prod
backend_image_tag:
description: "后端镜像标签(例如 sha-xxx 或 v1.0.0)"
required: true
type: string
frontend_image_tag:
description: "前端镜像标签(例如 sha-xxx 或 v1.0.0)"
required: true
type: string
permissions:
contents: read
jobs:
deploy:
name: 部署到目标环境
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: 校验部署变量
run: |
test -n "${{ inputs.backend_image_tag }}"
test -n "${{ inputs.frontend_image_tag }}"
- name: 校验部署 Secrets
run: |
test -n "${{ secrets.DEPLOY_HOST }}"
test -n "${{ secrets.DEPLOY_USER }}"
test -n "${{ secrets.DEPLOY_SSH_KEY }}"
test -n "${{ secrets.GHCR_USERNAME }}"
test -n "${{ secrets.GHCR_PAT }}"
test -n "${{ secrets.DEPLOY_WORKDIR }}"
- name: 打印部署清单
run: |
echo "目标环境: ${{ inputs.environment }}"
echo "后端镜像: ghcr.io/${{ github.repository }}-backend:${{ inputs.backend_image_tag }}"
echo "前端镜像: ghcr.io/${{ github.repository }}-frontend:${{ inputs.frontend_image_tag }}"
echo "部署目录: ${{ secrets.DEPLOY_WORKDIR }}"
- name: 远程部署(基于 SSH)
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
set -e
docker login ghcr.io -u "${{ secrets.GHCR_USERNAME }}" -p "${{ secrets.GHCR_PAT }}"
docker pull ghcr.io/${{ github.repository }}-backend:${{ inputs.backend_image_tag }}
docker pull ghcr.io/${{ github.repository }}-frontend:${{ inputs.frontend_image_tag }}
export BACKEND_IMAGE=ghcr.io/${{ github.repository }}-backend:${{ inputs.backend_image_tag }}
export FRONTEND_IMAGE=ghcr.io/${{ github.repository }}-frontend:${{ inputs.frontend_image_tag }}
cd ${{ secrets.DEPLOY_WORKDIR }}
docker compose -f docker-compose.prod.yml up -d