velyr-php Builder Experimental
The velyr-php images and Cloud Native Buildpacks builder: tags, PHP versions, extensions and what the buildpack does.
A Cloud Native Buildpacks builder for Laravel apps served by
Octane on FrankenPHP. It replaces the Dockerfile: pack build turns the app
source into a runnable image whose processes come from your velyr.toml.
Images#
| Image | Contents |
|---|---|
ghcr.io/velyrlabs/velyr-php-builder | The builder: build image, the velyr/laravel buildpack, CNB lifecycle 0.21.30. |
ghcr.io/velyrlabs/velyr-php-build | Build image: PHP CLI, Composer, the extensions below and the velyr-pack CLI. |
ghcr.io/velyrlabs/velyr-php-run | Default run image: FrankenPHP, the extensions below, bash and curl. |
ghcr.io/velyrlabs/velyr-php-run-media | The run image plus ffmpeg. |
All images are based on serversideup/php on Alpine 3.24, run
as www-data (uid and gid 33) and are published for linux/amd64 and linux/arm64. The app lives in /workspace.
Tags and PHP versions#
Every image is published for PHP 8.3, 8.4 and 8.5, the versions serversideup/php ships with FrankenPHP. The tag is the velyr-pack release plus the PHP minor; the plain release tag is the newest PHP:
| Tag | PHP |
|---|---|
v0.1.0-alpha.4-php8.3 | 8.3 |
v0.1.0-alpha.4-php8.4 | 8.4 |
v0.1.0-alpha.4-php8.5, v0.1.0-alpha.4 | 8.5 |
There is no latest tag. Pin a release tag with an explicit PHP minor, so upgrading PHP or velyr-pack is a change
you make on purpose.
You pick the PHP version with the builder, and the builder's run images are the same version, so build and runtime
always match. If composer.json requires a PHP the image does not have, composer install fails the build.
The base images are pinned by digest in php/stack/php-versions.txt, always on
the newest patch of each PHP minor of the latest serversideup/php release. A weekly workflow opens a pull request
when a newer patch is out, and the next velyr-pack release publishes it. To pick up a PHP security patch, move to
the newest velyr-pack release.
Extensions#
In both build and run images: pcntl, pdo_pgsql, pgsql, redis, zip, intl, bcmath, sodium, gd,
rdkafka, opentelemetry, protobuf, opcache, plus what serversideup/php includes by default.
There is no way to add an extension at build time yet. If you need one, open an issue or build your own stack images (see Build the images yourself).
Build an app#
$ pack build ghcr.io/you/shop:1 \
--builder ghcr.io/velyrlabs/velyr-php-builder:v0.1.0-alpha.4-php8.5 \
--path . \
--publishFor the media run image, add --run-image ghcr.io/velyrlabs/velyr-php-run-media:v0.1.0-alpha.4-php8.5, with the
same release and PHP version as the builder.
A project.toml at the root keeps vendor, node_modules, tests and local
files out of the build, like .dockerignore does for docker build. In CI, add
--cache-image <registry>/shop:cnb-cache so the Composer cache survives between runners; see CI/CD.
Front-end assets#
The builder has no Node.js and does not run npm or Vite. Build the assets before pack build (in CI, in a
previous step) so public/build is part of the source the builder sees, and do not exclude it in
project.toml.
What the buildpack does#
velyr/laravel detects an app whose composer.json lists laravel/framework under require. The build then:
- runs
composer install --no-dev --no-interaction --no-scripts --optimize-autoloader --prefer-dist, with the Composer cache in a cached layer; - copies your Caddyfile over Octane's FrankenPHP stub, from the path in
BP_OCTANE_CADDYFILE, or fromdocker/frankenphp/Caddyfilewhen that file exists; - creates
storage/framework/{cache/data,sessions,views},storage/logsandbootstrap/cache, and runs thepost-autoload-dumpComposer scripts (package discovery); - runs
php artisan route:cachewith a throwaway environment (APP_ENV=production, a dummyAPP_KEY, array cache and session, sync queue), then deletes any config cache, so configuration is always read from the runtime environment; - makes
storageandbootstrap/cachewritable by the app user; - installs the runtime helper that loads Swarm configs and secrets before each process;
- declares the processes (below).
Because routes are cached at build time, route files must not depend on environment variables or the database. The config is not cached: see Recipes to cache it when the container starts.
Build-time variables are passed with pack build --env:
| Variable | Meaning |
|---|---|
BP_OCTANE_CADDYFILE | Path, relative to the app, of the Caddyfile to use instead of Octane's stub. |
Processes#
With a velyr.toml, every [processes.<name>] becomes an image process, run as
/cnb/process/<name>. The process with health, when it is the only one, is the image default. Arguments
given to the container are appended to the process command, so one process serves several services:
worker-mail:
entrypoint: ["/cnb/process/worker"]
command: ["--queue=mail"] # runs: php artisan queue:work --queue=mailWithout velyr.toml, the image gets:
- a default
webprocess:php artisan octane:start --server=frankenphp --host=0.0.0.0 --port=8000 --workers=auto; - one process per
Procfileentry (name: command), run through/bin/sh -c. Awebentry in the Procfile is ignored, because the defaultwebalready exists, and a duplicate name fails the build.
Runtime#
Before a process starts, the image loads KEY=VALUE files from /config/common.env and
/run/secrets/app_secrets, so shared settings and secrets can live in Swarm configs and secrets instead of the
stack file. Runtime configuration covers the format and the precedence.
Two things differ from a serversideup/php container:
- The serversideup entrypoint does not run. The CNB launcher starts your process directly, so the
AUTORUN_*automations (config cache, migrations, storage link) andentrypoint.dscripts never run. Do that work in a process command instead; see Recipes. SSL_MODEis set tooff. TLS is expected to end at the reverse proxy in front of Swarm, and Octane serves plain HTTP on the port of its command.
PHP settings that serversideup reads from the environment in its php.ini (PHP_MEMORY_LIMIT,
PHP_OPCACHE_ENABLE, PHP_MAX_EXECUTION_TIME and the others it documents) still work, because PHP itself
resolves them.
Build the images yourself#
$ php/stack/build.sh # velyr-poc/* for the host arch, every PHP version
$ PHP_VERSIONS=8.5 php/stack/build.sh # only PHP 8.5
$ VELYR_TAG=v0.1.0 php/stack/build.sh ghcr.io/you --push # multi-arch images and builders, pushedbuild.sh cross-compiles the velyr-pack CLI for both architectures, builds the build image and the two run
images for each PHP version, and, with --push, creates the builders with builder.sh. Pushing logs pack in
to the registry with REGISTRY_USER and REGISTRY_TOKEN, or with your gh CLI login when they are unset.
To add an extension or a system package, edit extensions.txt or
packages/ and build under your own prefix.
The builder repository also holds base-<version>-php<minor>, a copy of the build image that the builder is
created on top of. It is not meant to be used directly.