Dockerfile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # syntax=docker/dockerfile:1
  2. FROM php-base AS common
  3. WORKDIR /app
  4. RUN apt-get update && \
  5. apt-get -y --no-install-recommends install \
  6. mailcap \
  7. libcap2-bin \
  8. && \
  9. apt-get clean && \
  10. rm -rf /var/lib/apt/lists/*
  11. RUN set -eux; \
  12. mkdir -p \
  13. /app/public \
  14. /config/caddy \
  15. /data/caddy \
  16. /etc/caddy; \
  17. sed -i 's/php/frankenphp run/g' /usr/local/bin/docker-php-entrypoint; \
  18. echo '<?php phpinfo();' > /app/public/index.php
  19. COPY --link caddy/frankenphp/Caddyfile /etc/caddy/Caddyfile
  20. COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
  21. CMD ["--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
  22. HEALTHCHECK CMD curl -f http://localhost:2019/metrics || exit 1
  23. # See https://caddyserver.com/docs/conventions#file-locations for details
  24. ENV XDG_CONFIG_HOME=/config
  25. ENV XDG_DATA_HOME=/data
  26. EXPOSE 80
  27. EXPOSE 443
  28. EXPOSE 443/udp
  29. EXPOSE 2019
  30. LABEL org.opencontainers.image.title=FrankenPHP
  31. LABEL org.opencontainers.image.description="The modern PHP app server"
  32. LABEL org.opencontainers.image.url=https://frankenphp.dev
  33. LABEL org.opencontainers.image.source=https://github.com/dunglas/frankenphp
  34. LABEL org.opencontainers.image.licenses=MIT
  35. LABEL org.opencontainers.image.vendor="Kévin Dunglas"
  36. FROM common AS builder
  37. ARG FRANKENPHP_VERSION='dev'
  38. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  39. COPY --from=golang-base /usr/local/go /usr/local/go
  40. ENV PATH=/usr/local/go/bin:$PATH
  41. # This is required to link the FrankenPHP binary to the PHP binary
  42. RUN apt-get update && \
  43. apt-get -y --no-install-recommends install \
  44. libargon2-dev \
  45. libbrotli-dev \
  46. libcurl4-openssl-dev \
  47. libonig-dev \
  48. libreadline-dev \
  49. libsodium-dev \
  50. libsqlite3-dev \
  51. libssl-dev \
  52. libxml2-dev \
  53. zlib1g-dev \
  54. # Needed by gotip
  55. git \
  56. && \
  57. apt-get clean
  58. RUN GOBIN=/usr/local/go/bin go install golang.org/dl/gotip@latest && gotip download
  59. WORKDIR /go/src/app
  60. COPY --link go.mod go.sum ./
  61. RUN gotip mod graph | awk '{if ($1 !~ "@") print $2}' | xargs gotip get
  62. WORKDIR /go/src/app/caddy
  63. COPY --link caddy/go.mod caddy/go.sum ./
  64. RUN gotip mod graph | awk '{if ($1 !~ "@") print $2}' | xargs gotip get
  65. WORKDIR /go/src/app
  66. COPY --link *.* ./
  67. COPY --link caddy caddy
  68. COPY --link internal internal
  69. COPY --link testdata testdata
  70. # todo: automate this?
  71. # see https://github.com/docker-library/php/blob/master/8.2/bookworm/zts/Dockerfile#L57-L59 for PHP values
  72. ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS" CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $PHP_CFLAGS" CGO_CPPFLAGS=$PHP_CPPFLAGS
  73. WORKDIR /go/src/app/caddy/frankenphp
  74. RUN GOBIN=/usr/local/bin gotip install -ldflags "-w -s -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" && \
  75. setcap cap_net_bind_service=+ep /usr/local/bin/frankenphp && \
  76. cp Caddyfile /etc/caddy/Caddyfile && \
  77. frankenphp version
  78. WORKDIR /go/src/app
  79. FROM common AS runner
  80. ENV GODEBUG=cgocheck=0
  81. COPY --from=builder /usr/local/bin/frankenphp /usr/local/bin/frankenphp
  82. RUN setcap cap_net_bind_service=+ep /usr/local/bin/frankenphp && \
  83. frankenphp version