From 341b0240c9697fc5b956f880ef604f2cf7186c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Wed, 19 Mar 2025 13:27:28 +0100 Subject: [PATCH] ci: include version in BuildInfo and Prometheus metrics (#1418) --- .dockerignore | 25 ++++++++++------------- .github/workflows/static.yaml | 2 ++ .gitignore | 3 +++ Dockerfile | 38 +++++++++++++++++------------------ alpine.Dockerfile | 35 ++++++++++++++++---------------- build-static.sh | 1 + static-builder.Dockerfile | 4 +--- 7 files changed, 54 insertions(+), 54 deletions(-) diff --git a/.dockerignore b/.dockerignore index 39f5c223..16910ad2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,14 +1,11 @@ -# ignored -**/* - -# authorized -!**/Caddyfile -!**/*.go -!**/go.* -!**/*.c -!**/*.h -!testdata/*.php -!testdata/*.txt -!build-static.sh -!app.tar -!app_checksum.txt +/caddy/frankenphp/frankenphp +/internal/testserver/testserver +/internal/testcli/testcli +/dist +.DS_Store +.idea/ +.vscode/ +__debug_bin +frankenphp.test +caddy/frankenphp/Build +*.log diff --git a/.github/workflows/static.yaml b/.github/workflows/static.yaml index 62b3cfbb..8b32cc9b 100644 --- a/.github/workflows/static.yaml +++ b/.github/workflows/static.yaml @@ -168,6 +168,7 @@ jobs: - name: Run sanity checks run: | "${BINARY}" version + "${BINARY}" build-info "${BINARY}" list-modules | grep frankenphp "${BINARY}" list-modules | grep http.encoders.br "${BINARY}" list-modules | grep http.handlers.mercure @@ -262,6 +263,7 @@ jobs: - name: Run sanity checks run: | "${BINARY}" version + "${BINARY}" build-info "${BINARY}" list-modules | grep frankenphp "${BINARY}" list-modules | grep http.encoders.br "${BINARY}" list-modules | grep http.handlers.mercure diff --git a/.gitignore b/.gitignore index e61ecb61..16910ad2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,10 @@ /internal/testserver/testserver /internal/testcli/testcli /dist +.DS_Store .idea/ .vscode/ __debug_bin frankenphp.test +caddy/frankenphp/Build +*.log diff --git a/Dockerfile b/Dockerfile index 24312888..a1e80415 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,7 +61,8 @@ ENV PATH=/usr/local/go/bin:$PATH # This is required to link the FrankenPHP binary to the PHP binary RUN apt-get update && \ apt-get -y --no-install-recommends install \ - cmake \ + cmake \ + git \ libargon2-dev \ libbrotli-dev \ libcurl4-openssl-dev \ @@ -75,21 +76,6 @@ RUN apt-get update && \ && \ apt-get clean -WORKDIR /go/src/app - -COPY --link go.mod go.sum ./ -RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get - -WORKDIR /go/src/app/caddy -COPY --link caddy/go.mod caddy/go.sum ./ -RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get - -WORKDIR /go/src/app -COPY --link *.* ./ -COPY --link caddy caddy -COPY --link internal internal -COPY --link testdata testdata - # Install e-dant/watcher (necessary for file watching) WORKDIR /usr/local/src/watcher RUN curl -s https://api.github.com/repos/e-dant/watcher/releases/latest | \ @@ -104,6 +90,18 @@ RUN curl -s https://api.github.com/repos/e-dant/watcher/releases/latest | \ cmake --install build && \ ldconfig +WORKDIR /go/src/app + +COPY --link go.mod go.sum ./ +RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get + +WORKDIR /go/src/app/caddy +COPY --link caddy/go.mod caddy/go.sum ./ +RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get + +WORKDIR /go/src/app +COPY --link . ./ + # See https://github.com/docker-library/php/blob/master/8.3/bookworm/zts/Dockerfile#L57-L59 for PHP values ENV CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $PHP_CFLAGS" ENV CGO_CPPFLAGS=$PHP_CPPFLAGS @@ -112,10 +110,11 @@ ENV CGO_LDFLAGS="-L/usr/local/lib -lssl -lcrypto -lreadline -largon2 -lcurl -lon RUN echo $CGO_LDFLAGS WORKDIR /go/src/app/caddy/frankenphp -RUN GOBIN=/usr/local/bin go install -tags 'nobadger,nomysql,nopgx' -ldflags "-w -s -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" && \ +RUN GOBIN=/usr/local/bin go install -tags 'nobadger,nomysql,nopgx' -ldflags "-w -s -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" -buildvcs=true && \ setcap cap_net_bind_service=+ep /usr/local/bin/frankenphp && \ cp Caddyfile /etc/caddy/Caddyfile && \ - frankenphp version + frankenphp version && \ + frankenphp build-info WORKDIR /go/src/app @@ -133,4 +132,5 @@ RUN apt-get install -y --no-install-recommends libstdc++6 && \ COPY --from=builder /usr/local/bin/frankenphp /usr/local/bin/frankenphp RUN setcap cap_net_bind_service=+ep /usr/local/bin/frankenphp && \ - frankenphp version + frankenphp version && \ + frankenphp build-info diff --git a/alpine.Dockerfile b/alpine.Dockerfile index ff981a57..7089ce93 100644 --- a/alpine.Dockerfile +++ b/alpine.Dockerfile @@ -82,21 +82,6 @@ RUN apk add --no-cache --virtual .build-deps \ sqlite-dev \ upx -WORKDIR /go/src/app - -COPY --link go.mod go.sum ./ -RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get - -WORKDIR /go/src/app/caddy -COPY caddy/go.mod caddy/go.sum ./ -RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get - -WORKDIR /go/src/app -COPY --link *.* ./ -COPY --link caddy caddy -COPY --link internal internal -COPY --link testdata testdata - # Install e-dant/watcher (necessary for file watching) WORKDIR /usr/local/src/watcher RUN curl -s https://api.github.com/repos/e-dant/watcher/releases/latest | \ @@ -110,16 +95,29 @@ RUN curl -s https://api.github.com/repos/e-dant/watcher/releases/latest | \ cmake --build build && \ cmake --install build +WORKDIR /go/src/app + +COPY --link go.mod go.sum ./ +RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get + +WORKDIR /go/src/app/caddy +COPY caddy/go.mod caddy/go.sum ./ +RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get + +WORKDIR /go/src/app +COPY --link . ./ + # See https://github.com/docker-library/php/blob/master/8.3/alpine3.20/zts/Dockerfile#L53-L55 ENV CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $PHP_CFLAGS" ENV CGO_CPPFLAGS=$PHP_CPPFLAGS ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS" WORKDIR /go/src/app/caddy/frankenphp -RUN GOBIN=/usr/local/bin go install -tags 'nobadger,nomysql,nopgx' -ldflags "-w -s -extldflags '-Wl,-z,stack-size=0x80000' -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" && \ +RUN GOBIN=/usr/local/bin go install -tags 'nobadger,nomysql,nopgx' -ldflags "-w -s -extldflags '-Wl,-z,stack-size=0x80000' -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" -buildvcs=true && \ setcap cap_net_bind_service=+ep /usr/local/bin/frankenphp && \ ([ -z "${NO_COMPRESS}" ] && upx --best /usr/local/bin/frankenphp || true) && \ - frankenphp version + frankenphp version && \ + frankenphp build-info WORKDIR /go/src/app @@ -135,4 +133,5 @@ RUN apk add --no-cache libstdc++ && \ COPY --from=builder /usr/local/bin/frankenphp /usr/local/bin/frankenphp RUN setcap cap_net_bind_service=+ep /usr/local/bin/frankenphp && \ - frankenphp version + frankenphp version && \ + frankenphp build-info diff --git a/build-static.sh b/build-static.sh index 5005a536..517a8298 100755 --- a/build-static.sh +++ b/build-static.sh @@ -323,6 +323,7 @@ if type "upx" >/dev/null 2>&1 && [ -z "${DEBUG_SYMBOLS}" ] && [ -z "${NO_COMPRES fi "dist/${bin}" version +"dist/${bin}" build-info if [ -n "${RELEASE}" ]; then gh release upload "v${FRANKENPHP_VERSION}" "dist/${bin}" --repo dunglas/frankenphp --clobber diff --git a/static-builder.Dockerfile b/static-builder.Dockerfile index cc5971e0..7bc79c72 100644 --- a/static-builder.Dockerfile +++ b/static-builder.Dockerfile @@ -88,9 +88,7 @@ COPY caddy/go.mod caddy/go.sum ./ RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get WORKDIR /go/src/app -COPY --link *.* ./ -COPY --link caddy caddy -COPY --link internal internal +COPY --link . ./ RUN --mount=type=secret,id=github-token GITHUB_TOKEN=$(cat /run/secrets/github-token) ./build-static.sh && \ rm -Rf dist/static-php-cli/source/*