diff --git a/.github/workflows/build-linux-static.yaml b/.github/workflows/build-linux-static.yaml new file mode 100644 index 0000000000..26991911a0 --- /dev/null +++ b/.github/workflows/build-linux-static.yaml @@ -0,0 +1,39 @@ +--- +name: Build Linux static binary + +on: + push: + branches: + - main + paths: + - "build-linux-static.sh" + - "docker-bake.hcl" + - "static-builder-gnu.Dockerfile" + - ".github/workflows/build-linux-static.yaml" + workflow_dispatch: + +permissions: + contents: write + +jobs: + build: + name: Build frankenphp linux/amd64 (glibc) + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v3 + + - name: Build static binary + run: bash build-linux-static.sh + + - name: Upload binary artifact + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 + with: + name: frankenphp-linux-amd64 + path: frankenphp + if-no-files-found: error diff --git a/.gitignore b/.gitignore index 0a849e1f21..7b7ee90e5f 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ __debug_bin frankenphp.test *.log compile_flags.txt +/frankenphp diff --git a/build-linux-static.sh b/build-linux-static.sh new file mode 100755 index 0000000000..9579fe036d --- /dev/null +++ b/build-linux-static.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +set -o errexit +set -x + +# The following environment variables can be passed to docker build and to the build-static.sh script to customize the static build: + # + # FRANKENPHP_VERSION: the version of FrankenPHP to use + # PHP_VERSION: the version of PHP to use + # PHP_EXTENSIONS: the PHP extensions to build (list of supported extensions) + # PHP_EXTENSION_LIBS: extra libraries to build that add features to the extensions + # XCADDY_ARGS: arguments to pass to xcaddy, for instance to add extra Caddy modules + # EMBED: path of the PHP application to embed in the binary + # CLEAN: when set, libphp and all its dependencies are built from scratch (no cache) + # COMPRESS: when set to 1, pack the resulting binary with UPX (Linux only; ignored when DEBUG_SYMBOLS is set) + # DEBUG_SYMBOLS: when set, debug-symbols will not be stripped and will be added to the binary + # MIMALLOC: (experimental, Linux-only) replace musl's mallocng by mimalloc for improved performance. We only recommend using this for musl targeting builds, for glibc prefer disabling this option and using LD_PRELOAD when you run your binary instead. + # RELEASE: (maintainers only) when set, the resulting binary will be uploaded on GitHub + +# PHP extensions from composer.json +PHP_EXTENSIONS="bcmath,ctype,curl,dom,fileinfo,filter,gd,hash,intl,json,mbstring,openssl,pcre,pdo,redis,session,tokenizer,xml" +PHP_VERSION=8.4 + +# Create a temporary override bake file to restrict to linux/amd64 only +OVERRIDE_FILE=$(mktemp /tmp/bake-override-XXXXXX.hcl) +cat > "${OVERRIDE_FILE}" <<'EOF' +target "static-builder-gnu" { + platforms = ["linux/amd64"] +} +EOF + +# Build the static Linux binary using the gnu (glibc) static builder +docker buildx bake --load \ + -f docker-bake.hcl \ + -f "${OVERRIDE_FILE}" \ + --set "*.args.PHP_EXTENSIONS=${PHP_EXTENSIONS}" \ + --set "*.args.PHP_VERSION=${PHP_VERSION}" \ + static-builder-gnu + +rm -f "${OVERRIDE_FILE}" + +# Copy the binary out of the container +docker cp $(docker create --name static-builder-gnu dunglas/frankenphp:static-builder-gnu):/go/src/app/dist/frankenphp-linux-x86_64 frankenphp +docker rm static-builder-gnu