-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
75 lines (64 loc) · 2.1 KB
/
docker-compose.yml
File metadata and controls
75 lines (64 loc) · 2.1 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
name: Multi-Arch Parallel Build
on:
push:
branches: [ "main" ]
workflow_dispatch:
env:
REGISTRY: ghcr.io
jobs:
# 步骤 A:准备工作,强行转小写
prepare:
runs-on: ubuntu-latest
outputs:
image_name: ${{ steps.lower.outputs.image_name }}
steps:
- id: lower
run: echo "image_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
# 步骤 B:并行构建(amd64 和 arm64 同时跑)
build:
needs: prepare
runs-on: ubuntu-latest
strategy:
matrix:
arch: [amd64, arm64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
if: matrix.arch == 'arm64'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push per Arch
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/${{ matrix.arch }}
# 推送时带上架构后缀,比如 :amd64 或 :arm64
tags: ${{ env.REGISTRY }}/${{ needs.prepare.outputs.image_name }}:${{ matrix.arch }}
cache-from: type=gha,scope=build-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=build-${{ matrix.arch }}
# 步骤 C:合并 Manifest(生成最终的 latest 标签)
manifest:
needs: [prepare, build]
runs-on: ubuntu-latest
steps:
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and Push Multi-arch Manifest
run: |
FULL_IMG="${{ env.REGISTRY }}/${{ needs.prepare.outputs.image_name }}"
docker buildx imagetools create -t ${FULL_IMG}:latest \
${FULL_IMG}:amd64 \
${FULL_IMG}:arm64