From 54beb0576a69443b22ab3dcf2321c2421803ff80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 17 Jul 2023 16:19:40 +0200 Subject: [PATCH] feat: add FrankenPHP version to the version command --- .github/workflows/docker.yml | 17 ++++++++--------- Dockerfile | 4 +++- alpine.Dockerfile | 6 ++++-- docker-bake.hcl | 3 +++ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 08f714f4dd..b20fe4f419 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -28,12 +28,12 @@ jobs: version: latest - name: Create variants matrix - id: matrix + id: matrix run: | - METADATA=$(docker buildx bake --print) + METADATA=$(docker buildx bake --print | jq -c) + echo "metadata=$METADATA" >> "$GITHUB_OUTPUT" echo "variants=$(jq -c '.group.default.targets|map(sub("runner-|builder-"; ""))|unique' <<< $METADATA)" >> "$GITHUB_OUTPUT" echo "platforms=$(jq -c 'first(.target[]) | .platforms' <<< $METADATA)" >> "$GITHUB_OUTPUT" - echo "metadata=$(jq -c <<< $METADATA)" >> "$GITHUB_OUTPUT" env: LATEST: '1' # TODO: unset this variable when releasing the first tagged version SHA: ${{github.sha}} @@ -83,6 +83,7 @@ jobs: uses: docker/bake-action@v3 with: pull: true + load: ${{!fromJson(needs.prepare.outputs.push)}} targets: | builder-${{matrix.variant}} runner-${{matrix.variant}} @@ -93,7 +94,7 @@ jobs: *.cache-from=type=gha,scope=${{github.ref}}-${{matrix.platform}} *.cache-from=type=gha,scope=refs/heads/main-${{matrix.platform}} *.cache-to=type=gha,scope=${{github.ref}}-${{matrix.platform}} - *.output=type=image,name=dunglas/frankenphp,push-by-digest=true,name-canonical=true,push=${{ needs.prepare.outputs.push }} + ${{fromJson(needs.prepare.outputs.push) && '*.output=type=image,name=dunglas/frankenphp,push-by-digest=true,name-canonical=true,push=true' || ''}} env: LATEST: '1' # TODO: unset this variable when releasing the first tagged version SHA: ${{github.sha}} @@ -133,11 +134,11 @@ jobs: - name: Run tests if: '!matrix.qemu' - continue-on-error: true + continue-on-error: ${{fromJson(needs.prepare.outputs.push)}} run: | docker run --platform=${{matrix.platform}} --rm \ - dunglas/frankenphp@$(jq -r '."builder-${{matrix.variant}}"."containerimage.digest"' <<< $METADATA) \ - "sh -c 'go test ${{matrix.race}} -v ./... && cd caddy && go test ${{matrix.race}} -v ./...'" + $(jq -r '."builder-${{matrix.variant}}"."containerimage.config.digest"' <<< $METADATA) \ + "sh -c 'frankenphp version && go test ${{matrix.race}} -v ./... && cd caddy && go test ${{matrix.race}} -v ./...'" env: METADATA: ${{steps.build.outputs.metadata}} @@ -160,8 +161,6 @@ jobs: name: metadata-${{matrix.target}}-${{matrix.variant}} path: /tmp/metadata - - run: ls -R /tmp/metadata - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 with: diff --git a/Dockerfile b/Dockerfile index a0ec4459f2..59f7a4cabc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ # syntax=docker/dockerfile:1 FROM php-base AS builder +ARG FRANKENPHP_VERSION='dev' + COPY --from=golang-base /usr/local/go/bin/go /usr/local/bin/go COPY --from=golang-base /usr/local/go /usr/local/go @@ -40,7 +42,7 @@ COPY testdata testdata ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS" CGO_CFLAGS=$PHP_CFLAGS CGO_CPPFLAGS=$PHP_CPPFLAGS RUN cd caddy/frankenphp && \ - go build && \ + go build -ldflags "-X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION Caddy'" && \ cp frankenphp /usr/local/bin && \ cp /go/src/app/caddy/frankenphp/Caddyfile /etc/Caddyfile diff --git a/alpine.Dockerfile b/alpine.Dockerfile index 67e3309b77..5fa61d6b5b 100644 --- a/alpine.Dockerfile +++ b/alpine.Dockerfile @@ -1,6 +1,8 @@ # syntax=docker/dockerfile:1 FROM php-base AS builder +ARG FRANKENPHP_VERSION='dev' + COPY --from=golang-base /usr/local/go/bin/go /usr/local/bin/go COPY --from=golang-base /usr/local/go /usr/local/go @@ -39,8 +41,8 @@ COPY testdata testdata ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS" CGO_CFLAGS=$PHP_CFLAGS CGO_CPPFLAGS=$PHP_CPPFLAGS RUN cd caddy/frankenphp && \ - go build && \ - cp frankenphp /usr/local/bin && \ + go build -ldflags "-X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION Caddy'" && \ + cp frankenphp /usr/local/bin && \ cp /go/src/app/caddy/frankenphp/Caddyfile /etc/Caddyfile ENTRYPOINT ["/bin/sh","-c"] diff --git a/docker-bake.hcl b/docker-bake.hcl index b5930d3a9c..2996b56387 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -87,4 +87,7 @@ target "default" { "org.opencontainers.image.version" = VERSION "org.opencontainers.image.revision" = SHA } + args = { + FRANKENPHP_VERSION = VERSION + } }