Skip to content

Commit 9046b97

Browse files
authored
ci: rebuild Docker images (if necessary) and binaries every night (#379)
1 parent cb02ce4 commit 9046b97

File tree

2 files changed

+92
-31
lines changed

2 files changed

+92
-31
lines changed

.github/workflows/docker.yaml

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,77 @@ on:
1111
- v*.*.*
1212
workflow_dispatch:
1313
inputs: {}
14+
schedule:
15+
- cron: '0 4 * * *'
1416
jobs:
1517
prepare:
1618
runs-on: ubuntu-latest
1719
outputs:
18-
# Push only if it's a tag or if we're committing in the main branch
19-
push: ${{ toJson(startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')) }}
20+
# Push if it's a scheduled job, a tag, or if we're committing to the main branch
21+
push: ${{ toJson(github.event_name == 'schedule' || startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')) }}
2022
variants: ${{ steps.matrix.outputs.variants }}
2123
platforms: ${{ steps.matrix.outputs.platforms }}
2224
metadata: ${{ steps.matrix.outputs.metadata }}
23-
php_version: ${{ steps.matrix.outputs.php_version }}
25+
php_version: ${{ steps.check.outputs.php_version }}
26+
skip: ${{ steps.check.outputs.skip }}
27+
ref: ${{ steps.check.outputs.ref }}
2428
steps:
29+
-
30+
name: Check PHP versions
31+
id: check
32+
run: |
33+
PHP_82_LATEST=$(skopeo inspect docker://docker.io/library/php:8.2 --override-os linux --override-arch amd64 | jq -r '.Env[] | select(test("^PHP_VERSION=")) | sub("^PHP_VERSION="; "")')
34+
PHP_83_LATEST=$(skopeo inspect docker://docker.io/library/php:8.3 --override-os linux --override-arch amd64 | jq -r '.Env[] | select(test("^PHP_VERSION=")) | sub("^PHP_VERSION="; "")')
35+
echo php_version="${PHP_83_LATEST},${PHP_82_LATEST}" >> "${GITHUB_OUTPUT}"
36+
37+
# Check if the Docker images must be rebuilt
38+
if [[ "${GITHUB_EVENT_NAME}" != "schedule" ]]; then
39+
echo skip=false >> "${GITHUB_OUTPUT}"
40+
exit 0
41+
fi
42+
43+
FRANKENPHP_82_LATEST=$(skopeo inspect docker://docker.io/dunglas/frankenphp:latest-php8.2 --override-os linux --override-arch amd64 | jq -r '.Env[] | select(test("^PHP_VERSION=")) | sub("^PHP_VERSION="; "")')
44+
FRANKENPHP_83_LATEST=$(skopeo inspect docker://docker.io/dunglas/frankenphp:latest-php8.3 --override-os linux --override-arch amd64 | jq -r '.Env[] | select(test("^PHP_VERSION=")) | sub("^PHP_VERSION="; "")')
45+
46+
if [[ "${FRANKENPHP_82_LATEST}" == "${PHP_82_LATEST}" ]] && [[ "${FRANKENPHP_83_LATEST}" == "${PHP_83_LATEST}" ]]; then
47+
echo skip=true >> "${GITHUB_OUTPUT}"
48+
exit 0
49+
fi
50+
51+
{
52+
echo ref="$(gh release view --repo dunglas/frankenphp --json tagName --jq '.tagName')"
53+
echo skip=false
54+
} >> "${GITHUB_OUTPUT}"
2555
-
2656
uses: actions/checkout@v4
57+
if: ${{ !fromJson(steps.check.outputs.skip) }}
58+
with:
59+
ref: ${{ steps.check.outputs.ref }}
2760
-
2861
name: Set up Docker Buildx
2962
uses: docker/setup-buildx-action@v3
3063
with:
3164
version: latest
3265
-
3366
name: Create variants matrix
67+
if: ${{ !fromJson(steps.check.outputs.skip) }}
3468
id: matrix
3569
run: |
36-
# Fetch latest versions of PHP
37-
PHP_82_LATEST=$(skopeo inspect docker://docker.io/library/php:8.2 --override-os linux --override-arch amd64 | jq -r '.Env[] | select(test("^PHP_VERSION=")) | sub("^PHP_VERSION="; "")')
38-
PHP_83_LATEST=$(skopeo inspect docker://docker.io/library/php:8.3 --override-os linux --override-arch amd64 | jq -r '.Env[] | select(test("^PHP_VERSION=")) | sub("^PHP_VERSION="; "")')
39-
export PHP_VERSION="${PHP_83_LATEST},${PHP_82_LATEST}"
40-
4170
METADATA="$(docker buildx bake --print | jq -c)"
42-
4371
{
44-
echo php_version="$PHP_VERSION"
45-
echo metadata="$METADATA"
46-
echo variants="$(jq -c '.group.default.targets|map(sub("runner-|builder-"; ""))|unique' <<< "$METADATA")"
47-
echo platforms="$(jq -c 'first(.target[]) | .platforms' <<< "$METADATA")"
48-
} >> "$GITHUB_OUTPUT"
72+
echo metadata="${METADATA}"
73+
echo variants="$(jq -c '.group.default.targets|map(sub("runner-|builder-"; ""))|unique' <<< "${METADATA}")"
74+
echo platforms="$(jq -c 'first(.target[]) | .platforms' <<< "${METADATA}")"
75+
} >> "${GITHUB_OUTPUT}"
4976
env:
5077
SHA: ${{ github.sha }}
51-
VERSION: ${{ github.ref_type == 'tag' && github.ref_name || github.sha }}
78+
VERSION: ${{ (github.ref_type == 'tag' && github.ref_name) || steps.check.outputs.ref || github.sha }}
79+
PHP_VERSION: ${{ steps.check.outputs.php_version }}
5280
build:
5381
runs-on: ubuntu-latest
5482
needs:
5583
- prepare
84+
if: ${{ !fromJson(needs.prepare.outputs.skip) }}
5685
strategy:
5786
fail-fast: false
5887
matrix:
@@ -69,6 +98,8 @@ jobs:
6998
steps:
7099
-
71100
uses: actions/checkout@v4
101+
with:
102+
ref: ${{ needs.prepare.outputs.ref }}
72103
-
73104
name: Set up QEMU
74105
if: matrix.qemu
@@ -108,7 +139,7 @@ jobs:
108139
${{ fromJson(needs.prepare.outputs.push) && '*.output=type=image,name=dunglas/frankenphp,push-by-digest=true,name-canonical=true,push=true' || '' }}
109140
env:
110141
SHA: ${{ github.sha }}
111-
VERSION: ${{ github.ref_type == 'tag' && github.ref_name || github.sha }}
142+
VERSION: ${{ github.ref_type == 'tag' && github.ref_name || needs.prepare.outputs.ref || github.sha }}
112143
PHP_VERSION: ${{ needs.prepare.outputs.php_version }}
113144
-
114145
# Workaround for https://github.com/actions/runner/pull/2477#issuecomment-1501003600
@@ -118,11 +149,11 @@ jobs:
118149
mkdir -p /tmp/metadata/builder /tmp/metadata/runner
119150
120151
# shellcheck disable=SC2086
121-
builderDigest=$(jq -r '."builder-${{ matrix.variant }}"."containerimage.digest"' <<< $METADATA)
152+
builderDigest=$(jq -r '."builder-${{ matrix.variant }}"."containerimage.digest"' <<< ${METADATA})
122153
touch "/tmp/metadata/builder/${builderDigest#sha256:}"
123154
124155
# shellcheck disable=SC2086
125-
runnerDigest=$(jq -r '."runner-${{ matrix.variant }}"."containerimage.digest"' <<< $METADATA)
156+
runnerDigest=$(jq -r '."runner-${{ matrix.variant }}"."containerimage.digest"' <<< ${METADATA})
126157
touch "/tmp/metadata/runner/${runnerDigest#sha256:}"
127158
env:
128159
METADATA: ${{ steps.build.outputs.metadata }}
@@ -150,7 +181,7 @@ jobs:
150181
continue-on-error: ${{ fromJson(needs.prepare.outputs.push) }}
151182
run: |
152183
docker run --platform=${{ matrix.platform }} --rm \
153-
"$(jq -r '."builder-${{ matrix.variant }}"."containerimage.config.digest"' <<< "$METADATA")" \
184+
"$(jq -r '."builder-${{ matrix.variant }}"."containerimage.config.digest"' <<< "${METADATA}")" \
154185
sh -c 'go test ${{ matrix.race }} -v ./... && cd caddy && go test ${{ matrix.race }} -v ./...'
155186
env:
156187
METADATA: ${{ steps.build.outputs.metadata }}
@@ -189,14 +220,14 @@ jobs:
189220
working-directory: /tmp/metadata
190221
run: |
191222
# shellcheck disable=SC2046,SC2086
192-
docker buildx imagetools create $(jq -cr '.target."${{ matrix.target }}-${{ matrix.variant }}".tags | map("-t " + .) | join(" ")' <<< $METADATA) \
223+
docker buildx imagetools create $(jq -cr '.target."${{ matrix.target }}-${{ matrix.variant }}".tags | map("-t " + .) | join(" ")' <<< ${METADATA}) \
193224
$(printf 'dunglas/frankenphp@sha256:%s ' *)
194225
env:
195226
METADATA: ${{ needs.prepare.outputs.metadata }}
196227
-
197228
name: Inspect image
198229
run: |
199230
# shellcheck disable=SC2046,SC2086
200-
docker buildx imagetools inspect $(jq -cr '.target."${{ matrix.target }}-${{ matrix.variant }}".tags | first' <<< $METADATA)
231+
docker buildx imagetools inspect $(jq -cr '.target."${{ matrix.target }}-${{ matrix.variant }}".tags | first' <<< ${METADATA})
201232
env:
202233
METADATA: ${{ needs.prepare.outputs.metadata }}

.github/workflows/static.yaml

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ on:
1111
- v*.*.*
1212
workflow_dispatch:
1313
inputs: {}
14+
schedule:
15+
- cron: '0 0 * * *'
1416
jobs:
1517
release:
1618
if: github.ref_type == 'tag'
@@ -24,20 +26,33 @@ jobs:
2426
allowUpdates: true
2527
omitBodyDuringUpdate: true
2628
omitNameDuringUpdate: true
29+
prepare:
30+
runs-on: ubuntu-latest
31+
outputs:
32+
ref: ${{ steps.ref.outputs.ref }}
33+
steps:
34+
-
35+
name: Get latest release
36+
id: ref
37+
if: github.event_name == 'schedule'
38+
run: echo ref="$(gh release view --repo dunglas/frankenphp --json tagName --jq '.tagName')" >> "${GITHUB_OUTPUT}"
2739
build-linux:
2840
name: Build Linux x86_64 binary
2941
runs-on: ubuntu-latest
42+
needs: [ prepare ]
3043
steps:
3144
-
3245
uses: actions/checkout@v4
46+
with:
47+
ref: ${{ needs.prepare.outputs.ref }}
3348
-
3449
name: Set up Docker Buildx
3550
uses: docker/setup-buildx-action@v3
3651
with:
3752
version: latest
3853
-
3954
name: Login to DockerHub
40-
if: startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')
55+
if: github.event_name == 'schedule' || startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')
4156
uses: docker/login-action@v3
4257
with:
4358
username: ${{secrets.REGISTRY_USERNAME}}
@@ -48,8 +63,8 @@ jobs:
4863
uses: docker/bake-action@v4
4964
with:
5065
pull: true
51-
load: ${{toJson(!startsWith(github.ref, 'refs/tags/') && (github.ref != 'refs/heads/main' || github.event_name == 'pull_request'))}}
52-
push: ${{toJson(startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request'))}}
66+
load: ${{toJson(github.event_name != 'schedule' && !startsWith(github.ref, 'refs/tags/') && (github.ref != 'refs/heads/main' || github.event_name == 'pull_request'))}}
67+
push: ${{toJson(github.event_name == 'schedule' || startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request'))}}
5368
targets: static-builder
5469
set: |
5570
*.cache-from=type=gha,scope=${{github.ref}}-static-builder
@@ -58,25 +73,27 @@ jobs:
5873
env:
5974
LATEST: '1' # TODO: unset this variable when releasing the first stable version
6075
SHA: ${{github.sha}}
61-
VERSION: ${{github.ref_type == 'tag' && github.ref_name || github.sha}}
76+
VERSION: ${{ (github.ref_type == 'tag' && github.ref_name) || needs.prepare.outputs.ref || github.sha}}
6277
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6378
-
6479
name: Pull Docker image
65-
if: startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')
80+
if: github.event_name == 'schedule' || startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')
6681
run: docker pull dunglas/frankenphp:static-builder
6782
-
6883
name: Copy binary
6984
run: docker cp "$(docker create --name static-builder dunglas/frankenphp:static-builder):/go/src/app/dist/frankenphp-linux-x86_64" frankenphp-linux-x86_64 ; docker rm static-builder
7085
-
7186
name: Upload asset
72-
if: github.ref_type == 'tag'
87+
if: github.event_name == 'schedule' || github.ref_type == 'tag'
7388
uses: ncipollo/release-action@v1
7489
with:
90+
tag: ${{ (github.ref_type == 'tag' && github.ref_name) || needs.prepare.outputs.ref }}
7591
generateReleaseNotes: true
7692
allowUpdates: true
7793
omitBodyDuringUpdate: true
7894
omitNameDuringUpdate: true
7995
artifacts: frankenphp-linux-x86_64
96+
replacesArtifacts: true
8097
-
8198
name: Upload artifact
8299
if: github.ref_type == 'branch'
@@ -86,11 +103,14 @@ jobs:
86103
build-mac:
87104
name: Build macOS x86_64 binaries
88105
runs-on: macos-latest
106+
needs: [ prepare ]
89107
env:
90108
HOMEBREW_NO_AUTO_UPDATE: 1
91109
steps:
92110
-
93111
uses: actions/checkout@v4
112+
with:
113+
ref: ${{ needs.prepare.outputs.ref }}
94114
-
95115
uses: actions/setup-go@v5
96116
with:
@@ -101,25 +121,35 @@ jobs:
101121
-
102122
name: Set FRANKENPHP_VERSION
103123
run: |
104-
if [ "$GITHUB_REF_TYPE" == "tag" ]; then export FRANKENPHP_VERSION=${GITHUB_REF_NAME:1}; else export FRANKENPHP_VERSION=$GITHUB_SHA; fi
105-
echo "FRANKENPHP_VERSION=$FRANKENPHP_VERSION" >> "$GITHUB_ENV"
124+
if [ "${GITHUB_REF_TYPE}" == "tag" ]; then
125+
export FRANKENPHP_VERSION=${GITHUB_REF_NAME:1}
126+
elif [ "${GITHUB_EVENT_NAME}" == "schedule" ]; then
127+
export FRANKENPHP_VERSION="${{ needs.prepare.outputs.ref }}"
128+
else
129+
export FRANKENPHP_VERSION=${GITHUB_SHA}
130+
fi
131+
132+
echo "FRANKENPHP_VERSION=${FRANKENPHP_VERSION}" >> "${GITHUB_ENV}"
106133
-
107134
name: Build FrankenPHP
108135
run: ./build-static.sh
109136
env:
110137
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111138
-
112139
name: Upload asset
113-
if: github.ref_type == 'tag'
140+
if: github.event_name == 'schedule' || github.ref_type == 'tag'
114141
uses: ncipollo/release-action@v1
115142
with:
143+
tag: ${{ (github.ref_type == 'tag' && github.ref_name) || needs.prepare.outputs.ref }}
116144
generateReleaseNotes: true
117145
allowUpdates: true
118146
omitBodyDuringUpdate: true
119147
omitNameDuringUpdate: true
120148
artifacts: dist/frankenphp-mac-x86_64
149+
replacesArtifacts: true
121150
-
122-
name: Upload binary
151+
name: Upload artifact
152+
if: github.ref_type == 'branch'
123153
uses: actions/upload-artifact@v3
124154
with:
125155
path: dist/frankenphp-mac-x86_64

0 commit comments

Comments
 (0)