2022-10-19 05:40:31 +00:00
FROM php:8.2.0RC4-zts-bullseye AS php-base
# Note that this image is based on the official PHP image, once 8.3 is released, this stage can likely be removed
RUN rm -Rf /usr/local/include/php/ /usr/local/lib/libphp.* /usr/local/lib/php/ /usr/local/php/
2021-09-24 16:52:20 +00:00
2022-10-04 12:36:03 +00:00
ENV PHPIZE_DEPS \
autoconf \
dpkg-dev \
file \
g++ \
gcc \
libc-dev \
make \
pkg-config \
re2c
2021-09-24 16:52:20 +00:00
RUN apt-get update && \
2022-10-04 12:36:03 +00:00
apt-get -y --no-install-recommends install \
$PHPIZE_DEPS \
libargon2-dev \
libcurl4-openssl-dev \
libonig-dev \
libreadline-dev \
libsodium-dev \
libsqlite3-dev \
libssl-dev \
libxml2-dev \
zlib1g-dev \
bison \
2022-10-19 05:40:31 +00:00
git \
2022-10-04 12:36:03 +00:00
&& \
2022-10-19 05:40:31 +00:00
apt-get clean
2022-10-04 12:36:03 +00:00
2022-10-13 16:05:22 +00:00
RUN git clone --depth= 1 --single-branch --branch= frankenphp-8.2 https://github.com/dunglas/php-src.git && \
2022-10-04 12:36:03 +00:00
cd php-src && \
2021-09-24 16:52:20 +00:00
# --enable-embed is only necessary to generate libphp.so, we don't use this SAPI directly
2022-10-04 12:36:03 +00:00
./buildconf && \
2022-10-13 16:05:22 +00:00
./configure \
2022-10-19 09:19:49 +00:00
--enable-embed \
2022-10-13 16:05:22 +00:00
--enable-zts \
2022-10-15 16:57:16 +00:00
--disable-zend-signals \
2022-10-19 05:40:31 +00:00
# --enable-mysqlnd is included here because it's harder to compile after the fact than extensions are (since it's a plugin for several extensions, not an extension in itself)
--enable-mysqlnd \
# make sure invalid --configure-flags are fatal errors instead of just warnings
--enable-option-checking= fatal \
# https://github.com/docker-library/php/issues/439
--with-mhash \
# https://github.com/docker-library/php/issues/822
--with-pic \
# --enable-ftp is included here because ftp_ssl_connect() needs ftp to be compiled statically (see https://github.com/docker-library/php/issues/236)
--enable-ftp \
# --enable-mbstring is included here because otherwise there's no way to get pecl to use it properly (see https://github.com/docker-library/php/issues/195)
--enable-mbstring \
# https://wiki.php.net/rfc/argon2_password_hash
--with-password-argon2 \
# https://wiki.php.net/rfc/libsodium
--with-sodium= shared \
# always build against system sqlite3 (https://github.com/php/php-src/commit/6083a387a81dbbd66d6316a3a12a63f06d5f7109)
--with-pdo-sqlite= /usr \
--with-sqlite3= /usr \
--with-curl \
--with-iconv \
--with-openssl \
--with-readline \
--with-zlib \
# https://github.com/bwoebi/phpdbg-docs/issues/1#issuecomment-163872806 ("phpdbg is primarily a CLI debugger, and is not suitable for debugging an fpm stack.")
--disable-phpdbg \
--with-config-file-path= " $PHP_INI_DIR " \
--with-config-file-scan-dir= " $PHP_INI_DIR /conf.d " && \
2022-10-15 07:46:44 +00:00
make -j$( nproc) && \
2021-09-24 16:52:20 +00:00
make install && \
2022-10-13 16:05:22 +00:00
rm -Rf php-src/ && \
2022-10-19 05:40:31 +00:00
echo "Creating src archive for building extensions\n" && \
tar -c -f /usr/src/php.tar.xz -J /php-src/ && \
2022-10-04 12:36:03 +00:00
ldconfig && \
php --version
2022-10-19 05:40:31 +00:00
FROM php-base AS builder
COPY --from= golang:bullseye /usr/local/go/bin/go /usr/local/bin/go
COPY --from= golang:bullseye /usr/local/go /usr/local/go
2021-09-24 16:52:20 +00:00
WORKDIR /go/src/app
2022-10-13 16:05:22 +00:00
COPY go.mod go.sum ./
RUN go get -v ./...
RUN mkdir caddy && cd caddy
COPY go.mod go.sum ./
2022-10-19 05:40:31 +00:00
RUN go get -v ./...
2022-10-13 16:05:22 +00:00
2021-09-24 16:52:20 +00:00
COPY . .
2022-10-19 05:40:31 +00:00
# todo: automate this?
# see https://github.com/docker-library/php/blob/master/8.2-rc/bullseye/zts/Dockerfile#L57-L59 for php values
ENV CGO_LDFLAGS = " -lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS " CGO_CFLAGS = $PHP_CFLAGS CGO_CPPFLAGS = $PHP_CPPFLAGS
2022-10-13 16:05:22 +00:00
RUN cd caddy/frankenphp && \
go build && \
cp frankenphp /usr/local/bin && \
2022-10-19 05:40:31 +00:00
cp /go/src/app/caddy/frankenphp/Caddyfile /etc/Caddyfile
FROM php:8.2.0RC4-zts-bullseye AS final
COPY --from= mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
2022-10-13 16:05:22 +00:00
WORKDIR /app
RUN mkdir -p /app/public
RUN echo '<?php phpinfo();' > /app/public/index.php
2022-10-19 05:40:31 +00:00
COPY --from= builder /usr/local/bin/frankenphp /usr/local/bin/frankenphp
COPY --from= builder /etc/Caddyfile /etc/Caddyfile
COPY --from= php-base /usr/local/include/php/ /usr/local/include/php
COPY --from= php-base /usr/local/lib/libphp.* /usr/local/lib
COPY --from= php-base /usr/local/lib/php/ /usr/local/lib/php
COPY --from= php-base /usr/local/php/ /usr/local/php
COPY --from= php-base /usr/local/bin/ /usr/local/bin
COPY --from= php-base /usr/src /usr/src
RUN sed -i 's/php/frankenphp run/g' /usr/local/bin/docker-php-entrypoint
CMD [ "--config" , "/etc/Caddyfile" ]