forked from NicTool/NicTool
-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (93 loc) · 3.22 KB
/
Copy pathci-image.yml
File metadata and controls
109 lines (93 loc) · 3.22 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
name: CI Image
on:
push:
branches: [master]
paths:
- 'dist/docker/Dockerfile'
- '.github/workflows/ci-image.yml'
- 'server/Makefile.PL'
- 'client/Makefile.PL'
workflow_dispatch:
permissions:
contents: read
packages: write
env:
IMAGE: ghcr.io/${{ github.repository }}/build
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-24.04
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v6
- name: Lowercase image name
id: meta
run: |
echo "image=$(echo $IMAGE | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
echo "platform_pair=$(echo ${{ matrix.platform }} | tr / -)" >> "$GITHUB_OUTPUT"
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# On master: build and push by digest, then merge job tags :latest.
# On any other ref (workflow_dispatch from a feature branch): build only,
# to validate the Dockerfile without writing to GHCR.
- id: build
uses: docker/build-push-action@v7
with:
context: .
file: dist/docker/Dockerfile
target: base
platforms: ${{ matrix.platform }}
tags: ${{ steps.meta.outputs.image }}
outputs: type=image,push-by-digest=true,name-canonical=true,push=${{ github.ref == 'refs/heads/master' }}
cache-from: type=gha,scope=${{ steps.meta.outputs.platform_pair }}
cache-to: type=gha,scope=${{ steps.meta.outputs.platform_pair }},mode=max
- name: Export digest
if: github.ref == 'refs/heads/master'
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- uses: actions/upload-artifact@v4
if: github.ref == 'refs/heads/master'
with:
name: digest-${{ steps.meta.outputs.platform_pair }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-24.04
needs: build
steps:
- name: Lowercase image name
id: meta
run: echo "image=$(echo $IMAGE | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
- uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digest-*
merge-multiple: true
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create multi-arch manifest
working-directory: /tmp/digests
run: |
docker buildx imagetools create \
-t ${{ steps.meta.outputs.image }}:latest \
$(printf '${{ steps.meta.outputs.image }}@sha256:%s ' *)
- name: Inspect manifest
run: docker buildx imagetools inspect ${{ steps.meta.outputs.image }}:latest