1+ name : Build Docker Images
2+
3+ permissions :
4+ contents : read
5+ packages : write
6+
7+ on :
8+ push :
9+ branches :
10+ - main
11+ paths-ignore :
12+ - ' assets/'
13+ - ' **/*.md'
14+ - ' LICENSE'
15+ - ' .gitignore'
16+
17+ concurrency :
18+ group : docker-build-${{ github.ref }}
19+ cancel-in-progress : true
20+
21+ jobs :
22+ discover :
23+ runs-on : ubuntu-latest
24+ outputs :
25+ matrix : ${{ steps.set-matrix.outputs.matrix }}
26+ steps :
27+ - name : Checkout
28+ uses : actions/checkout@v4
29+
30+ - name : Discover Dockerfiles in docker/
31+ id : set-matrix
32+ shell : bash
33+ run : |
34+ set -euo pipefail
35+ files=(docker/*)
36+ include=()
37+ for file in "${files[@]}"; do
38+ if [[ -f "$file" ]]; then
39+ name="$(basename "$file" | tr '.' '-')"
40+ filename="$(basename "$file")"
41+ if [[ "$filename" == "Dockerfile" ]]; then
42+ tag="latest"
43+ else
44+ tag="${filename#Dockerfile.}"
45+ fi
46+ include+=("{\"name\":\"$name\",\"file\":\"$file\",\"tag\":\"$tag\"}")
47+ fi
48+ done
49+
50+ if [[ ${#include[@]} -eq 0 ]]; then
51+ echo "No files found in docker/" >&2
52+ exit 1
53+ fi
54+
55+ matrix="{\"include\":[$(IFS=,; echo "${include[*]}")]}"
56+ echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
57+
58+ build :
59+ runs-on : ubuntu-latest
60+ needs : discover
61+ strategy :
62+ fail-fast : false
63+ matrix : ${{ fromJson(needs.discover.outputs.matrix) }}
64+ steps :
65+ - name : Checkout
66+ uses : actions/checkout@v4
67+
68+ - name : Set up QEMU
69+ uses : docker/setup-qemu-action@v3
70+
71+ - name : Set up Docker Buildx
72+ uses : docker/setup-buildx-action@v3
73+
74+ - name : Log in to GHCR
75+ uses : docker/login-action@v3
76+ with :
77+ registry : ghcr.io
78+ username : ${{ github.actor }}
79+ password : ${{ secrets.GITHUB_TOKEN }}
80+
81+ - name : Build and publish ${{ matrix.file }} (amd64 + arm64)
82+ uses : docker/build-push-action@v6
83+ with :
84+ context : .
85+ file : ${{ matrix.file }}
86+ push : true
87+ tags : ghcr.io/${{ github.repository }}:${{ matrix.tag }}
88+ platforms : linux/amd64,linux/arm64
89+ cache-from : type=gha
90+ cache-to : type=gha,mode=max
0 commit comments