Skip to content

Commit e01f595

Browse files
committed
add gnu static action
1 parent 4558e2a commit e01f595

1 file changed

Lines changed: 124 additions & 0 deletions

File tree

.github/workflows/static.yaml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
push: ${{ toJson((steps.check.outputs.ref || (github.event_name == 'workflow_dispatch' && inputs.version) || startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')) && true || false) }}
3737
platforms: ${{ steps.matrix.outputs.platforms }}
3838
metadata: ${{ steps.matrix.outputs.metadata }}
39+
gnu_metadata: ${{ steps.matrix.outputs.gnu_metadata }}
3940
ref: ${{ steps.check.outputs.ref }}
4041
steps:
4142
- name: Get version
@@ -59,9 +60,11 @@ jobs:
5960
id: matrix
6061
run: |
6162
METADATA="$(docker buildx bake --print static-builder | jq -c)"
63+
GNU_METADATA="$(docker buildx bake --print gnu-static | jq -c)"
6264
{
6365
echo metadata="${METADATA}"
6466
echo platforms="$(jq -c 'first(.target[]) | .platforms' <<< "${METADATA}")"
67+
echo gnu_metadata="${GNU_METADATA}"
6568
} >> "${GITHUB_OUTPUT}"
6669
env:
6770
SHA: ${{ github.sha }}
@@ -177,12 +180,113 @@ jobs:
177180
env:
178181
BINARY: ./frankenphp-linux-${{ matrix.platform == 'linux/amd64' && 'x86_64' || 'aarch64' }}${{ matrix.debug && '-debug' || '' }}${{ matrix.mimalloc && '-mimalloc' || '' }}
179182

183+
build-linux-gnu:
184+
strategy:
185+
fail-fast: false
186+
matrix:
187+
platform: ${{ fromJson(needs.prepare.outputs.platforms) }}
188+
name: Build ${{ matrix.platform }} GNU static binary
189+
runs-on: ubuntu-24.04
190+
needs: [prepare]
191+
steps:
192+
- name: Prepare
193+
id: prepare
194+
run: |
195+
platform=${{ matrix.platform }}
196+
echo "sanitized_platform=${platform//\//-}" >> "${GITHUB_OUTPUT}"
197+
- uses: actions/checkout@v4
198+
with:
199+
ref: ${{ needs.prepare.outputs.ref }}
200+
- name: Set up Docker Buildx
201+
uses: docker/setup-buildx-action@v3
202+
with:
203+
platforms: ${{ matrix.platform }}
204+
- name: Login to DockerHub
205+
if: ${{ fromJson(needs.prepare.outputs.push) }}
206+
uses: docker/login-action@v3
207+
with:
208+
username: ${{ secrets.REGISTRY_USERNAME }}
209+
password: ${{ secrets.REGISTRY_PASSWORD }}
210+
- name: Build
211+
id: build
212+
uses: docker/bake-action@v6
213+
with:
214+
pull: true
215+
load: ${{ !fromJson(needs.prepare.outputs.push) }}
216+
targets: gnu-static
217+
set: |
218+
${{ (github.event_name == 'pull_request' || matrix.platform == 'linux/arm64') && 'gnu-static.args.NO_COMPRESS=1' || '' }}
219+
*.tags=
220+
*.platform=${{ matrix.platform }}
221+
*.cache-from=type=gha,scope=${{ needs.prepare.outputs.ref || github.ref }}-gnu-static
222+
*.cache-from=type=gha,scope=refs/heads/main-gnu-static
223+
*.cache-to=type=gha,scope=${{ needs.prepare.outputs.ref || github.ref }}-gnu-static,ignore-error=true
224+
${{ fromJson(needs.prepare.outputs.push) && format('*.output=type=image,name={0}-gnu,push-by-digest=true,name-canonical=true,push=true', env.IMAGE_NAME) || '' }}
225+
env:
226+
SHA: ${{ github.sha }}
227+
VERSION: ${{ (github.ref_type == 'tag' && github.ref_name) || needs.prepare.outputs.ref || 'dev' }}
228+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
229+
- # Workaround for https://github.com/actions/runner/pull/2477#issuecomment-1501003600
230+
name: Export metadata
231+
if: fromJson(needs.prepare.outputs.push)
232+
run: |
233+
mkdir -p /tmp/metadata-gnu
234+
235+
# shellcheck disable=SC2086
236+
digest=$(jq -r '."gnu-static"."containerimage.digest"' <<< ${METADATA})
237+
touch "/tmp/metadata-gnu/${digest#sha256:}"
238+
env:
239+
METADATA: ${{ steps.build.outputs.metadata }}
240+
- name: Upload metadata
241+
if: fromJson(needs.prepare.outputs.push)
242+
uses: actions/upload-artifact@v4
243+
with:
244+
name: metadata-gnu-static-${{ steps.prepare.outputs.sanitized_platform }}
245+
path: /tmp/metadata-gnu/*
246+
if-no-files-found: error
247+
retention-days: 1
248+
- name: Copy binary
249+
run: |
250+
# shellcheck disable=SC2034
251+
digest=$(jq -r '."gnu-static"."${{ fromJson(needs.prepare.outputs.push) && 'containerimage.digest' || 'containerimage.config.digest' }}"' <<< "${METADATA}")
252+
docker create --platform=${{ matrix.platform }} --name gnu-static "${{ fromJson(needs.prepare.outputs.push) && format('{0}-gnu@{1}', env.IMAGE_NAME, '${digest}') || '${digest}' }}"
253+
docker cp "gnu-static:/go/src/app/dist/${BINARY}" "${BINARY}-gnu"
254+
env:
255+
METADATA: ${{ steps.build.outputs.metadata }}
256+
BINARY: frankenphp-linux-${{ matrix.platform == 'linux/amd64' && 'x86_64' || 'aarch64' }}
257+
- name: Upload artifact
258+
if: ${{ !fromJson(needs.prepare.outputs.push) }}
259+
uses: actions/upload-artifact@v4
260+
with:
261+
name: frankenphp-linux-${{ matrix.platform == 'linux/amd64' && 'x86_64' || 'aarch64' }}-gnu
262+
path: frankenphp-linux-${{ matrix.platform == 'linux/amd64' && 'x86_64' || 'aarch64' }}-gnu
263+
- name: Upload assets
264+
if: fromJson(needs.prepare.outputs.push) && (needs.prepare.outputs.ref || github.ref_type == 'tag')
265+
run: gh release upload "${{ (github.ref_type == 'tag' && github.ref_name) || needs.prepare.outputs.ref }}" frankenphp-linux-${{ matrix.platform == 'linux/amd64' && 'x86_64' || 'aarch64' }}-gnu --repo dunglas/frankenphp --clobber
266+
env:
267+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
268+
- if: fromJson(needs.prepare.outputs.push) && (needs.prepare.outputs.ref || github.ref_type == 'tag')
269+
uses: actions/attest-build-provenance@v2
270+
with:
271+
subject-path: ${{ github.workspace }}/frankenphp-linux-*-gnu
272+
- name: Run sanity checks
273+
run: |
274+
"${BINARY}" version
275+
"${BINARY}" list-modules | grep frankenphp
276+
"${BINARY}" list-modules | grep http.encoders.br
277+
"${BINARY}" list-modules | grep http.handlers.mercure
278+
"${BINARY}" list-modules | grep http.handlers.mercure
279+
"${BINARY}" list-modules | grep http.handlers.vulcain
280+
env:
281+
BINARY: ./frankenphp-linux-${{ matrix.platform == 'linux/amd64' && 'x86_64' || 'aarch64' }}-gnu
282+
180283
# Adapted from https://docs.docker.com/build/ci/github-actions/multi-platform/
181284
push:
182285
runs-on: ubuntu-24.04
183286
needs:
184287
- prepare
185288
- build-linux
289+
- build-linux-gnu
186290
if: fromJson(needs.prepare.outputs.push)
187291
steps:
188292
- name: Download metadata
@@ -191,6 +295,12 @@ jobs:
191295
pattern: metadata-static-builder-*
192296
path: /tmp/metadata
193297
merge-multiple: true
298+
- name: Download GNU metadata
299+
uses: actions/download-artifact@v4
300+
with:
301+
pattern: metadata-gnu-static-*
302+
path: /tmp/metadata-gnu
303+
merge-multiple: true
194304
- name: Set up Docker Buildx
195305
uses: docker/setup-buildx-action@v3
196306
- name: Login to DockerHub
@@ -206,12 +316,26 @@ jobs:
206316
$(printf "${IMAGE_NAME}@sha256:%s " *)
207317
env:
208318
METADATA: ${{ needs.prepare.outputs.metadata }}
319+
- name: Create GNU manifest list and push
320+
working-directory: /tmp/metadata-gnu
321+
run: |
322+
# shellcheck disable=SC2046,SC2086
323+
docker buildx imagetools create $(jq -cr '.target."gnu-static".tags | map("-t " + . + "-gnu") | join(" ")' <<< "${GNU_METADATA}") \
324+
$(printf "${IMAGE_NAME}-gnu@sha256:%s " *)
325+
env:
326+
GNU_METADATA: ${{ needs.prepare.outputs.gnu_metadata }}
209327
- name: Inspect image
210328
run: |
211329
# shellcheck disable=SC2046,SC2086
212330
docker buildx imagetools inspect "$(jq -cr '.target."static-builder".tags | first' <<< "${METADATA}")"
213331
env:
214332
METADATA: ${{ needs.prepare.outputs.metadata }}
333+
- name: Inspect GNU image
334+
run: |
335+
# shellcheck disable=SC2046,SC2086
336+
docker buildx imagetools inspect "$(jq -cr '.target."gnu-static".tags | first' <<< "${GNU_METADATA}")-gnu"
337+
env:
338+
GNU_METADATA: ${{ needs.prepare.outputs.gnu_metadata }}
215339

216340
build-mac:
217341
strategy:

0 commit comments

Comments
 (0)