Dockerfile.alpine 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. FROM php:8.2.0RC4-zts-alpine3.16 AS php-base
  2. # Note that this image is based on the official PHP image, once 8.3 is released, this stage can likely be removed
  3. RUN rm -Rf /usr/local/include/php/ /usr/local/lib/libphp.* /usr/local/lib/php/ /usr/local/php/
  4. ENV PHPIZE_DEPS \
  5. autoconf \
  6. dpkg-dev dpkg \
  7. file \
  8. g++ \
  9. gcc \
  10. libc-dev \
  11. make \
  12. pkgconf \
  13. re2c
  14. RUN apk add --no-cache --virtual .build-deps \
  15. $PHPIZE_DEPS \
  16. argon2-dev \
  17. coreutils \
  18. curl-dev \
  19. readline-dev \
  20. libsodium-dev \
  21. sqlite-dev \
  22. openssl-dev \
  23. libxml2-dev \
  24. gnu-libiconv-dev \
  25. linux-headers \
  26. oniguruma-dev \
  27. bison \
  28. git
  29. RUN git clone --depth=1 --single-branch --branch=PHP-8.2 https://github.com/php/php-src.git
  30. WORKDIR /php-src/
  31. # --enable-embed is only necessary to generate libphp.so, we don't use this SAPI directly
  32. RUN ./buildconf
  33. RUN ./configure \
  34. --enable-embed \
  35. --enable-zts \
  36. --disable-zend-signals \
  37. # --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)
  38. --enable-mysqlnd \
  39. # make sure invalid --configure-flags are fatal errors instead of just warnings
  40. --enable-option-checking=fatal \
  41. # https://github.com/docker-library/php/issues/439
  42. --with-mhash \
  43. # https://github.com/docker-library/php/issues/822
  44. --with-pic \
  45. # --enable-ftp is included here because ftp_ssl_connect() needs ftp to be compiled statically (see https://github.com/docker-library/php/issues/236)
  46. --enable-ftp \
  47. # --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)
  48. --enable-mbstring \
  49. # https://wiki.php.net/rfc/argon2_password_hash
  50. --with-password-argon2 \
  51. # https://wiki.php.net/rfc/libsodium
  52. --with-sodium=shared \
  53. # always build against system sqlite3 (https://github.com/php/php-src/commit/6083a387a81dbbd66d6316a3a12a63f06d5f7109)
  54. --with-pdo-sqlite=/usr \
  55. --with-sqlite3=/usr \
  56. --with-curl \
  57. --with-iconv \
  58. --with-openssl \
  59. --with-readline \
  60. --with-zlib \
  61. # 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.")
  62. --disable-phpdbg \
  63. --with-config-file-path="$PHP_INI_DIR" \
  64. --with-config-file-scan-dir="$PHP_INI_DIR/conf.d"
  65. RUN make -j$(nproc)
  66. RUN make install
  67. RUN rm -Rf /php-src/
  68. RUN echo "Creating src archive for building extensions\n"
  69. RUN tar -c -f /usr/src/php.tar.xz -J /php-src/
  70. #RUN ldconfig
  71. RUN php --version
  72. FROM php-base AS builder
  73. COPY --from=golang:alpine3.16 /usr/local/go/bin/go /usr/local/bin/go
  74. COPY --from=golang:alpine3.16 /usr/local/go /usr/local/go
  75. WORKDIR /go/src/app
  76. COPY go.mod go.sum ./
  77. RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get
  78. RUN mkdir caddy && cd caddy
  79. COPY caddy/go.mod caddy/go.sum ./caddy/
  80. RUN cd caddy && go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get
  81. COPY *.* ./
  82. COPY caddy caddy
  83. COPY C-Thread-Pool C-Thread-Pool
  84. COPY internal internal
  85. COPY testdata testdata
  86. # todo: automate this?
  87. # see https://github.com/docker-library/php/blob/master/8.2-rc/bullseye/zts/Dockerfile#L57-L59 for php values
  88. ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS" CGO_CFLAGS=$PHP_CFLAGS CGO_CPPFLAGS=$PHP_CPPFLAGS
  89. RUN cd caddy/frankenphp && \
  90. go build && \
  91. cp frankenphp /usr/local/bin && \
  92. cp /go/src/app/caddy/frankenphp/Caddyfile /etc/Caddyfile
  93. ENTRYPOINT ["/bin/bash","-c"]
  94. FROM php:8.2.0RC4-zts-alpine3.16 AS final
  95. COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
  96. WORKDIR /app
  97. RUN mkdir -p /app/public
  98. RUN echo '<?php phpinfo();' > /app/public/index.php
  99. COPY --from=builder /usr/local/bin/frankenphp /usr/local/bin/frankenphp
  100. COPY --from=builder /etc/Caddyfile /etc/Caddyfile
  101. COPY --from=php-base /usr/local/include/php/ /usr/local/include/php
  102. COPY --from=php-base /usr/local/lib/libphp.* /usr/local/lib
  103. COPY --from=php-base /usr/local/lib/php/ /usr/local/lib/php
  104. COPY --from=php-base /usr/local/php/ /usr/local/php
  105. COPY --from=php-base /usr/local/bin/ /usr/local/bin
  106. COPY --from=php-base /usr/src /usr/src
  107. RUN sed -i 's/php/frankenphp run/g' /usr/local/bin/docker-php-entrypoint
  108. CMD [ "--config", "/etc/Caddyfile" ]