-
Notifications
You must be signed in to change notification settings - Fork 18
86 lines (74 loc) · 2.6 KB
/
image.yml
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
name: Build and publish container images
on:
push: { branches: [ main ] }
permissions:
packages: write
jobs:
build:
if: ${{ startsWith(github.event.head_commit.message, 'feat:') || startsWith(github.event.head_commit.message, 'fix:') }}
runs-on: ubuntu-20.04
outputs:
commit: ${{ steps.metadata.outputs.commit }}
strategy:
matrix:
architecture: [ amd64, arm64v8 ]
include:
- architecture: amd64
platform: linux/amd64
- architecture: arm64v8
platform: linux/arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Obtain project metadata
id: metadata
run: echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate image metadata
uses: docker/metadata-action@v5
id: image-metadata
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=${{ matrix.architecture }}-${{ steps.metadata.outputs.commit }},enable={{is_default_branch}}
type=raw,value=${{ matrix.architecture }},enable={{is_default_branch}}
- name: Build and push platform specific images
uses: docker/build-push-action@v6
with:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: ${{ matrix.platform }}
tags: ${{ steps.image-metadata.outputs.tags }}
build-args: |
BUILDKIT_CONTEXT_KEEP_GIT_DIR=true
merge:
runs-on: ubuntu-20.04
needs: [ build ]
env:
IMAGE: ghcr.io/${{ github.repository }}
COMMIT: ${{ needs.build.outputs.commit }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate manifest for multi-arch images from source manifests
run: |
docker buildx imagetools create \
--tag ${IMAGE}:${COMMIT} ${IMAGE}:{amd64,arm64v8}-${COMMIT}
docker buildx imagetools create \
--tag ${IMAGE}:latest ${IMAGE}:{amd64,arm64v8}