blob: 92276f65f5ec97e925f725c1702d3a4ab19d41a9 (
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
86
87
88
89
90
91
92
93
94
|
name: "images4docker: Build"
on:
workflow_dispatch:
workflow_call:
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 image
uses: docker/build-push-action@v6
with:
context: images4docker
file: ${{ matrix.dockerfile }}
push: false
load: true
provenance: false
tags: |
ghcr.io/project-tick/project-tick/${{ matrix.name }}:latest
ghcr.io/project-tick/project-tick/${{ matrix.name }}:${{ steps.tagmeta.outputs.sha_tag }}
ghcr.io/project-tick/project-tick/${{ matrix.name }}:${{ steps.tagmeta.outputs.immutable_tag }}
- name: Push image (with retry)
run: |
push_all() {
docker push "ghcr.io/project-tick/project-tick/${{ matrix.name }}:latest" \
&& docker push "ghcr.io/project-tick/project-tick/${{ matrix.name }}:${{ steps.tagmeta.outputs.sha_tag }}" \
&& docker push "ghcr.io/project-tick/project-tick/${{ matrix.name }}:${{ steps.tagmeta.outputs.immutable_tag }}"
}
for attempt in 1 2 3 4 5; do
push_all && exit 0
echo "Push attempt $attempt/5 failed, retrying in 30s..."
sleep 30
done
exit 1
|