generated from ublue-os/image-template
-
Notifications
You must be signed in to change notification settings - Fork 0
302 lines (275 loc) · 11.8 KB
/
build.yml
File metadata and controls
302 lines (275 loc) · 11.8 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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
---
name: Build DistinctionOS
on:
pull_request:
branches:
- main
schedule:
- cron: '05 6 */5 * *' # 12:05am Mountain time every 5 days Ref: 'minute hour day(s) Month day-of-the-week'
push:
branches:
- main
paths-ignore:
- '.github/**'
- '**/README.md'
- '**/claude.md'
- 'repo_files/**'
- 'system_files/**' # modifcations to system files are usually small and don't warrant a full rebuild
workflow_dispatch:
inputs:
fresh-rechunk:
description: 'Clear rechunk history (forces full redownload for users)'
type: boolean
default: false
handwritten:
description: 'Optional handwritten changelog message for this release'
type: string
default: ''
env:
IMAGE_DESC: "My Customized Bazzite Image"
IMAGE_KEYWORDS: "bootc,ublue,universal-blue"
IMAGE_LOGO_URL: "https://avatars.githubusercontent.com/u/120078124?s=200&v=4"
IMAGE_NAME: "${{ github.event.repository.name }}" # output image name, usually same as repo name
IMAGE_REGISTRY: "ghcr.io/${{ github.repository_owner }}" # do not edit
DEFAULT_TAG: "latest"
concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true
jobs:
build_push:
name: Build and push image
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
id-token: write
outputs:
digest: ${{ steps.push.outputs.digest }}
steps:
# These stage versions are pinned by https://github.com/renovatebot/renovate
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
with:
fetch-depth: 0 # Full history for changelog commit range
- name: Prepare environment
run: |
# Lowercase the image uri
echo "IMAGE_REGISTRY=${IMAGE_REGISTRY,,}" >> ${GITHUB_ENV}
echo "IMAGE_NAME=${IMAGE_NAME,,}" >> ${GITHUB_ENV}
- name: Get current date
id: date
run: |
echo "date=$(date -u +%Y\-%m\-%d\T%H\:%M\:%S\Z)" >> $GITHUB_OUTPUT
- name: Image Metadata
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
id: metadata
with:
# This generates all the tags for your image, you can add custom tags here too!
# Default tags are "$DEFAULT_TAG" and "$DEFAULT_TAG.$date".
tags: |
type=raw,value=${{ env.DEFAULT_TAG }}
type=raw,value=${{ env.DEFAULT_TAG }}.{{date 'YYYYMMDD'}}
type=raw,value={{date 'YYYYMMDD'}}
type=sha,enable=${{ github.event_name == 'pull_request' }}
type=ref,event=pr
labels: |
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}/refs/heads/main/README.md
org.opencontainers.image.created=${{ steps.date.outputs.date }}
org.opencontainers.image.description=${{ env.IMAGE_DESC }}
org.opencontainers.image.documentation=https://raw.githubusercontent.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}/refs/heads/main/README.md
org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}/blob/main/Containerfile
org.opencontainers.image.title=${{ env.IMAGE_NAME }}
org.opencontainers.image.url=https://github.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
org.opencontainers.image.vendor=${{ github.repository_owner }}
org.opencontainers.image.version=${{ env.DEFAULT_TAG }}.{{date 'YYYYMMDD'}}
org.opencontainers.image.revision=${{ github.sha }}
io.artifacthub.package.deprecated=false
io.artifacthub.package.keywords=${{ env.IMAGE_KEYWORDS }}
io.artifacthub.package.license=Apache-2.0
io.artifacthub.package.logo-url=${{ env.IMAGE_LOGO_URL }}
io.artifacthub.package.prerelease=false
containers.bootc=1
sep-tags: " "
sep-annotations: " "
- name: Maximize build space
uses: jlumbroso/free-disk-space@v1.3.1
with:
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: false
swap-storage: true
- name: Build image (rootful)
id: build_image
run: |
# Builds image in root store as root, to be picked up by Rechunker
sudo buildah bud \
--format docker \
--tag "localhost/${IMAGE_NAME}:${{ env.DEFAULT_TAG }}" \
--file Containerfile \
.
- name: Remove source images
run: |
images=$(sudo podman images -n --sort repository --format '{{.ID}} {{.Repository}}' | grep -v localhost | awk '{print $1}')
if [ -n "${images}" ]; then
for image in ${images}; do
echo "Removing image: $image"
sudo podman rmi --force "$image"
done
else
echo "No images to remove."
fi
- name: Run Rechunker
id: rechunk
uses: hhd-dev/rechunk@v1.2.4
if: github.event_name != 'pull_request'
with:
rechunk: "ghcr.io/hhd-dev/rechunk:v1.2.3"
ref: "localhost/${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }}"
prev-ref: "${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }}"
skip_compression: false
max-layers: 90
labels: ${{ steps.metadata.outputs.labels }} # Rechunk strips out all the labels during build, this needs to be reapplied here with newline separator
- name: Remove Rechunker image
run: |
image=$(sudo podman images -n --sort repository --format '{{.ID}} {{.Repository}}' | grep rechunk | awk '{print $1}')
if [ -n "${image}" ]; then
sudo podman rmi --force "$image"
else
echo "No image to remove"
fi
- name: Rechunk output
continue-on-error: true
if: github.event_name != 'pull_request'
run: |
if [[ "${STEPS_RECHUNK_CONCLUSION}" == "success" ]]; then
echo "=== Rechunk Changelog ==="
if [ -f "${STEPS_RECHUNK_OUTPUTS_CHANGELOG}" ]; then
cat "${STEPS_RECHUNK_OUTPUTS_CHANGELOG}"
fi
echo ""
echo "=== Rechunk Manifest ==="
if [ -f "${STEPS_RECHUNK_OUTPUTS_MANIFEST}" ]; then
cat "${STEPS_RECHUNK_OUTPUTS_MANIFEST}"
fi
else
echo "Rechunk conclusion: ${STEPS_RECHUNK_CONCLUSION}"
fi
env:
STEPS_RECHUNK_CONCLUSION: ${{ steps.rechunk.conclusion }}
STEPS_RECHUNK_OUTPUTS_CHANGELOG: ${{ steps.rechunk.outputs.changelog }}
STEPS_RECHUNK_OUTPUTS_MANIFEST: ${{ steps.rechunk.outputs.manifest }}
- name: Load in podman and tag
if: github.event_name != 'pull_request'
run: |
IMAGE=$(podman pull ${STEPS_RECHUNK_OUTPUTS_REF})
sudo rm -rf ${STEPS_RECHUNK_OUTPUTS_LOCATION}
for tag in ${STEPS_METADATA_OUTPUTS_TAGS}; do
podman tag $IMAGE ${IMAGE_NAME}:$tag
done
env:
STEPS_RECHUNK_OUTPUTS_REF: ${{ steps.rechunk.outputs.ref }}
STEPS_RECHUNK_OUTPUTS_LOCATION: ${{ steps.rechunk.outputs.location }}
STEPS_METADATA_OUTPUTS_TAGS: ${{ steps.metadata.outputs.tags }}
IMAGE_NAME: ${{ env.IMAGE_NAME }}
- name: Login to GitHub Container Registry
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Lowercase Registry
id: registry_case
uses: ASzc/change-string-case-action@v8
with:
string: ${{ env.IMAGE_REGISTRY }}
- name: Inspect layer sizes
run: |
echo "=== Layer size analysis ==="
podman inspect localhost/${IMAGE_NAME}:${DEFAULT_TAG} | jq '.[0].RootFS.Layers[] | length' | \
awk '{sum+=$1; print "Layer size: " $1/1024/1024 " MB"} END {print "Total: " sum/1024/1024 " MB"}'
- name: Push To GHCR
uses: redhat-actions/push-to-registry@5ed88d269cf581ea9ef6dd6806d01562096bee9c # v2
if: github.event_name != 'pull_request'
id: push
env:
REGISTRY_USER: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ github.token }}
with:
registry: ${{ env.IMAGE_REGISTRY }}
image: ${{ env.IMAGE_NAME }}
tags: ${{ steps.metadata.outputs.tags }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
extra-args: |
--compression-format=gzip
--compression-level=6
# This section is optional and only needs to be enabled if you plan on distributing
# your project for others to consume. You will need to create a public and private key
# using Cosign and save the private key as a repository secret in Github for this workflow
# to consume. For more details, review the image signing section of the README.
- name: Install Cosign
uses: sigstore/cosign-installer@ba7bc0a3fef59531c69a25acd34668d6d3fe6f22 # v4.1.0
if: github.event_name != 'pull_request'
- name: Sign container image
id: sign_container_image
if: github.event_name != 'pull_request'
run: |
echo "${STEPS_PUSH_OUTPUTS_REGISTRY_PATHS}"
IMAGE_FULL="${STEPS_REGISTRY_CASE_OUTPUTS_LOWERCASE}/${IMAGE_NAME}"
cosign sign -y --key env://COSIGN_PRIVATE_KEY $IMAGE_FULL@"${STEPS_PUSH_OUTPUTS_DIGEST}"
env:
COSIGN_EXPERIMENTAL: false
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}
STEPS_PUSH_OUTPUTS_REGISTRY_PATHS: ${{ steps.push.outputs.registry-paths }}
STEPS_REGISTRY_CASE_OUTPUTS_LOWERCASE: ${{ steps.registry_case.outputs.lowercase }}
STEPS_PUSH_OUTPUTS_DIGEST: ${{ steps.push.outputs.digest }}
generate_release:
name: Generate Release
needs: build_push
if: github.event_name != 'pull_request'
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
with:
fetch-depth: 500 # Deep history for commit range in changelog
- name: Install skopeo
run: |
sudo apt-get update -q
sudo apt-get install -y -q skopeo
- name: Generate changelog
id: changelog
env:
IMAGE_REGISTRY: "ghcr.io/${{ github.repository_owner }}"
IMAGE_NAME: ${{ github.event.repository.name }}
HANDWRITTEN: ${{ github.event.inputs.handwritten || '' }}
run: |
REGISTRY="${IMAGE_REGISTRY,,}"
IMAGE="${IMAGE_NAME,,}"
python3 .github/workflows/changelog.py \
"${IMAGE}" \
./output.env \
./changelog.md \
--registry "docker://${REGISTRY}/" \
--workdir . \
--handwritten "${HANDWRITTEN}"
# Source the env file for tag and title
source ./output.env
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "title=${TITLE}" >> $GITHUB_OUTPUT
# Show in job summary
echo "## Release: ${TITLE}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
cat ./changelog.md >> $GITHUB_STEP_SUMMARY
- name: Create Release
uses: softprops/action-gh-release@153bb8e04406b158c6c84fc1615b65b24149a1fe # v2
with:
name: ${{ steps.changelog.outputs.title }}
tag_name: ${{ steps.changelog.outputs.tag }}
body_path: ./changelog.md
make_latest: true