blob: 4657d06d2944866fdaf5152720de3ea8820cfbdc (
plain)
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
|
name: "images4docker: Build"
on:
push:
branches: ["trunk", "master"]
paths:
- "images4docker/dockerfiles/**"
- ".github/workflows/images4docker-build.yml"
schedule:
- cron: "17 3 * * *"
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.make.outputs.matrix }}
count: ${{ steps.make.outputs.count }}
steps:
- uses: actions/checkout@v6
- id: make
run: |
set -euo pipefail
entries=()
for f in images4docker/dockerfiles/*.Dockerfile; do
name="$(basename "$f" .Dockerfile)"
entries+=("$name|$f")
done
json='{"include":['
first=true
for entry in "${entries[@]}"; do
IFS='|' read -r name dockerfile <<< "$entry"
$first || json+=','
first=false
json+="{\"name\":\"$name\",\"dockerfile\":\"$dockerfile\"}"
done
json+=']}'
echo "matrix=$json" >> "$GITHUB_OUTPUT"
echo "count=${#entries[@]}" >> "$GITHUB_OUTPUT"
build:
needs: prepare
if: needs.prepare.outputs.count != '0'
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 6
matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}
steps:
- uses: actions/checkout@v6
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute image tags
id: tagmeta
run: |
set -euo pipefail
short_sha="${GITHUB_SHA::12}"
ts="$(date -u +%Y%m%d-%H%M%S)"
echo "sha_tag=sha-${short_sha}" >> "$GITHUB_OUTPUT"
echo "immutable_tag=${ts}-r${GITHUB_RUN_ID}-a${GITHUB_RUN_ATTEMPT}-${short_sha}" >> "$GITHUB_OUTPUT"
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: images4docker
file: ${{ matrix.dockerfile }}
push: true
provenance: false
tags: |
ghcr.io/${{ github.repository_owner }}/images/${{ matrix.name }}:latest
ghcr.io/${{ github.repository_owner }}/images/${{ matrix.name }}:${{ steps.tagmeta.outputs.sha_tag }}
ghcr.io/${{ github.repository_owner }}/images/${{ matrix.name }}:${{ steps.tagmeta.outputs.immutable_tag }}
|