Skip to content
Draft
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
9 changes: 9 additions & 0 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
- '8.5'
- '8.5-frankenphp'
- '8.5-www'
- '8.6'
- '8.6-frankenphp'
- '8.6-www'
runs-on: blacksmith-4vcpu-ubuntu-2404
steps:
- name: Checkout
Expand Down Expand Up @@ -63,6 +66,9 @@ jobs:
- '8.5'
- '8.5-frankenphp'
- '8.5-www'
- '8.6'
- '8.6-frankenphp'
- '8.6-www'
runs-on: blacksmith-4vcpu-ubuntu-2404-arm
steps:
- name: Checkout
Expand Down Expand Up @@ -108,6 +114,9 @@ jobs:
- '8.5'
- '8.5-frankenphp'
- '8.5-www'
- '8.6'
- '8.6-frankenphp'
- '8.6-www'
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Checkout
Expand Down
163 changes: 163 additions & 0 deletions 8.6-frankenphp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
ARG PHP_VERSION=8.6.0RC7
ARG FRANKENPHP_VERSION=1.13.5
ARG GO_VERSION=1.27
ARG WATCHER_VERSION=0.14.5

# FrankenPHP does not publish PHP 8.6 images yet, so it is compiled here following
# its upstream Dockerfile. Since PHP 8.6 every official php image is built as ZTS
# with the embed SAPI (the separate "-zts" variant was dropped), so the "cli"
# variant is the FrankenPHP base.
FROM golang:${GO_VERSION}-trixie AS golang-base

# -----------------------------------------------------
# FrankenPHP Build
# -----------------------------------------------------
FROM php:${PHP_VERSION}-cli-trixie AS builder

ARG FRANKENPHP_VERSION
ARG WATCHER_VERSION
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

COPY --from=golang-base /usr/local/go /usr/local/go

ENV PATH=/usr/local/go/bin:$PATH
ENV GOTOOLCHAIN=local

RUN apt-get update && apt-get -y --no-install-recommends install \
cmake \
git \
libargon2-dev \
libbrotli-dev \
libcap2-bin \
libcurl4-openssl-dev \
libonig-dev \
libreadline-dev \
libsodium-dev \
libsqlite3-dev \
libssl-dev \
libxml2-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*

# e-dant/watcher (FrankenPHP file watching)
WORKDIR /usr/local/src/watcher
RUN curl -fsSL "https://github.com/e-dant/watcher/archive/refs/tags/release/${WATCHER_VERSION}.tar.gz" | tar xz --strip-components 1 \
&& cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
&& cmake --build build \
&& cmake --install build \
&& ldconfig

WORKDIR /go/src/app
RUN git clone --depth 1 --branch "v${FRANKENPHP_VERSION}" https://github.com/php/frankenphp.git . \
&& go mod download \
&& cd caddy && go mod download

# See https://github.com/docker-library/php/blob/master/8.6-rc/trixie/cli/Dockerfile for PHP values
ENV CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $PHP_CFLAGS"
ENV CGO_CPPFLAGS=$PHP_CPPFLAGS
ENV CGO_LDFLAGS="-L/usr/local/lib -lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS"

WORKDIR /go/src/app/caddy/frankenphp
RUN GOBIN=/usr/local/bin \
../../go.sh install -ldflags "-w -s -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP v$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=false \
&& setcap cap_net_bind_service=+ep /usr/local/bin/frankenphp \
&& frankenphp version \
&& frankenphp build-info

# -----------------------------------------------------
# FrankenPHP
#------------------------------------------------------
FROM php:${PHP_VERSION}-cli-trixie

ARG PORT=9001

ENV PORT=$PORT SERVER_NAME=":80, :$PORT"
ENV COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_NO_INTERACTION=1 COMPOSER_CACHE_DIR="/tmp"
ENV PHP_INI_SCAN_DIR=":$PHP_INI_DIR/app.conf.d"
# See https://caddyserver.com/docs/conventions#file-locations for details
ENV XDG_CONFIG_HOME=/config XDG_DATA_HOME=/data
ENV GODEBUG=cgocheck=0

