1
- name : CI for Native Docker Image
1
+ name : Build
2
2
3
3
on :
4
4
push :
9
9
- main
10
10
11
11
jobs :
12
+ warm-cache :
13
+ name : Warm Dependencies Cache
14
+ runs-on : ubuntu-latest
15
+ permissions :
16
+ contents : read
17
+ packages : write
18
+ steps :
19
+ - name : Checkout repository
20
+ uses : actions/checkout@v4
21
+
22
+ - name : Set up Docker Buildx
23
+ uses : docker/setup-buildx-action@v3
24
+
25
+ - name : Log in to the GitHub Container Registry
26
+ if : github.event_name == 'push'
27
+ uses : docker/login-action@v3
28
+ with :
29
+ registry : ghcr.io
30
+ username : ${{ github.actor }}
31
+ password : ${{ secrets.GH_PAT }}
32
+
33
+ - name : Build dependencies stage
34
+ uses : docker/build-push-action@v6
35
+ with :
36
+ context : .
37
+ file : ./src/main/docker/Dockerfile.native
38
+ target : dependencies
39
+ platforms : linux/amd64
40
+ push : ${{ github.event_name == 'push' }}
41
+ cache-from : |
42
+ type=gha,scope=deps
43
+ type=registry,ref=ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:deps-cache
44
+ cache-to : |
45
+ type=gha,mode=max,scope=deps
46
+ ${{ github.event_name == 'push' && 'type=registry,ref=ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:deps-cache,mode=max' || '' }}
47
+ tags : |
48
+ ${{ github.event_name == 'push' && format('ghcr.io/{0}/podmortem-log-parser:deps-cache', github.repository_owner) || '' }}
49
+ build-args : |
50
+ GITHUB_USER=${{ github.actor }}
51
+ GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
52
+
12
53
test-build :
13
- name : Test Build on Pull Request
54
+ name : Test Build
14
55
if : github.event_name == 'pull_request'
15
- runs-on : builder
56
+ needs : warm-cache
57
+ runs-on : ubuntu-latest
16
58
steps :
17
59
- name : Checkout repository
18
60
uses : actions/checkout@v4
@@ -27,20 +69,31 @@ jobs:
27
69
file : ./src/main/docker/Dockerfile.native
28
70
platforms : linux/amd64
29
71
push : false
30
- cache-from : type=gha
31
- cache-to : type=gha,mode=max
72
+ cache-from : |
73
+ type=gha,scope=deps
74
+ type=gha,scope=build-amd64
75
+ type=registry,ref=ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:deps-cache
76
+ cache-to : type=gha,mode=max,scope=build-amd64
32
77
build-args : |
33
78
GITHUB_USER=${{ github.actor }}
34
79
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
35
80
36
- build-and-push :
37
- name : Build and Push on Main
81
+ build-arch :
82
+ name : Build ${{ matrix.arch }}
38
83
if : github.event_name == 'push' && github.ref == 'refs/heads/main'
39
- runs-on : builder
84
+ needs : warm-cache
85
+ runs-on : ubuntu-latest
40
86
permissions :
41
87
contents : read
42
88
packages : write
43
-
89
+ strategy :
90
+ matrix :
91
+ arch : [amd64, arm64]
92
+ include :
93
+ - arch : amd64
94
+ platform : linux/amd64
95
+ - arch : arm64
96
+ platform : linux/arm64
44
97
steps :
45
98
- name : Checkout repository
46
99
uses : actions/checkout@v4
@@ -55,19 +108,46 @@ jobs:
55
108
username : ${{ github.actor }}
56
109
password : ${{ secrets.GH_PAT }}
57
110
58
- - name : Build and push Docker image
59
- id : build-and-push
111
+ - name : Build and push ${{ matrix.arch }} image
60
112
uses : docker/build-push-action@v6
61
113
with :
62
114
context : .
63
115
file : ./src/main/docker/Dockerfile.native
64
- platforms : linux/amd64,linux/arm64
116
+ platforms : ${{ matrix.platform }}
65
117
push : true
66
- cache-from : type=gha
67
- cache-to : type=gha,mode=max
118
+ cache-from : |
119
+ type=gha,scope=deps
120
+ type=gha,scope=build-${{ matrix.arch }}
121
+ type=registry,ref=ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:deps-cache
122
+ cache-to : type=gha,mode=max,scope=build-${{ matrix.arch }}
68
123
tags : |
69
- ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:latest
70
- ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:${{ github.sha }}
124
+ ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:${{ github.sha }}-${{ matrix.arch }}
71
125
build-args : |
72
126
GITHUB_USER=${{ github.actor }}
73
127
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
128
+
129
+ create-manifest :
130
+ name : Create Multi-Arch Manifest
131
+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
132
+ needs : build-arch
133
+ runs-on : ubuntu-latest
134
+ permissions :
135
+ contents : read
136
+ packages : write
137
+ steps :
138
+ - name : Log in to the GitHub Container Registry
139
+ uses : docker/login-action@v3
140
+ with :
141
+ registry : ghcr.io
142
+ username : ${{ github.actor }}
143
+ password : ${{ secrets.GH_PAT }}
144
+
145
+ - name : Create and push multi-arch manifest
146
+ run : |
147
+ docker buildx imagetools create -t ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:latest \
148
+ ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:${{ github.sha }}-amd64 \
149
+ ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:${{ github.sha }}-arm64
150
+
151
+ docker buildx imagetools create -t ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:${{ github.sha }} \
152
+ ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:${{ github.sha }}-amd64 \
153
+ ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:${{ github.sha }}-arm64
0 commit comments