Skip to content

Commit 1a03bc2

Browse files
authored
build: make UPX packing opt-in via COMPRESS env var (#2429)
## Summary UPX is now disabled by default for the static build. To pack the binary with UPX (Linux only), set `COMPRESS=1` at build time. The previous `NO_COMPRESS` flag is removed; CI invocations and the `static-builder-{musl,gnu}` Dockerfiles were updated accordingly. Docs (all locales) were refreshed. ## Why drop UPX from the default? - **AV false positives.** UPX-packed binaries get flagged routinely on Windows and macOS, generating recurring support friction for end users. - **Permanent memory cost.** UPX decompresses the whole binary into anonymous memory at launch, so the OS can no longer share read-only text pages across processes or demand-page from disk. For a long-running server with workers, the savings on disk are paid back continuously in RAM. - **Startup latency.** ~100–300 ms added per launch — noticeable for container cold starts and test runs. - **Tooling friction.** Complicates debugging, core dumps, SBOM/attestation, and trips up some security scanners. - **Modest upside.** ~60% size reduction is nice, but FrankenPHP is mostly distributed via Docker layers (cached) or downloaded once per host. If artifact size is the concern, `xz`-compressing the release asset gives similar savings without any of the runtime downsides. Users who still want a packed binary can opt in explicitly with `COMPRESS=1`.
1 parent cb9e3da commit 1a03bc2

21 files changed

Lines changed: 21 additions & 24 deletions

.github/workflows/docker.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ jobs:
143143
runner-${{ matrix.variant }}
144144
# Remove tags to prevent "can't push tagged ref [...] by digest" error
145145
set: |
146-
${{ (github.event_name == 'pull_request') && '*.args.NO_COMPRESS=1' || '' }}
147146
*.tags=
148147
*.platform=${{ matrix.platform }}
149148
${{ fromJson(needs.prepare.outputs.push) && '' || format('builder-{0}.cache-from=type=gha,scope=builder-{0}-{1}-{2}', matrix.variant, needs.prepare.outputs.ref || github.ref, matrix.platform) }}

.github/workflows/static.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ jobs:
148148
set: |
149149
${{ matrix.debug && 'static-builder-musl.args.DEBUG_SYMBOLS=1' || '' }}
150150
${{ matrix.mimalloc && 'static-builder-musl.args.MIMALLOC=1' || '' }}
151-
${{ (github.event_name == 'pull_request' || matrix.platform == 'linux/arm64') && 'static-builder-musl.args.NO_COMPRESS=1' || '' }}
152151
*.tags=
153152
*.platform=${{ matrix.platform }}
154153
${{ fromJson(needs.prepare.outputs.push) && '' || format('*.cache-from=type=gha,scope={0}-static-builder-musl{1}{2}', needs.prepare.outputs.ref || github.ref, matrix.debug && '-debug' || '', matrix.mimalloc && '-mimalloc' || '') }}
@@ -302,7 +301,6 @@ jobs:
302301
source: .
303302
targets: static-builder-gnu
304303
set: |
305-
${{ (github.event_name == 'pull_request' || matrix.platform == 'linux/arm64') && 'static-builder-gnu.args.NO_COMPRESS=1' || '' }}
306304
*.tags=
307305
*.platform=${{ matrix.platform }}
308306
${{ fromJson(needs.prepare.outputs.push) && '' || format('*.cache-from=type=gha,scope={0}-static-builder-gnu', needs.prepare.outputs.ref || github.ref) }}
@@ -466,7 +464,6 @@ jobs:
466464
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
467465
FRANKENPHP_VERSION: ${{ steps.version.outputs.version }}
468466
RELEASE: ${{ (needs.prepare.outputs.ref || github.ref_type == 'tag') && '1' || '' }}
469-
NO_COMPRESS: ${{ github.event_name == 'pull_request' && '1' || '' }}
470467
- name: Upload logs
471468
if: ${{ failure() }}
472469
uses: actions/upload-artifact@v7

alpine.Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ LABEL org.opencontainers.image.vendor="Kévin Dunglas"
5454
FROM common AS builder
5555

5656
ARG FRANKENPHP_VERSION='dev'
57-
ARG NO_COMPRESS=''
57+
ARG COMPRESS=''
5858
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
5959

6060
COPY --link --from=golang-base /usr/local/go /usr/local/go
@@ -128,7 +128,7 @@ WORKDIR /go/src/app/caddy/frankenphp
128128
RUN GOBIN=/usr/local/bin \
129129
../../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' -X 'github.com/caddyserver/caddy/v2.CustomBinaryName=frankenphp' -X 'github.com/caddyserver/caddy/v2/modules/caddyhttp.ServerHeader=FrankenPHP Caddy'" -buildvcs=true && \
130130
setcap cap_net_bind_service=+ep /usr/local/bin/frankenphp && \
131-
([ -z "${NO_COMPRESS}" ] && upx --best /usr/local/bin/frankenphp || true) && \
131+
([ -n "${COMPRESS}" ] && upx --best /usr/local/bin/frankenphp || true) && \
132132
frankenphp version && \
133133
frankenphp build-info
134134

build-static.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ os="$(uname -s | tr '[:upper:]' '[:lower:]')"
2121
# - FRANKENPHP_VERSION: FrankenPHP version (default: current Git commit)
2222
# - EMBED: Path to the PHP app to embed (default: none)
2323
# - DEBUG_SYMBOLS: Enable debug symbols if set to 1 (default: none)
24+
# - COMPRESS: Pack the resulting Linux binary with UPX if set to 1; ignored when DEBUG_SYMBOLS is set (default: none)
2425
# - MIMALLOC: Use mimalloc as the allocator if set to 1 (default: none)
2526
# - XCADDY_ARGS: Additional arguments to pass to xcaddy
2627
# - RELEASE: [maintainer only] Create a GitHub release if set to 1 (default: none)
@@ -189,7 +190,7 @@ if [ -n "${EMBED}" ] && [ -d "${EMBED}" ]; then
189190
fi
190191

191192
SPC_OPT_INSTALL_ARGS="go-xcaddy"
192-
if [ -z "${DEBUG_SYMBOLS}" ] && [ -z "${NO_COMPRESS}" ] && [ "${os}" = "linux" ]; then
193+
if [ -n "${COMPRESS}" ] && [ -z "${DEBUG_SYMBOLS}" ] && [ "${os}" = "linux" ]; then
193194
SPC_OPT_BUILD_ARGS="${SPC_OPT_BUILD_ARGS} --with-upx-pack"
194195
SPC_OPT_INSTALL_ARGS="${SPC_OPT_INSTALL_ARGS} upx"
195196
fi

docs/cn/embed.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ EMBED=/path/to/your/app ./build-static.sh
138138

139139
## 分发二进制文件
140140

141-
在Linux上,创建的二进制文件使用[UPX](https://upx.github.io)进行压缩
141+
在 Linux 上,可以通过在构建时设置环境变量 `COMPRESS=1` 来使用 [UPX](https://upx.github.io) 压缩生成的二进制文件
142142

143143
在Mac上,您可以在发送文件之前压缩它以减小文件大小。
144144
我们推荐使用 `xz`

docs/cn/static.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ cd frankenphp
124124
- `XCADDY_ARGS`:传递给 [xcaddy](https://github.com/caddyserver/xcaddy) 的参数,例如用于添加额外的 Caddy 模块
125125
- `EMBED`: 要嵌入二进制文件的 PHP 应用程序的路径
126126
- `CLEAN`: 设置后,libphp 及其所有依赖项都是重新构建的(不使用缓存)
127-
- `NO_COMPRESS`: 不要使用UPX压缩生成的二进制文件
127+
- `COMPRESS`: 设置为 `1` 时使用 UPX 压缩生成的二进制文件(仅限 Linux;设置了 `DEBUG_SYMBOLS` 时忽略此选项)
128128
- `DEBUG_SYMBOLS`: 设置后,调试符号将被保留在二进制文件内
129129
- `MIMALLOC`: (实验性,仅限Linux) 用[mimalloc](https://github.com/microsoft/mimalloc)替换musl的mallocng,以提高性能。我们仅建议在musl目标构建中使用此选项,对于glibc,建议禁用此选项,并在运行二进制文件时使用[`LD_PRELOAD`](https://microsoft.github.io/mimalloc/overrides.html)
130130
- `RELEASE`: (仅限维护者)设置后,生成的二进制文件将上传到 GitHub 上

docs/embed.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ To customize the extensions, use the `PHP_EXTENSIONS` environment variable.
144144

145145
## Distributing the binary
146146

147-
On Linux, the created binary is compressed using [UPX](https://upx.github.io).
147+
On Linux, the created binary can be compressed using [UPX](https://upx.github.io) by setting the `COMPRESS=1` environment variable at build time.
148148

149149
On macOS, to reduce the size of the file before sending it, you can compress it.
150150
We recommend `xz`.

docs/es/embed.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Para personalizar las extensiones, use la variable de entorno `PHP_EXTENSIONS`.
138138

139139
## Distribuir el binario
140140

141-
En Linux, el binario creado se comprime usando [UPX](https://upx.github.io).
141+
En Linux, el binario creado puede comprimirse usando [UPX](https://upx.github.io) estableciendo la variable de entorno `COMPRESS=1` en el momento de la compilación.
142142

143143
En Mac, para reducir el tamaño del archivo antes de enviarlo, puede comprimirlo.
144144
Recomendamos `xz`.

docs/es/static.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Las siguientes variables de entorno pueden pasarse a `docker build` y al script
123123
- `XCADDY_ARGS`: argumentos a pasar a [xcaddy](https://github.com/caddyserver/xcaddy), por ejemplo para agregar módulos adicionales de Caddy
124124
- `EMBED`: ruta de la aplicación PHP a incrustar en el binario
125125
- `CLEAN`: cuando está establecido, libphp y todas sus dependencias se compilan desde cero (sin caché)
126-
- `NO_COMPRESS`: no comprimir el binario resultante usando UPX
126+
- `COMPRESS`: cuando se establece en `1`, comprime el binario resultante usando UPX (solo Linux; se ignora cuando `DEBUG_SYMBOLS` está establecido)
127127
- `DEBUG_SYMBOLS`: cuando está establecido, los símbolos de depuración no se eliminarán y se añadirán al binario
128128
- `MIMALLOC`: (experimental, solo Linux) reemplaza mallocng de musl por [mimalloc](https://github.com/microsoft/mimalloc) para mejorar el rendimiento. Solo recomendamos usar esto para compilaciones orientadas a musl; para glibc, preferimos deshabilitar esta opción y usar [`LD_PRELOAD`](https://microsoft.github.io/mimalloc/overrides.html) cuando ejecutes tu binario.
129129
- `RELEASE`: (solo para mantenedores) cuando está establecido, el binario resultante se subirá a GitHub

docs/fr/embed.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ PHP_EXTENSIONS=ctype,iconv,pdo_sqlite \
145145

146146
## Distribuer le binaire
147147

148-
Sous Linux, le binaire est compressé par défaut à l'aide de [UPX](https://upx.github.io).
148+
Sous Linux, le binaire peut être compressé à l'aide de [UPX](https://upx.github.io) en définissant la variable d'environnement `COMPRESS=1` au moment de la compilation.
149149

150150
Sous Mac, pour réduire la taille du fichier avant de l'envoyer, vous pouvez le compresser.
151151
Nous recommandons `xz`.

0 commit comments

Comments
 (0)