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#

ImageContents
ghcr.io/velyrlabs/velyr-php-builderThe builder: build image, the velyr/laravel buildpack, CNB lifecycle 0.21.30.
ghcr.io/velyrlabs/velyr-php-buildBuild image: PHP CLI, Composer, the extensions below and the velyr-pack CLI.
ghcr.io/velyrlabs/velyr-php-runDefault run image: FrankenPHP, the extensions below, bash and curl.
ghcr.io/velyrlabs/velyr-php-run-mediaThe 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:

TagPHP
v0.1.0-alpha.4-php8.38.3
v0.1.0-alpha.4-php8.48.4
v0.1.0-alpha.4-php8.5, v0.1.0-alpha.48.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#

console
$ pack build ghcr.io/you/shop:1 \
    --builder ghcr.io/velyrlabs/velyr-php-builder:v0.1.0-alpha.4-php8.5 \
    --path . \
    --publish

For 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:

  1. runs composer install --no-dev --no-interaction --no-scripts --optimize-autoloader --prefer-dist, with the Composer cache in a cached layer;
  2. copies your Caddyfile over Octane's FrankenPHP stub, from the path in BP_OCTANE_CADDYFILE, or from docker/frankenphp/Caddyfile when that file exists;
  3. creates storage/framework/{cache/data,sessions,views}, storage/logs and bootstrap/cache, and runs the post-autoload-dump Composer scripts (package discovery);
  4. runs php artisan route:cache with a throwaway environment (APP_ENV=production, a dummy APP_KEY, array cache and session, sync queue), then deletes any config cache, so configuration is always read from the runtime environment;
  5. makes storage and bootstrap/cache writable by the app user;
  6. installs the runtime helper that loads Swarm configs and secrets before each process;
  7. 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:

VariableMeaning
BP_OCTANE_CADDYFILEPath, 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:

yaml
worker-mail:
  entrypoint: ["/cnb/process/worker"]
  command: ["--queue=mail"]          # runs: php artisan queue:work --queue=mail

Without velyr.toml, the image gets:

  • a default web process: php artisan octane:start --server=frankenphp --host=0.0.0.0 --port=8000 --workers=auto;
  • one process per Procfile entry (name: command), run through /bin/sh -c. A web entry in the Procfile is ignored, because the default web already 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) and entrypoint.d scripts never run. Do that work in a process command instead; see Recipes.
  • SSL_MODE is set to off. 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#

console
$ 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, pushed

build.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.