# PHP 8.6 removed internal C APIs (XtOffsetOf, zval_dtor, INI_STR/INT/FLT, ...). Until PECL releases
# support 8.6: apcu (5.1.29 release commit, not on PECL), igbinary and imagick are built from pinned
# upstream commits, amqp from the sctr/php-amqp fork (php-8.6-support branch, pending upstream),
# redis by scripts/install-phpredis.sh, and protobuf and grpc are left out because no upstream code
# compiles on 8.6 yet.
ENV EXTENSIONS="sctr/php-amqp@7a4318b41915d8957ab207de43783d94db25aa25 krakjoe/apcu@66300e28647c16fef7672a5add532f4262b23a75 ast bcmath exif ffi gd gettext gmp igbinary/igbinary@2b1f5d62e3037b07c2a46499ac32091cdb41fb40 Imagick/imagick@55ed2e9fda264395636a2e27e51f31673f5566ab intl maxminddb mongodb opcache pcntl pdo_mysql pdo_pgsql sockets sysvmsg sysvsem sysvshm uuid xsl zip opentelemetry zstd symfony/php-ext-deepclone@v0.8.11"

WORKDIR /app

# php extensions installer: https://github.com/mlocati/docker-php-extension-installer
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions

RUN apt-get update && apt-get install -y --no-install-recommends \
git \
acl \
file \
gettext \
procps \
supervisor \
unzip \
zip \
imagemagick \
gifsicle \
jpegoptim \
optipng \
pngquant \
libnss3-tools \
mailcap \
libcap2-bin \
# Runtime libraries of the webp tools unpacked below
libgif7 libjpeg62-turbo libpng16-16t64 libsharpyuv0 libtiff6 libwebp7 libwebpdemux2 libwebpmux3 \
# The webp package depends on OpenGL (~200 MB of Mesa and LLVM) only for its vwebp viewer:
# unpack its command-line tools instead of installing it.
&& cd /tmp && apt-get download webp \
&& dpkg-deb --fsys-tarfile webp_*.deb | tar -x -C / \
./usr/bin/cwebp ./usr/bin/dwebp ./usr/bin/gif2webp ./usr/bin/img2webp ./usr/bin/webpinfo ./usr/bin/webpmux \
&& rm webp_*.deb \
&& rm -rf /var/lib/apt/lists/*

# Same layout as the upstream FrankenPHP image
RUN set -eux; \
mkdir -p /app/public /config/caddy /data/caddy /etc/caddy /etc/frankenphp; \
sed -i 's/php/frankenphp run/g' /usr/local/bin/docker-php-entrypoint

EXPOSE 80
EXPOSE 443
EXPOSE 443/udp
EXPOSE 2019

# Install latest libvips
# @see https://github.com/dooman87/imagemagick-docker/blob/main/Dockerfile.bookworm
ARG VIPS_VERSION=8.18.7
ENV LD_LIBRARY_PATH="/usr/local/lib"
ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"

COPY --chmod=755 scripts/install-libvips.sh /tmp/install-libvips.sh
RUN /tmp/install-libvips.sh ${VIPS_VERSION} && rm /tmp/install-libvips.sh

# Install PHP extensions
RUN set -eux; install-php-extensions $EXTENSIONS

ARG PHPREDIS_REF=623e8db5a39657ba7218ceea81ab8338d248b036
COPY --chmod=755 scripts/install-phpredis.sh /tmp/install-phpredis.sh
RUN /tmp/install-phpredis.sh ${PHPREDIS_REF} && rm /tmp/install-phpredis.sh

# Keep frequently changing binaries and startup code after dependency installation.
COPY --from=builder /usr/local/lib/libwatcher* /usr/local/lib/
COPY --from=builder /usr/local/bin/frankenphp /usr/local/bin/frankenphp
# The builder stage sets cap_net_bind_service, which COPY keeps: running setcap here would
# rewrite the binary into another layer and store it twice.
RUN ldconfig \
&& frankenphp version
COPY --from=composer/composer:2-bin /composer /usr/bin/composer
COPY --link --chmod=755 ./8.6-frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint

ENTRYPOINT ["docker-entrypoint"]

# Copying manifest files to host
COPY ./8.6-frankenphp/manifest /

# Copy Imagemagick policy
RUN mv /etc/ImageMagick-7/IM7-policy.xml /etc/ImageMagick-7/policy.xml
8 changes: 8 additions & 0 deletions 8.6-frankenphp/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -e

if [ "${INSTALL_COMPOSER_DEPS:-0}" = "1" ] && [ -z "$(ls -A 'vendor/' 2>/dev/null)" ]; then
composer install --prefer-dist --no-progress --no-interaction
fi

exec docker-php-entrypoint "$@"
156 changes: 156 additions & 0 deletions 8.6-frankenphp/manifest/etc/ImageMagick-7/IM7-policy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policymap [
<!ELEMENT policymap (policy)*>
<!ATTLIST policymap xmlns CDATA #FIXED "">
<!ELEMENT policy EMPTY>
<!ATTLIST policy xmlns CDATA #FIXED "">
<!ATTLIST policy domain NMTOKEN #REQUIRED>
<!ATTLIST policy name NMTOKEN #IMPLIED>
<!ATTLIST policy pattern CDATA #IMPLIED>
<!ATTLIST policy rights NMTOKEN #IMPLIED>
<!ATTLIST policy stealth NMTOKEN #IMPLIED>
<!ATTLIST policy value CDATA #IMPLIED>
]>
<!--
Creating a security policy that fits your specific local environment
before making use of ImageMagick is highly advised. You can find guidance on
setting up this policy at https://imagemagick.org/script/security-policy.php,
and it's important to verify your policy using the validation tool located
at https://imagemagick-secevaluator.doyensec.com/.


Open ImageMagick security policy:

The default policy for ImageMagick installations is the open security
policy. This policy is designed for usage in secure settings like those
protected by firewalls or within Docker containers. Within this framework,
ImageMagick enjoys broad access to resources and functionalities. This policy
provides convenient and adaptable options for image manipulation. However,
it's important to note that it might present security vulnerabilities in
less regulated conditions. Thus, organizations should thoroughly assess
the appropriateness of the open policy according to their particular use
case and security prerequisites.

ImageMagick security policies in a nutshell:

Domains include system, delegate, coder, filter, module, path, or resource.

Rights include none, read, write, execute and all. Use | to combine them,
for example: "read | write" to permit read from, or write to, a path.

Use a glob expression as a pattern.

Suppose we do not want users to process MPEG video images, use this policy:

<policy domain="delegate" rights="none" pattern="mpeg:decode" />

Here we do not want users reading images from HTTP:

<policy domain="coder" rights="none" pattern="HTTP" />

The /repository file system is restricted to read only. We use a glob
expression to match all paths that start with /repository:

<policy domain="path" rights="read" pattern="/repository/*" />

Prevent users from executing any image filters:

<policy domain="filter" rights="none" pattern="*" />

Cache large images to disk rather than memory:

<policy domain="resource" name="area" value="1GP"/>

Use the default system font unless overridden by the application:

<policy domain="system" name="font" value="/usr/share/fonts/favorite.ttf"/>

Define arguments for the memory, map, area, width, height and disk resources
with SI prefixes (.e.g 100MB). In addition, resource policies are maximums
for each instance of ImageMagick (e.g. policy memory limit 1GB, -limit 2GB
exceeds policy maximum so memory limit is 1GB).

Rules are processed in order. Here we want to restrict ImageMagick to only
read or write a small subset of proven web-safe image types:

<policy domain="delegate" rights="none" pattern="*" />
<policy domain="filter" rights="none" pattern="*" />
<policy domain="coder" rights="none" pattern="*" />
<policy domain="coder" rights="read|write" pattern="{GIF,JPEG,PNG,WEBP}" />

See https://imagemagick.org/script/security-policy.php for a deeper
understanding of ImageMagick security policies.
-->
<policymap>
<policy domain="Undefined" rights="none"/>
<!-- Set maximum parallel threads. -->
<!-- <policy domain="resource" name="thread" value="2"/> -->
<!-- Set maximum time in seconds. When this limit is exceeded, an exception
is thrown and processing stops. -->
<!-- <policy domain="resource" name="time" value="120"/> -->
<!-- Set maximum number of open pixel cache files. When this limit is
exceeded, any subsequent pixels cached to disk are closed and reopened
on demand. -->
<!-- <policy domain="resource" name="file" value="768"/> -->
<!-- Set maximum amount of memory in bytes to allocate for the pixel cache
from the heap. When this limit is exceeded, the image pixels are cached
to memory-mapped disk. -->
<policy domain="resource" name="memory" value="1024MiB"/>
<!-- Set maximum amount of memory map in bytes to allocate for the pixel
cache. When this limit is exceeded, the image pixels are cached to
disk. -->
<policy domain="resource" name="map" value="2048MiB"/>
<!-- Set the maximum width * height of an image that can reside in the pixel
cache memory. Images that exceed the area limit are cached to disk. -->
<policy domain="resource" name="area" value="512MP"/>
<!-- Set maximum amount of disk space in bytes permitted for use by the pixel
cache. When this limit is exceeded, the pixel cache is not be created
and an exception is thrown. -->
<policy domain="resource" name="disk" value="2GiB"/>
<!-- Set the maximum length of an image sequence. When this limit is
exceeded, an exception is thrown. -->
<!-- <policy domain="resource" name="list-length" value="32"/> -->
<!-- Set the maximum width of an image. When this limit is exceeded, an
exception is thrown. -->
<policy domain="resource" name="width" value="128KP"/>
<!-- Set the maximum height of an image. When this limit is exceeded, an
exception is thrown. -->
<policy domain="resource" name="height" value="128KP"/>
<!-- Periodically yield the CPU for at least the time specified in
milliseconds. -->
<!-- <policy domain="resource" name="throttle" value="2"/> -->
<!-- Do not create temporary files in the default shared directories, instead
specify a private area to store only ImageMagick temporary files. -->
<!-- <policy domain="resource" name="temporary-path" value="/magick/tmp/"/> -->
<!-- Force memory initialization by memory mapping select memory
allocations. -->
<!-- <policy domain="cache" name="memory-map" value="anonymous"/> -->
<!-- Ensure all image data is fully flushed and synchronized to disk. -->
<!-- <policy domain="cache" name="synchronize" value="true"/> -->
<!-- Replace passphrase for secure distributed processing -->
<!-- <policy domain="cache" name="shared-secret" value="secret-passphrase" stealth="true"/> -->
<!-- Do not permit any delegates to execute. -->
<!-- <policy domain="delegate" rights="none" pattern="*"/> -->
<!-- Do not permit any image filters to load. -->
<!-- <policy domain="filter" rights="none" pattern="*"/> -->
<!-- Don't read/write from/to stdin/stdout. -->
<!-- <policy domain="path" rights="none" pattern="-"/> -->
<!-- don't read sensitive paths. -->
<!-- <policy domain="path" rights="none" pattern="/etc/*"/> -->
<!-- Indirect reads are not permitted. -->
<policy domain="path" rights="none" pattern="@*"/>
<!-- These image types are security risks on read, but write is fine -->
<!-- <policy domain="module" rights="write" pattern="{MSL,MVG,PS,SVG,URL,XPS}"/> -->
<!-- This policy sets the number of times to replace content of certain
memory buffers and temporary files before they are freed or deleted. -->
<!-- <policy domain="system" name="shred" value="1"/> -->
<!-- Enable the initialization of buffers with zeros, resulting in a minor
performance penalty but with improved security. -->
<!-- <policy domain="system" name="memory-map" value="anonymous"/> -->
<!-- Set the maximum amount of memory in bytes that are permitted for
allocation requests. -->
<!-- <policy domain="system" name="max-memory-request" value="256MiB"/> -->
<policy domain="delegate" rights="none" pattern="URL" />
<policy domain="delegate" rights="none" pattern="HTTPS" />
<policy domain="delegate" rights="none" pattern="HTTP" />
</policymap>
26 changes: 26 additions & 0 deletions 8.6-frankenphp/manifest/etc/frankenphp/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
{$CADDY_GLOBAL_OPTIONS}

frankenphp {
{$FRANKENPHP_CONFIG}
}
}

{$CADDY_EXTRA_CONFIG}

{$SERVER_NAME:localhost} {
log {
output stdout
format console
}

root * /app/public
encode zstd br gzip

{$CADDY_SERVER_EXTRA_DIRECTIVES}

# Disable Topics tracking if not enabled explicitly: https://github.com/jkarlin/topics
header ?Permissions-Policy "browsing-topics=()"

php_server
}
4 changes: 4 additions & 0 deletions 8.6-frankenphp/manifest/etc/frankenphp/worker.Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
worker {
file /app/public/index.php
env APP_RUNTIME Runtime\FrankenPhpSymfony\Runtime
}
Loading
Loading