-
Notifications
You must be signed in to change notification settings - Fork 0
249 lines (220 loc) · 9.01 KB
/
build_all.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
name: Build all
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- '**/README.md'
schedule:
# Every Saturday at 2AM UTC
- cron: "0 2 * * 6"
pull_request:
branches:
- 'main'
env:
DNF_CACHE_PATH: /var/cache/libdnf5 # F41+ and newer F40 with libdnf5
HOST_DNF_CACHE_PATH: /tmp/libdnf5 # Any path is okay
DNF_CACHE_PURGE_THRESHOLD_MB: 400
FEDORA_VERSION: "41"
jobs:
build-and-push:
strategy:
matrix:
job:
- { name: amd64, os: ubuntu-latest, pretty-name: Build and push amd64 image }
- { name: arm64, os: ubuntu-24.04-arm, pretty-name: Build and push arm64 image }
runs-on: ${{ matrix.job.os }}
name: ${{ matrix.job.pretty-name }}
permissions:
contents: read
packages: write
id-token: write # needed for signing the images with GitHub OIDC Token
attestations: write
steps:
- name: Check out the repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Install Podman and buildah on arm64
if: contains( matrix.job.name , 'arm64')
uses: awalsh128/cache-apt-pkgs-action@5902b33ae29014e6ca012c5d8025d4346556bd40 # v1.4.3
with:
packages: podman, buildah
- name: Mkdir for DNF Cache
run: mkdir -p ${{ env.HOST_DNF_CACHE_PATH }}
- name: Restore DNF Cache
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: ${{ env.HOST_DNF_CACHE_PATH }}
key: dnf-cache-${{ matrix.job.name }}
- name: Install Cosign
uses: sigstore/cosign-installer@d7d6bc7722e3daa8354c50bcb52f4837da5e9b6a # v3.8.1
- name: Extract metadata for Docker (main)
id: meta-main
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest=false
tags: |
type=raw,value={{date 'YYYYMMDD'}}-${{ matrix.job.name }},enable={{is_default_branch}}
type=raw,value=latest-${{ matrix.job.name }},enable={{is_default_branch}}
type=ref,event=pr,suffix=-${{ matrix.job.name }}
- name: Log in to ghcr.io (Using Action)
uses: redhat-actions/podman-login@4934294ad0449894bcd1e9f191899d7292469603 # v1.7
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
- name: Buildah Action (main)
id: build-image-main
uses: redhat-actions/buildah-build@7a95fa7ee0f02d552a32753e7414641a04307056 # v2.13
with:
context: fe
containerfiles: fe/Dockerfile.${{ env.FEDORA_VERSION }}
tags: ${{ steps.meta-main.outputs.tags }}
oci: true
extra-args: |
--squash
-v ${{ env.HOST_DNF_CACHE_PATH }}:${{ env.DNF_CACHE_PATH }}
- name: Purge dnf5 cache if too big
run: |
# Folder size (KB)
folder_size=$(du -sk ${{ env.HOST_DNF_CACHE_PATH }} | cut -f1)
echo "Folder size: ${folder_size} KB; $(($folder_size /1024)) MB"
# 100MB = 100 * 1024 KB
threshold=$((${{ env.DNF_CACHE_PURGE_THRESHOLD_MB }} * 1024))
echo "Threshold size: ${threshold} KB; ${{ env.DNF_CACHE_PURGE_THRESHOLD_MB }} MB"
if [ "$folder_size" -gt "$threshold" ]; then
echo "Threshold size exceed, purging."
rm -rf ${{ env.HOST_DNF_CACHE_PATH }}/*
echo '### DNF Cache purging: true' >> $GITHUB_STEP_SUMMARY
else
echo "Threshold size is not exceed."
echo '### DNF Cache purging: false' >> $GITHUB_STEP_SUMMARY
fi
- name: Get Date for creating cache key
id: get-date
shell: bash
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
- name: Save DNF Cache
uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: ${{ env.HOST_DNF_CACHE_PATH }}
key: dnf-cache-${{ matrix.job.name }}-${{ steps.get-date.outputs.date }}
- name: Push (main)
id: push-main
uses: redhat-actions/push-to-registry@5ed88d269cf581ea9ef6dd6806d01562096bee9c # v2.8
with:
image: ${{ steps.build-image-main.outputs.image }}
tags: ${{ steps.build-image-main.outputs.tags }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
extra-args: |
--compression-format=zstd
- name: Attest (main)
uses: actions/attest-build-provenance@bd77c077858b8d561b7a36cbe48ef4cc642ca39d # v2.2.2
if: github.event_name != 'pull_request'
with:
subject-name: ghcr.io/${{ github.repository }}
subject-digest: ${{ steps.push-main.outputs.digest }}
push-to-registry: true
link-container-tags:
runs-on: ubuntu-24.04-arm
name: Link Container tags
needs: build-and-push
if: github.event_name != 'pull_request'
permissions:
contents: read
packages: write
id-token: write # needed for signing the images with GitHub OIDC Token
attestations: write
steps:
- name: Login ghcr.io
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push manifest (latest)
id: manifest-latest
uses: Noelware/docker-manifest-action@f28ea24f3298760adb21e97192a135ccadf5d983
with:
inputs: ghcr.io/${{ github.repository }}:latest
images: |
ghcr.io/${{ github.repository }}:latest-amd64,
ghcr.io/${{ github.repository }}:latest-arm64
push: true
- name: Get Date
id: get-date
shell: bash
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
- name: Create and push manifest (time)
id: manifest-time
uses: Noelware/docker-manifest-action@f28ea24f3298760adb21e97192a135ccadf5d983
with:
inputs: ghcr.io/${{ github.repository }}:${{ steps.get-date.outputs.date }}
images: |
ghcr.io/${{ github.repository }}:${{ steps.get-date.outputs.date }}-amd64,
ghcr.io/${{ github.repository }}:${{ steps.get-date.outputs.date }}-arm64
push: true
- name: Install Cosign
uses: sigstore/cosign-installer@d7d6bc7722e3daa8354c50bcb52f4837da5e9b6a # v3.8.1
- name: "Image:Digest -> Digest"
id: get-digest-only
shell: bash
run: |
echo "digest-latest=$(echo ${LATEST} | awk -F'@' '{print $2}')" >> $GITHUB_OUTPUT
echo "digest-time=$(echo ${TIME} | awk -F'@' '{print $2}')" >> $GITHUB_OUTPUT
env:
LATEST: ${{ steps.manifest-latest.outputs.images }}
TIME: ${{ steps.manifest-time.outputs.images }}
- name: Attest (Tag resign) (latest)
uses: actions/attest-build-provenance@bd77c077858b8d561b7a36cbe48ef4cc642ca39d # v2.2.2
with:
subject-name: ghcr.io/${{ github.repository }}
subject-digest: ${{ steps.get-digest-only.outputs.digest-latest }}
push-to-registry: true
- name: Sign the images with GitHub OIDC Token (recursive)
env:
IMAGES: ${{ steps.manifest-time.outputs.images }}
run: |
cosign sign --yes --recursive ${IMAGES}
- name: Attest (Tag resign) (time)
uses: actions/attest-build-provenance@bd77c077858b8d561b7a36cbe48ef4cc642ca39d # v2.2.2
with:
subject-name: ghcr.io/${{ github.repository }}
subject-digest: ${{ steps.get-digest-only.outputs.digest-time }}
push-to-registry: true
# For PR Test Only
# https://stackoverflow.com/questions/59077079/how-to-get-pull-request-number-within-github-actions-workflow
link-container-tags-test:
runs-on: ubuntu-24.04-arm
name: Link Container tags (PR Test)
needs: build-and-push
if: github.event_name == 'pull_request'
permissions:
contents: read
packages: write
steps:
- name: Get PR number
id: pr
run: echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
- name: Login ghcr.io
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push manifest (PR)
id: manifest-time
uses: Noelware/docker-manifest-action@f28ea24f3298760adb21e97192a135ccadf5d983
with:
inputs: ghcr.io/${{ github.repository }}:pr-${{ steps.pr.outputs.PR_NUMBER }}
images: |
ghcr.io/${{ github.repository }}:pr-${{ steps.pr.outputs.PR_NUMBER }}-amd64,
ghcr.io/${{ github.repository }}:pr-${{ steps.pr.outputs.PR_NUMBER }}-arm64
push: true