forked from AlmaLinux/docker-images
-
Notifications
You must be signed in to change notification settings - Fork 0
294 lines (264 loc) · 11.2 KB
/
actions-rootfs-builder.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
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
name: AlmaLinux 8 and 9, Container/Docker Images builder and uploader
on:
workflow_dispatch:
inputs:
major_version:
description: 'AlmaLinux major version'
required: true
default: '9'
type: choice
options:
- 10
- 9
- 8
platform:
description: 'Comma-separated list of platforms: linux/amd64, linux/ppc64le, linux/s390x, linux/arm64'
required: true
default: 'linux/amd64, linux/arm64'
image_types:
description: 'Comma-separated list of image types (put each type in quotes): "default", "minimal", "micro", "base", "init"'
required: true
default: '"micro"'
# registry:
# description: 'Registry to push'
# required: true
# default: 'docker.io/ykohut'
# type: choice
# options:
# - docker.io/ykohut
# - quay.io/ykohut
# - ghcr.io/yuravk
registry:
description: 'Comma-separated list of registries: docker.io/ykohut, quay.io/ykohut, ghcr.io/yuravk'
required: true
default: 'docker.io/ykohut, quay.io/ykohut, ghcr.io/yuravk'
push:
description: 'Push to registries'
required: true
type: boolean
env:
# VERSION_MINOR: ${{ inputs.major_version == '9' && '3' || '9' }}
REGISTRY_IMAGE: ykohut/almalinux
jobs:
build:
name: "Build ${{ inputs.major_version }} ${{ matrix.image_types }} for ${{ inputs.platform }} and push to all registries"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# platform: ${{ fromJSON(format('[{0}]', inputs.platform || '"linux/amd64", "linux/ppc64le", "linux/s390x", "linux/arm64"')) }}
# - linux/amd64
# - linux/ppc64le
# - linux/s390x
# - linux/arm64
image_types: ${{ fromJSON(format('[{0}]', inputs.image_types || '"default", "minimal", "micro", "base", "init"')) }}
# - default
# - minimal
# - micro
# - base
# - init
steps:
-
name: "Set environment variables"
run: |
platform="$( echo '${{ inputs.platform }}' | sed 's/\//_/g' )"
echo "PLATFORM_PAIR=${platform//,/}" >> $GITHUB_ENV
-
name: "Prepare version minor number"
run: |
# set minor version
case ${{ inputs.major_version }} in
8)
VERSION_MINOR="9" ;;
9)
VERSION_MINOR="3" ;;
10)
VERSION_MINOR="0" ;;
esac
echo "VERSION_MINOR=${VERSION_MINOR}" >> $GITHUB_ENV
-
name: "Prepare date stamp"
run: |
# date stamp
STAMP=$(date '+%Y%m%d')
echo "STAMP=${STAMP}" >> $GITHUB_ENV
-
name: "Prepare image names"
run: |
# list of registries to push to
REGISTRIES="${{ inputs.registry }}"
IMAGE_NAMES=
# generate image names in format $REGISTRY/almalinux or $REGISTRY/${{ inputs.major_version }}-${{ matrix.image_types }}
# image names are used by docker/metadata-action to set 'images'
for REGISTRY in ${REGISTRIES//,/ }; do
# 'default' images goes to $REGISTRY/almalinux
[ "${{ matrix.image_types }}" = "default" ] \
&& IMAGE_NAME="$REGISTRY/almalinux" \
|| IMAGE_NAME="$REGISTRY/${{ inputs.major_version }}-${{ matrix.image_types }}"
IMAGE_NAMES="${IMAGE_NAMES} ${IMAGE_NAME}"
unset IMAGE_NAME
done
# remove space at the beginning of string
IMAGE_NAMES=${IMAGE_NAMES# }
# separate with comma instead of space and export to the action
echo "IMAGE_NAMES=${IMAGE_NAMES// /,}" >> $GITHUB_ENV
echo
echo $IMAGE_NAMES
# -
# name: "Prepare tags"
# run: |
# # list of repositories to push
# REPOS=$( echo '${{ inputs.image_types }}' | tr -d '"')
# # list of registries to push to
# REGISTRIES="${{ inputs.registry }}"
# TAGS=
# # generate tags list in format $REGISTRY/${{ inputs.major_version }}-${REPO}:$TAG
# for REPO in ${REPOS//,/ }; do
# for REGISTRY in ${REGISTRIES//,/ }; do
# case ${{ matrix.image_types }} in
# default )
# # tags: MAJOR, MAJOR.MINOR
# TAGS="${TAGS} $REGISTRY/${{ inputs.major_version }}-${REPO}:${{ inputs.major_version }} $REGISTRY/${{ inputs.major_version }}-${REPO}:${{ inputs.major_version }}.${VERSION_MINOR}"
# # tags: MAJOR.MINOR-STAMP
# TAGS="${TAGS} $REGISTRY/${{ inputs.major_version }}-${REPO}:${{ inputs.major_version }}.${VERSION_MINOR}-${STAMP}"
# # tags: latest
# [ "${{ inputs.major_version }}" = "9" ] && TAGS="${TAGS} $REGISTRY/${{ inputs.major_version }}-${REPO}:latest"
# ;;
# * )
# # tags: MAJOR-TYPE, MAJOR.MINOR-TYPE
# TAGS="${TAGS} $REGISTRY/${{ inputs.major_version }}-${REPO}:${{ inputs.major_version }}-${{ matrix.image_types }} $REGISTRY/${{ inputs.major_version }}-${REPO}:${{ inputs.major_version }}.${VERSION_MINOR}-${{ matrix.image_types }}"
# # tags: MAJOR.MINOR-TYPE-STAMP
# TAGS="${TAGS} $REGISTRY/${{ inputs.major_version }}-${REPO}:${{ inputs.major_version }}.${VERSION_MINOR}-${{ matrix.image_types }}-${STAMP}"
# ;;
# esac
# done
# done
# # remove space at the beginning of string
# TAGS=${TAGS# }
# # separate with comma instead of space and export to the action
# echo "TAGS=${TAGS// /,}" >> $GITHUB_ENV
# echo
# echo $TAGS
-
name: "Switch into containerd image store"
run: |
# Use containerd image store
sudo sed -i '$s/}/, "features": { "containerd-snapshotter": true } }/' /etc/docker/daemon.json
sudo systemctl restart docker
docker info -f '{{ .DriverStatus }}'
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker.io
if: contains(inputs.registry, 'docker.io') && inputs.push
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to Quay.io
if: contains(inputs.registry, 'quay.io') && inputs.push
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_IO_USERNAME }}
password: ${{ secrets.QUAY_IO_CLI_PASSWORD }}
-
name: Login to Ghcr.io
if: contains(inputs.registry, 'ghcr.io') && inputs.push
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GIT_HUB_USERNAME }}
password: ${{ secrets.GIT_HUB_TOKEN }}
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: ${{ env.IMAGE_NAMES }}
# images: ${{ inputs.registry }}/${{ inputs.major_version }}-${{ matrix.image_types }}
# images: |
# docker.io/ykohut/${{ inputs.major_version }}-${{ matrix.image_types }}
# quay.io/ykohut/${{ inputs.major_version }}-${{ matrix.image_types }}
# ghcr.io/yuravk/${{ inputs.major_version }}-${{ matrix.image_types }}
# generate Docker tags
tags: |
type=raw,priority=500,value=latest,enable=${{ matrix.image_types != 'default' || ( matrix.image_types == 'default' && inputs.major_version == '9' ) }}
type=raw,priority=400,value=${{ inputs.major_version }},enable=true
type=raw,priority=300,value=${{ inputs.major_version }}.${{ env.VERSION_MINOR }},enable=true
type=raw,priority=200,value=${{ inputs.major_version }}.${{ env.VERSION_MINOR }}-${{ env.STAMP }},enable=true
labels: |
maintainer=Yuriy Kohut <ykohut@almalinux.org>
org.opencontainers.image.title=${{ inputs.major_version }}-${{ matrix.image_types }}
org.opencontainers.image.description=Almalinux ${{ inputs.major_version }}.${{ env.VERSION_MINOR }} ${{ matrix.image_types }} images.
org.opencontainers.image.vendor=AlmaLinux.org
-
name: Build images
# if 'Push to registries' is checked
if: inputs.push
id: build-images
uses: docker/build-push-action@v5
with:
provenance: false
context: "{{defaultContext}}:dockerfiles/al${{ inputs.major_version }}"
file: ./Dockerfile.${{ matrix.image_types }}
platforms: ${{ inputs.platform }}
push: false
load: true
# tags: ${{ env.TAGS }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
-
name: Test images
# if 'Push to registries' is checked
if: inputs.push
id: test-images
run: |
archs="${{ inputs.platform }}"
for arch in ${archs//,/ }; do
# docker run --platform=${arch} ${{ steps.build-images.outputs.imageid }} /bin/bash -c " \
docker run --platform=${arch} ${{ steps.build-images.outputs.digest }} /bin/bash -c " \
uname -m \
&& cat /etc/almalinux-release \
&& ( test "${{ matrix.image_types }}" != "micro" && rpm -q gpg-pubkey) || true "
done
-
name: Push to registry
# if 'Push to registries' is checked
if: inputs.push
id: push-images
uses: docker/build-push-action@v5
with:
provenance: false
context: "{{defaultContext}}:dockerfiles/al${{ inputs.major_version }}"
file: ./Dockerfile.${{ matrix.image_types }}
platforms: ${{ inputs.platform }}
push: ${{ inputs.push }}
# tags: ${{ env.TAGS }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
-
name: "Create file with date stamp for ${{ inputs.major_version }} ${{ matrix.image_types }}"
if: ${{ matrix.image_types }} == 'default' || ${{ matrix.image_types }} == 'minimal'
run: |
echo "${{ env.STAMP}}" > ${{ inputs.major_version }}-${{ matrix.image_types }}
-
name: "Commit date stamp for ${{ inputs.major_version }} ${{ matrix.image_types }}"
if: ${{ matrix.image_types }} == 'default' || ${{ matrix.image_types }} == 'minimal'
uses: EndBug/add-and-commit@v9
with:
default_author: user_info
new_branch: actions
message: "${{ env.STAMP }} stamp for new ${{ inputs.major_version }} ${{ matrix.image_types }} pushed"
# pull: '--rebase --autostash ...'
push: true