-
Notifications
You must be signed in to change notification settings - Fork 1
114 lines (95 loc) · 3.8 KB
/
docker-build-deploy.yml
File metadata and controls
114 lines (95 loc) · 3.8 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Build and Push Docker Image to GHCR and ALI_DOCKER_REGISTRY
on:
workflow_dispatch: # 手动触发
permissions:
contents: read
packages: write
jobs:
build-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Get short SHA
id: vars
run: echo "short_sha=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
- name: Log in to GHCR with GITHUB_TOKEN
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Aliyun Docker Registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.ALI_DOCKER_REGISTRY }}
username: ${{ secrets.ALI_DOCKER_USERNAME }}
password: ${{ secrets.ALI_DOCKER_PASSWORD }}
- name: Build and push frontend image
uses: docker/build-push-action@v5
with:
context: ./frontend
file: ./frontend/Dockerfile
push: true
tags: |
ghcr.io/pancrepal-xiaoyibao/kb-frontend:latest
ghcr.io/pancrepal-xiaoyibao/kb-frontend:${{ github.sha }}
ghcr.io/pancrepal-xiaoyibao/kb-frontend:${{ steps.vars.outputs.short_sha }}
${{ secrets.ALI_DOCKER_REGISTRY }}/${{ secrets.ALI_NAMESPACE }}/kb-frontend:latest
${{ secrets.ALI_DOCKER_REGISTRY }}/${{ secrets.ALI_NAMESPACE }}/kb-frontend:${{ steps.vars.outputs.short_sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
- name: Frontend build summary
run: |
echo "✅ 前端容器构建完成!"
echo ""
echo "前端镜像标签:"
echo " - ghcr.io/pancrepal-xiaoyibao/kb-frontend:latest"
echo " - ghcr.io/pancrepal-xiaoyibao/kb-frontend:${{ steps.vars.outputs.short_sha }}"
build-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Get short SHA
id: vars
run: echo "short_sha=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
- name: Log in to GHCR with GITHUB_TOKEN
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Aliyun Docker Registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.ALI_DOCKER_REGISTRY }}
username: ${{ secrets.ALI_DOCKER_USERNAME }}
password: ${{ secrets.ALI_DOCKER_PASSWORD }}
- name: Build and push backend image
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: |
ghcr.io/pancrepal-xiaoyibao/kb-backend:latest
ghcr.io/pancrepal-xiaoyibao/kb-backend:${{ github.sha }}
ghcr.io/pancrepal-xiaoyibao/kb-backend:${{ steps.vars.outputs.short_sha }}
${{ secrets.ALI_DOCKER_REGISTRY }}/${{ secrets.ALI_NAMESPACE }}/kb-backend:latest
${{ secrets.ALI_DOCKER_REGISTRY }}/${{ secrets.ALI_NAMESPACE }}/kb-backend:${{ steps.vars.outputs.short_sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
- name: Backend build summary
run: |
echo "✅ 后端容器构建完成!"
echo ""
echo "后端镜像标签:"
echo " - ghcr.io/pancrepal-xiaoyibao/kb-backend:latest"
echo " - ghcr.io/pancrepal-xiaoyibao/kb-backend:${{ steps.vars.outputs.short_sha }}"