alpine.Dockerfile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 by gotip
  56. git \
  57. bash
  58. RUN GOBIN=/usr/local/go/bin go install golang.org/dl/gotip@latest && (yes || true) | gotip download 600296
  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 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 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'" && \
  75. setcap cap_net_bind_service=+ep /usr/local/bin/frankenphp && \
  76. upx --best /usr/local/bin/frankenphp && \
  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