alpine.Dockerfile 3.5 KB

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