-
Notifications
You must be signed in to change notification settings - Fork 49
117 lines (102 loc) · 3.85 KB
/
build-app-api.yml
File metadata and controls
117 lines (102 loc) · 3.85 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
115
116
117
name: App and API Images
on:
push:
tags: ["v*"]
env:
REGISTRY: chaitin-registry.cn-hangzhou.cr.aliyuncs.com
NAMESPACE: koalaqa
jobs:
build-and-push:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
service:
- name: api
dockerfile: backend/Dockerfile
context: backend
- name: app
dockerfile: ui/Dockerfile
context: ui
platform:
- arch: amd64
os: linux/amd64
runner: ubuntu-latest
- arch: arm64
os: linux/arm64
runner: ubuntu-24.04-arm
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract tag name and build time
id: extract_tag
run: |
echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "build_time=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Aliyun Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.ALIYUN_CLOUD_USERNAME }}
password: ${{ secrets.ALIYUN_CLOUD_PASSWORD }}
- name: Build and push Docker image for ${{ matrix.platform.arch }}
uses: docker/build-push-action@v5
with:
context: ${{ matrix.service.context }}
file: ${{ matrix.service.dockerfile }}
push: true
tags: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ matrix.service.name }}:${{ steps.extract_tag.outputs.tag }}-${{ matrix.platform.arch }}
platforms: ${{ matrix.platform.os }}
cache-from: type=gha,scope=${{ matrix.service.name }}-${{ matrix.platform.arch }}
cache-to: type=gha,mode=max,scope=${{ matrix.service.name }}-${{ matrix.platform.arch }}
provenance: false
sbom: false
build-args: |
VERSION=${{ steps.extract_tag.outputs.tag }}
COMMIT_HASH=${{ github.sha }}
BUILD_TIME=${{ steps.extract_tag.outputs.build_time }}
HTTP_PROXY=${{ secrets.HTTP_PROXY }}
HTTPS_PROXY=${{ secrets.HTTPS_PROXY }}
create-manifest:
needs: build-and-push
runs-on: ubuntu-latest
strategy:
matrix:
service:
- name: api
- name: app
steps:
- name: Extract tag name
id: extract_tag
run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Login to Aliyun Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.ALIYUN_CLOUD_USERNAME }}
password: ${{ secrets.ALIYUN_CLOUD_PASSWORD }}
- name: Create and push manifest
run: |
docker buildx imagetools create -t \
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ matrix.service.name }}:${{ steps.extract_tag.outputs.tag }} \
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ matrix.service.name }}:${{ steps.extract_tag.outputs.tag }}-amd64 \
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ matrix.service.name }}:${{ steps.extract_tag.outputs.tag }}-arm64
notify:
needs: create-manifest
runs-on: ubuntu-latest
if: always()
steps:
- name: Extract tag name
id: extract_tag
run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Build result notification
run: |
if [ "${{ needs.create-manifest.result }}" == "success" ]; then
echo "✅ App and UI images built successfully!"
echo "🚀 Images pushed to Aliyun Cloud: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}"
echo "📦 Tag: ${{ steps.extract_tag.outputs.tag }}"
else
echo "❌ App and UI image build failed, please check logs"
exit 1
fi