Skip to content

ci: include version in BuildInfo and Prometheus metrics #1418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .github/workflows/static.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
39 changes: 38 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ on:
permissions:
contents: read
jobs:
tests:
tests-linux:
name: Tests (Linux, PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -71,3 +72,39 @@ jobs:
if: matrix.php-versions == '8.4'
with:
version: latest
tests-mac:
name: Tests (macOS, PHP 8.4)
runs-on: macos-latest
env:
GOEXPERIMENT: cgocheck2
HOMEBREW_NO_AUTO_UPDATE: 1
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.24"
cache-dependency-path: |
go.sum
caddy/go.sum
- uses: shivammathur/setup-php@v2
with:
php-version: 8.4
ini-file: development
coverage: none
tools: none
env:
phpts: ts
debug: true
- name: Set Set CGO flags
run: |
{
echo "CGO_CFLAGS=-I/opt/homebrew/include/ $(php-config --includes)"
echo "CGO_LDFLAGS=-L/opt/homebrew/lib/ $(php-config --ldflags) $(php-config --libs)"
} >> "${GITHUB_ENV}"
- name: Build
run: go build -tags nowatcher
- name: Run library tests
run: go test -tags nowatcher -race -v ./...
- name: Run Caddy module tests
working-directory: caddy/
run: go test -tags nowatcher,nobadger,nomysql,nopgx -race -v ./...
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
/internal/testserver/testserver
/internal/testcli/testcli
/dist
.DS_Store
.idea/
.vscode/
__debug_bin
frankenphp.test
caddy/frankenphp/Build
*.log
9 changes: 3 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,13 @@ docker buildx bake -f docker-bake.hcl --pull --no-cache --push
3. Enable `tmate` to connect to the container

```patch
-
name: Set CGO flags
- name: Set CGO flags
run: echo "CGO_CFLAGS=$(php-config --includes)" >> "$GITHUB_ENV"
+ -
+ run: |
+ - run: |
+ sudo apt install gdb
+ mkdir -p /home/runner/.config/gdb/
+ printf "set auto-load safe-path /\nhandle SIG34 nostop noprint pass" > /home/runner/.config/gdb/gdbinit
+ -
+ uses: mxschmitt/action-tmate@v3
+ - uses: mxschmitt/action-tmate@v3
```

4. Connect to the container
Expand Down
38 changes: 19 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 | \
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
35 changes: 17 additions & 18 deletions alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 | \
Expand All @@ -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

Expand All @@ -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
1 change: 1 addition & 0 deletions build-static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions caddy/caddy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func TestPHPIniConfiguration(t *testing.T) {
frankenphp {
num_threads 2
worker ../testdata/ini.php 1
php_ini max_execution_time 100
php_ini upload_max_filesize 100M
php_ini memory_limit 10000000
}
}
Expand All @@ -673,7 +673,7 @@ func TestPHPIniConfiguration(t *testing.T) {
}
`, "caddyfile")

testSingleIniConfiguration(tester, "max_execution_time", "100")
testSingleIniConfiguration(tester, "upload_max_filesize", "100M")
testSingleIniConfiguration(tester, "memory_limit", "10000000")
}

Expand All @@ -688,7 +688,7 @@ func TestPHPIniBlockConfiguration(t *testing.T) {
frankenphp {
num_threads 1
php_ini {
max_execution_time 15
upload_max_filesize 100M
memory_limit 20000000
}
}
Expand All @@ -702,7 +702,7 @@ func TestPHPIniBlockConfiguration(t *testing.T) {
}
`, "caddyfile")

testSingleIniConfiguration(tester, "max_execution_time", "15")
testSingleIniConfiguration(tester, "upload_max_filesize", "100M")
testSingleIniConfiguration(tester, "memory_limit", "20000000")
}

Expand Down
14 changes: 7 additions & 7 deletions caddy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/dunglas/frankenphp v1.4.4
github.com/dunglas/mercure/caddy v0.18.4
github.com/dunglas/vulcain/caddy v1.1.1
github.com/prometheus/client_golang v1.21.0
github.com/prometheus/client_golang v1.21.1
github.com/spf13/cobra v1.9.1
github.com/stretchr/testify v1.10.0
go.uber.org/zap v1.27.0
Expand Down Expand Up @@ -185,16 +185,16 @@ require (
go.uber.org/mock v0.5.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap/exp v0.3.0 // indirect
golang.org/x/crypto v0.33.0 // indirect
golang.org/x/crypto v0.36.0 // indirect
golang.org/x/crypto/x509roots/fallback v0.0.0-20250214233241-911360c8a4f4 // indirect
golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa // indirect
golang.org/x/mod v0.23.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/net v0.37.0 // indirect
golang.org/x/oauth2 v0.26.0 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/term v0.29.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/sync v0.12.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/term v0.30.0 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/time v0.10.0 // indirect
golang.org/x/tools v0.30.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250218202821-56aae31c358a // indirect
Expand Down
Loading