Skip to content
Closed
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
12 changes: 12 additions & 0 deletions build-static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ set -o pipefail
# - PHP_EXTENSIONS: comma-separated extensions (default: the list in craft.yml)
# - PHP_EXTENSION_LIBS: comma-separated extra libraries (default: the list in craft.yml)
# - XCADDY_ARGS: extra Caddy modules to pass to xcaddy (default: the list in craft.yml)
# - GO_BUILD_FLAGS: extra flags to pass to go build (default: none)
# - GO_LDFLAGS: extra Go linker flags, without double quotes (default: none)
# - GO_TAGS: extra comma-separated Go build tags (default: none)
# - FRANKENPHP_VERSION: FrankenPHP version (default: current Git commit)
# - EMBED: path to the PHP app to embed (default: none)
# - CLEAN: when set, rebuild everything from scratch (default: none)
Expand Down Expand Up @@ -213,6 +216,15 @@ while IFS= read -r line || [ -n "${line}" ]; do
*"SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES:"*)
[ -n "${XCADDY_ARGS}" ] && line=" SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES: \"${XCADDY_ARGS}\""
;;
*"SPC_CMD_VAR_FRANKENPHP_GO_BUILD_FLAGS:"*)
line=" SPC_CMD_VAR_FRANKENPHP_GO_BUILD_FLAGS: \"${GO_BUILD_FLAGS}\""
;;
*"SPC_CMD_VAR_FRANKENPHP_GO_LDFLAGS:"*)
line=" SPC_CMD_VAR_FRANKENPHP_GO_LDFLAGS: \"${GO_LDFLAGS}\""
;;
*"SPC_CMD_VAR_FRANKENPHP_GO_TAGS:"*)
line=" SPC_CMD_VAR_FRANKENPHP_GO_TAGS: \"${GO_TAGS}\""
;;
esac

printf '%s\n' "${line}" >>"${craft}"
Expand Down
3 changes: 3 additions & 0 deletions craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ download-options:

extra-env:
SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES: "--with github.com/dunglas/caddy-cbrotli --with github.com/dunglas/mercure/caddy --with github.com/dunglas/vulcain/caddy"
SPC_CMD_VAR_FRANKENPHP_GO_BUILD_FLAGS: ""
SPC_CMD_VAR_FRANKENPHP_GO_LDFLAGS: ""
SPC_CMD_VAR_FRANKENPHP_GO_TAGS: ""
EXTENSION_DIR: "/usr/lib/frankenphp/modules"
OPENSSLDIR: "/etc/ssl"

Expand Down
14 changes: 14 additions & 0 deletions docs/embed.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ You can also run the PHP CLI scripts embedded in your binary:
./my-app php-cli bin/console
```

## Extraction path

At startup, the embedded app is extracted to a private temporary directory whose name changes
with the content of the app. Some apps need a fixed path, for instance because they ship
precompiled code referencing absolute paths, such as an OPcache file cache.
Set it at build time with Go linker flags:

```console
EMBED=/path/to/your/app GO_LDFLAGS="-X github.com/dunglas/frankenphp.EmbeddedAppPath=/opt/my-app" ./build-static.sh
```

Files already present at this path are kept as is: it must only be writable by the user
running the binary.

## PHP extensions

By default, the script will build extensions required by the `composer.json` file of your project, if any.
Expand Down
14 changes: 14 additions & 0 deletions docs/static.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ In this example, we add the [Souin](https://souin.io) HTTP cache module for Cadd
> The cbrotli, Mercure, and Vulcain modules are included by default if `XCADDY_ARGS` is empty or not set.
> If you customize the value of `XCADDY_ARGS`, you must include them explicitly if you want them to be included.

### Go build flags

To pass extra flags to the Go build, use the `GO_BUILD_FLAGS`, `GO_LDFLAGS` (linker flags, without double quotes) and `GO_TAGS` (comma-separated build tags) variables.
Linker flags and tags are merged with the ones FrankenPHP needs:

```console
docker run --rm -v "$PWD/output:/output" -e OUTPUT_DIR=/output -e SPC_LOGS_DIR=/output/log \
-e GO_BUILD_FLAGS=-trimpath \
-e GO_LDFLAGS="-X github.com/dunglas/frankenphp.EmbeddedAppPath=/opt/my-app" \
dunglas/frankenphp:static-builder-musl
```

These variables are applied by static-php-cli (`SPC_CMD_VAR_FRANKENPHP_GO_*`), older versions ignore them.

See also how to [customize the FrankenPHP static build](#customizing-the-frankenphp-static-build)

### GitHub token
Expand Down
Loading