fix(ci): Docker builds

This commit is contained in:
Kévin Dunglas
2025-07-16 15:36:16 +02:00
parent 0c25b2488c
commit 1da2ba1f28
11 changed files with 42 additions and 28 deletions

View File

@@ -8,13 +8,14 @@ on:
branches:
- main
paths:
- "*.c"
- "*.h"
- "*.stub.php"
- "*Dockerfile"
- "docker-bake.hcl"
- "*.sh"
- ".github/workflows/docker.yaml"
- "**cgo.go"
- "**Dockerfile"
- "**.c"
- "**.h"
- "**.sh"
- "**.stub.php"
push:
branches:
- main
@@ -205,7 +206,7 @@ jobs:
run: |
docker run --platform=${{ matrix.platform }} --rm \
"$(jq -r '."builder-${{ matrix.variant }}"."containerimage.config.digest"' <<< "${METADATA}")" \
sh -c 'go test -tags ${{ matrix.race }} -v $(go list ./... | grep -v github.com/dunglas/frankenphp/internal/testext | grep -v github.com/dunglas/frankenphp/internal/extgen) && cd caddy && go test -tags nobadger,nomysql,nopgx ${{ matrix.race }} -v ./...'
sh -c './go.sh test -tags ${{ matrix.race }} -v $(./go.sh list ./... | grep -v github.com/dunglas/frankenphp/internal/testext | grep -v github.com/dunglas/frankenphp/internal/extgen) && cd caddy && ../go.sh test ${{ matrix.race }} -v ./...'
env:
METADATA: ${{ steps.build.outputs.metadata }}
# Adapted from https://docs.docker.com/build/ci/github-actions/multi-platform/

View File

@@ -8,13 +8,14 @@ on:
branches:
- main
paths:
- "*.c"
- "*.h"
- "*.stub.php"
- "*Dockerfile"
- "docker-bake.hcl"
- "*.sh"
- ".github/workflows/static.yaml"
- ".github/workflows/docker.yaml"
- "**cgo.go"
- "**Dockerfile"
- "**.c"
- "**.h"
- "**.sh"
- "**.stub.php"
push:
branches:
- main

View File

@@ -115,10 +115,9 @@ ENV CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $PHP_CFLAGS"
ENV CGO_CPPFLAGS=$PHP_CPPFLAGS
ENV CGO_LDFLAGS="-L/usr/local/lib -lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS"
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'" -buildvcs=true && \
RUN GOBIN=/usr/local/bin \
../../go.sh install -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/frankenphp/Caddyfile && \
frankenphp version && \

View File

@@ -122,7 +122,8 @@ 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'" -buildvcs=true && \
RUN GOBIN=/usr/local/bin \
../../go.sh install -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 && \

View File

@@ -90,9 +90,6 @@ fi
if [ "${os}" = "linux" ] && { [[ "${arch}" =~ "aarch" ]] || [[ "${arch}" =~ "arm" ]]; }; then
fpic="-fPIC"
fpie="-fPIE"
# FIXME: temporary workaround because pre-built poackages aren't compiled wiht -fPIC yet
SPC_OPT_DOWNLOAD_ARGS="--ignore-cache-sources=php-src --retry 5"
else
fpic="-fpic"
fpie="-fpie"

9
cgo.go Normal file
View File

@@ -0,0 +1,9 @@
package frankenphp
// #cgo darwin pkg-config: libxml-2.0
// #cgo CFLAGS: -Wall -Werror
// #cgo linux CFLAGS: -D_GNU_SOURCE
// #cgo LDFLAGS: -lphp -lm -lutil
// #cgo linux LDFLAGS: -ldl -lresolv
// #cgo darwin LDFLAGS: -Wl,-rpath,/usr/local/lib -liconv -ldl
import "C"

View File

@@ -80,10 +80,10 @@ RUN git clone https://github.com/e-dant/watcher . && \
ldconfig
WORKDIR /go/src/app
COPY . .
COPY --link . ./
WORKDIR /go/src/app/caddy/frankenphp
RUN go build -buildvcs=false -tags 'nobadger,nomysql,nopgx'
RUN ../../go.sh build -buildvcs=false
WORKDIR /go/src/app
CMD [ "zsh" ]

View File

@@ -14,12 +14,6 @@ package frankenphp
// #cgo nocallback frankenphp_update_server_context
// #cgo noescape frankenphp_update_server_context
// #cgo darwin pkg-config: libxml-2.0
// #cgo CFLAGS: -Wall -Werror
// #cgo linux CFLAGS: -D_GNU_SOURCE
// #cgo LDFLAGS: -lphp -lm -lutil
// #cgo linux LDFLAGS: -ldl -lresolv
// #cgo darwin LDFLAGS: -Wl,-rpath,/usr/local/lib -liconv -ldl
// #include <stdlib.h>
// #include <stdint.h>
// #include <php_variables.h>

7
go.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/sh
# Runs the go command with the proper Go and cgo flags.
GOFLAGS="$GOFLAGS -tags=nobadger,nomysql,nopgx" \
CGO_CFLAGS="$CGO_CFLAGS $(php-config --includes)" \
CGO_LDFLAGS="$CGO_LDFLAGS $(php-config --ldflags) $(php-config --libs)" \
go "$@"

6
internal/watcher/cgo.go Normal file
View File

@@ -0,0 +1,6 @@
//go:build !nowatcher
package watcher
// #cgo LDFLAGS: -lwatcher-c -lstdc++
import "C"

View File

@@ -2,7 +2,6 @@
package watcher
// #cgo LDFLAGS: -lwatcher-c -lstdc++
// #include <stdint.h>
// #include <stdlib.h>
// #include "watcher.h"