alpine.Dockerfile 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # syntax=docker/dockerfile:1
  2. FROM php-base AS common
  3. ARG TARGETARCH
  4. WORKDIR /app
  5. RUN apk add --no-cache \
  6. ca-certificates \
  7. libcap \
  8. mailcap
  9. RUN set -eux; \
  10. mkdir -p \
  11. /app/public \
  12. /config/caddy \
  13. /data/caddy \
  14. /etc/caddy; \
  15. sed -i 's/php/frankenphp run/g' /usr/local/bin/docker-php-entrypoint; \
  16. echo '<?php phpinfo();' > /app/public/index.php
  17. COPY --link caddy/frankenphp/Caddyfile /etc/caddy/Caddyfile
  18. COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
  19. CMD ["--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
  20. HEALTHCHECK CMD curl -f http://localhost:2019/metrics || exit 1
  21. # See https://caddyserver.com/docs/conventions#file-locations for details
  22. ENV XDG_CONFIG_HOME=/config
  23. ENV XDG_DATA_HOME=/data
  24. EXPOSE 80
  25. EXPOSE 443
  26. EXPOSE 443/udp
  27. EXPOSE 2019
  28. LABEL org.opencontainers.image.title=FrankenPHP
  29. LABEL org.opencontainers.image.description="The modern PHP app server"
  30. LABEL org.opencontainers.image.url=https://frankenphp.dev
  31. LABEL org.opencontainers.image.source=https://github.com/dunglas/frankenphp
  32. LABEL org.opencontainers.image.licenses=MIT
  33. LABEL org.opencontainers.image.vendor="Kévin Dunglas"
  34. FROM common AS builder
  35. ARG FRANKENPHP_VERSION='dev'
  36. SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
  37. COPY --link --from=golang-base /usr/local/go /usr/local/go
  38. ENV PATH=/usr/local/go/bin:$PATH
  39. # hadolint ignore=SC2086
  40. RUN apk add --no-cache --virtual .build-deps \
  41. $PHPIZE_DEPS \
  42. argon2-dev \
  43. brotli-dev \
  44. coreutils \
  45. curl-dev \
  46. gnu-libiconv-dev \
  47. libsodium-dev \
  48. libxml2-dev \
  49. linux-headers \
  50. oniguruma-dev \
  51. openssl-dev \
  52. readline-dev \
  53. sqlite-dev \
  54. upx \
  55. # Needed for the custom Go build
  56. git \
  57. bash
  58. # FIXME: temporary workaround for https://github.com/golang/go/issues/68285
  59. WORKDIR /
  60. RUN git clone https://go.googlesource.com/go goroot
  61. WORKDIR /goroot
  62. # Revert https://github.com/golang/go/commit/3560cf0afb3c29300a6c88ccd98256949ca7a6f6 to prevent the crash with musl
  63. RUN git config --global user.email "build@example.com" && \
  64. git config --global user.name "Build" && \
  65. git checkout "$(go env GOVERSION)" && \
  66. git revert 3560cf0afb3c29300a6c88ccd98256949ca7a6f6
  67. WORKDIR /goroot/src
  68. ENV GOHOSTARCH="$TARGETARCH"
  69. RUN ./make.bash
  70. ENV PATH="/goroot/bin:$PATH"
  71. RUN go version
  72. WORKDIR /go/src/app
  73. COPY --link go.mod go.sum ./
  74. RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get
  75. WORKDIR /go/src/app/caddy
  76. COPY caddy/go.mod caddy/go.sum ./
  77. RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get
  78. WORKDIR /go/src/app
  79. COPY --link *.* ./
  80. COPY --link caddy caddy
  81. COPY --link internal internal
  82. COPY --link testdata testdata
  83. # todo: automate this?
  84. # see https://github.com/docker-library/php/blob/master/8.2/bookworm/zts/Dockerfile#L57-L59 for php values
  85. ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS" CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $PHP_CFLAGS" CGO_CPPFLAGS=$PHP_CPPFLAGS
  86. WORKDIR /go/src/app/caddy/frankenphp
  87. RUN GOBIN=/usr/local/bin go install -ldflags "-w -s -extldflags '-Wl,-z,stack-size=0x80000' -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" && \
  88. setcap cap_net_bind_service=+ep /usr/local/bin/frankenphp && \
  89. upx --best /usr/local/bin/frankenphp && \
  90. frankenphp version
  91. WORKDIR /go/src/app
  92. FROM common AS runner
  93. ENV GODEBUG=cgocheck=0
  94. COPY --from=builder /usr/local/bin/frankenphp /usr/local/bin/frankenphp
  95. RUN setcap cap_net_bind_service=+ep /usr/local/bin/frankenphp && \
  96. frankenphp version