Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 479
WiP: One Dockerfile to rule them all#64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
1f6da3392d79a3455082c13210af3426f97a399affcf4d205207b57adcbed906f5a3020cd63652fa3e25bf6f058502b71256c0785908917c509533a027dadadc0ca2bbfd4ad5f5e2163a3855f7a02590e750eb4e02088deFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,10 @@ | ||
| Dockerfile | ||
| Dockerfile.dev | ||
| /.git/ | ||
| /.github/ | ||
| /.gitmodules/ | ||
| /.idea/ | ||
| /.vscode/ | ||
back-2-95 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /docs/ | ||
| /*Dockerfile* | ||
| /.*ignore | ||
| /*.hcl | ||
| /*.md | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,7 @@ on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| jobs: | ||
| docker-tests: | ||
| runs-on: ubuntu-latest | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,144 +1,156 @@ | ||
| FROM php:8.2.0RC5-zts-bullseye AS php-base | ||
| # rebuild PHP until https://github.com/docker-library/php/pull/1331 is merged | ||
| RUN set -eux; \ | ||
| \ | ||
| savedAptMark="$(apt-mark showmanual)"; \ | ||
| apt-get update; \ | ||
| apt-get install -y --no-install-recommends \ | ||
| libargon2-dev \ | ||
| libcurl4-openssl-dev \ | ||
| libonig-dev \ | ||
| libreadline-dev \ | ||
| libsodium-dev \ | ||
| libsqlite3-dev \ | ||
| libssl-dev \ | ||
| libxml2-dev \ | ||
| zlib1g-dev \ | ||
| ; \ | ||
| \ | ||
| export \ | ||
| CFLAGS="$PHP_CFLAGS" \ | ||
| CPPFLAGS="$PHP_CPPFLAGS" \ | ||
| LDFLAGS="$PHP_LDFLAGS" \ | ||
| ; \ | ||
| docker-php-source extract; \ | ||
| cd /usr/src/php; \ | ||
| gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ | ||
| debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)"; \ | ||
| ./configure \ | ||
| --build="$gnuArch" \ | ||
| --with-config-file-path="$PHP_INI_DIR" \ | ||
| --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \ | ||
| \ | ||
| # 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 \ | ||
| # --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 \ | ||
| # 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) | ||
| # syntax=docker/dockerfile:1.4 | ||
| ARG DISTRO | ||
| # | ||
| # Base images | ||
| # | ||
| FROM php:8.2.0RC5-zts-bullseye as php-bullseye | ||
| FROM php:8.2.0RC5-zts-alpine3.16 as php-alpine316 | ||
| FROM php-${DISTRO} as php | ||
| # | ||
| # Golang images | ||
| # | ||
| FROM golang:bullseye as golang-bullseye | ||
| FROM golang:alpine3.16 as golang-alpine316 | ||
| FROM golang-${DISTRO} as golang | ||
| # | ||
| # php-src builder | ||
| # | ||
| # See https://github.com/docker-library/php/blob/master/Dockerfile-linux.template | ||
| # to see how php-src is build on debian and alpine | ||
| # | ||
| # Debian based | ||
| FROM php as php-debian | ||
| ENV PHPIZE_DEPS \ | ||
| autoconf \ | ||
| dpkg-dev \ | ||
| file \ | ||
| g++ \ | ||
| gcc \ | ||
| libc-dev \ | ||
| make \ | ||
| pkg-config \ | ||
| re2c | ||
| RUN apt-get update && \ | ||
| 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 \ | ||
| git | ||
| FROM php-debian as php-src-bullseye | ||
| # Alpine based | ||
| FROM php as php-alpine | ||
| ENV PHPIZE_DEPS \ | ||
| autoconf \ | ||
| dpkg-dev dpkg \ | ||
| file \ | ||
| g++ \ | ||
| gcc \ | ||
| libc-dev \ | ||
| make \ | ||
| pkgconf \ | ||
| re2c | ||
| RUN apk add --no-cache \ | ||
| $PHPIZE_DEPS \ | ||
| argon2-dev \ | ||
| coreutils \ | ||
| curl-dev \ | ||
| readline-dev \ | ||
| libsodium-dev \ | ||
| sqlite-dev \ | ||
| openssl-dev \ | ||
| libxml2-dev \ | ||
| gnu-libiconv-dev \ | ||
| linux-headers \ | ||
| oniguruma-dev \ | ||
| bison \ | ||
| git | ||
| FROM php-alpine as php-src-alpine316 | ||
| # | ||
| # Clone of php-src repository | ||
| # | ||
| FROM alpine/git AS repo | ||
back-2-95 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| RUN git clone --depth=1 --single-branch --branch=PHP-8.2 https://github.com/php/php-src.git /php-src | ||
back-2-95 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| # | ||
| # php-src builder - actual build phase | ||
| # | ||
| FROM php-src-${DISTRO} AS php-src | ||
| RUN rm -Rf /usr/local/include/php/ /usr/local/lib/libphp.* /usr/local/lib/php/ /usr/local/php/ | ||
| COPY --from=repo /php-src /php-src | ||
| WORKDIR /php-src/ | ||
| # --enable-embed is only necessary to generate libphp.so, we don't use this SAPI directly | ||
| RUN ./buildconf | ||
| RUN ./configure \ | ||
| --enable-embed \ | ||
| --enable-zts \ | ||
| --disable-zend-signals \ | ||
| # --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.") | ||
| # 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 \ | ||
| \ | ||
| # in PHP 7.4+, the pecl/pear installers are officially deprecated (requiring an explicit "--with-pear") | ||
| --with-pear \ | ||
| \ | ||
| # bundled pcre does not support JIT on s390x | ||
| # https://manpages.debian.org/bullseye/libpcre3-dev/pcrejit.3.en.html#AVAILABILITY_OF_JIT_SUPPORT | ||
| $(test "$gnuArch" = 's390x-linux-gnu' && echo '--without-pcre-jit') \ | ||
| --with-libdir="lib/$debMultiarch" \ | ||
| \ | ||
| --disable-cgi \ | ||
| \ | ||
| # https://github.com/docker-library/php/pull/939#issuecomment-730501748 | ||
| --enable-embed \ | ||
| \ | ||
| --enable-zts \ | ||
| # https://externals.io/message/118859 | ||
| --disable-zend-signals \ | ||
| ; \ | ||
| make -j "$(nproc)"; \ | ||
| find -type f -name '*.a' -delete; \ | ||
| make install; \ | ||
| find \ | ||
| /usr/local \ | ||
| -type f \ | ||
| -perm '/0111' \ | ||
| -exec sh -euxc ' \ | ||
| strip --strip-all "$@" || : \ | ||
| ' -- '{}' + \ | ||
| ; \ | ||
| make clean; \ | ||
| \ | ||
| # https://github.com/docker-library/php/issues/692 (copy default example "php.ini" files somewhere easily discoverable) | ||
| cp -v php.ini-* "$PHP_INI_DIR/"; \ | ||
| \ | ||
| cd /; \ | ||
| docker-php-source delete; \ | ||
| \ | ||
| # reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies | ||
| apt-mark auto '.*' > /dev/null; \ | ||
| [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \ | ||
| find /usr/local -type f -executable -exec ldd '{}' ';' \ | ||
| | awk '/=>/ { print $(NF-1) }' \ | ||
| | sort -u \ | ||
| | xargs -r dpkg-query --search \ | ||
| | cut -d: -f1 \ | ||
| | sort -u \ | ||
| | xargs -r apt-mark manual \ | ||
| ; \ | ||
| apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ | ||
| rm -rf /var/lib/apt/lists/*; \ | ||
| \ | ||
| # update pecl channel definitions https://github.com/docker-library/php/issues/443 | ||
| pecl update-channels; \ | ||
| rm -rf /tmp/pear ~/.pearrc; \ | ||
| \ | ||
| # smoke test | ||
| php --version | ||
| 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 | ||
| # This is required to link the frankenPHP binary to the PHP binary | ||
| RUN apt-get update && \ | ||
| apt-get -y --no-install-recommends install \ | ||
| libargon2-dev \ | ||
| libcurl4-openssl-dev \ | ||
| libonig-dev \ | ||
| libreadline-dev \ | ||
| libsodium-dev \ | ||
| libsqlite3-dev \ | ||
| libssl-dev \ | ||
| libxml2-dev \ | ||
| zlib1g-dev \ | ||
| && \ | ||
| apt-get clean | ||
| --with-config-file-path="$PHP_INI_DIR" \ | ||
| --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" | ||
| RUN make -j$(nproc) | ||
back-2-95 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| RUN make install | ||
| RUN rm -Rf /php-src/ | ||
| RUN echo "Creating src archive for building extensions\n" | ||
| RUN tar -c -f /usr/src/php.tar.xz -J /php-src/ | ||
| RUN php --version | ||
| # | ||
| # Builder | ||
| # | ||
| FROM php-src AS builder | ||
| COPY --from=golang /usr/local/go/bin/go /usr/local/bin/go | ||
| COPY --from=golang /usr/local/go /usr/local/go | ||
| WORKDIR /go/src/app | ||
| @@ -150,35 +162,43 @@ COPY caddy/go.mod caddy/go.sum ./caddy/ | ||
| RUN cd caddy && go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get | ||
| COPY *.* ./ | ||
| COPY caddy caddy | ||
| COPY C-Thread-Pool C-Thread-Pool | ||
| COPY internal internal | ||
| COPY testdata testdata | ||
| COPY . . | ||
back-2-95 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| # 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 | ||
| RUN cd caddy/frankenphp && \ | ||
| go build && \ | ||
| cp frankenphp /usr/local/bin && \ | ||
| cp /go/src/app/caddy/frankenphp/Caddyfile /etc/Caddyfile | ||
| RUN cd caddy/frankenphp && go build | ||
| ENTRYPOINT ["/bin/bash","-c"] | ||
| # | ||
| # FrankenPHP image | ||
| # | ||
| FROM php AS frankenphp | ||
| FROM php-base AS final | ||
| WORKDIR /app | ||
| # Add PHP extension installer | ||
| # See https://github.com/mlocati/docker-php-extension-installer | ||
| COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ | ||
| WORKDIR /app | ||
| # Copy build FrankenPHP binary | ||
| COPY --from=builder /go/src/app/caddy/frankenphp/frankenphp /usr/local/bin/frankenphp | ||
| # Copy build PHP | ||
| COPY --from=builder /usr/local/include/php/ /usr/local/include/php | ||
| COPY --from=builder /usr/local/lib/libphp.* /usr/local/lib | ||
| COPY --from=builder /usr/local/lib/php/ /usr/local/lib/php | ||
| COPY --from=builder /usr/local/php/ /usr/local/php | ||
| COPY --from=builder /usr/local/bin/ /usr/local/bin | ||
| COPY --from=builder /usr/src /usr/src | ||
| RUN mkdir -p /app/public | ||
| RUN echo '<?php phpinfo();' > /app/public/index.php | ||
| # Copy Caddy configuration | ||
| COPY caddy/frankenphp/Caddyfile /etc/Caddyfile | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it's OK to copy the Caddyfile here @dunglas ? | ||
| COPY --from=builder /usr/local/bin/frankenphp /usr/local/bin/frankenphp | ||
| COPY --from=builder /etc/Caddyfile /etc/Caddyfile | ||
| # Create default file to serve | ||
| RUN mkdir -p /app/public && echo '<?php phpinfo();' > /app/public/index.php | ||
| # Modify docker-php-entrypoint to start frankenphp | ||
| RUN sed -i 's/php/frankenphp run/g' /usr/local/bin/docker-php-entrypoint | ||
| CMD [ "--config", "/etc/Caddyfile" ] | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.