Dockerfile 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. WORKDIR /app
  7. RUN apt-get update && \
  8. apt-get -y --no-install-recommends install \
  9. mailcap \
  10. libcap2-bin \
  11. && \
  12. apt-get clean && \
  13. rm -rf /var/lib/apt/lists/*
  14. RUN set -eux; \
  15. mkdir -p \
  16. /app/public \
  17. /config/caddy \
  18. /data/caddy \
  19. /etc/caddy; \
  20. sed -i 's/php/frankenphp run/g' /usr/local/bin/docker-php-entrypoint; \
  21. echo '<?php phpinfo();' > /app/public/index.php
  22. COPY --link caddy/frankenphp/Caddyfile /etc/caddy/Caddyfile
  23. RUN curl -sSLf \
  24. -o /usr/local/bin/install-php-extensions \
  25. https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions && \
  26. chmod +x /usr/local/bin/install-php-extensions
  27. CMD ["--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
  28. HEALTHCHECK CMD curl -f http://localhost:2019/metrics || exit 1
  29. # See https://caddyserver.com/docs/conventions#file-locations for details
  30. ENV XDG_CONFIG_HOME=/config
  31. ENV XDG_DATA_HOME=/data
  32. EXPOSE 80
  33. EXPOSE 443
  34. EXPOSE 443/udp
  35. EXPOSE 2019
  36. LABEL org.opencontainers.image.title=FrankenPHP
  37. LABEL org.opencontainers.image.description="The modern PHP app server"
  38. LABEL org.opencontainers.image.url=https://frankenphp.dev
  39. LABEL org.opencontainers.image.source=https://github.com/dunglas/frankenphp
  40. LABEL org.opencontainers.image.licenses=MIT
  41. LABEL org.opencontainers.image.vendor="Kévin Dunglas"
  42. FROM common AS builder
  43. ARG FRANKENPHP_VERSION='dev'
  44. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  45. COPY --from=golang-base /usr/local/go /usr/local/go
  46. ENV PATH=/usr/local/go/bin:$PATH
  47. # This is required to link the FrankenPHP binary to the PHP binary
  48. RUN apt-get update && \
  49. apt-get -y --no-install-recommends install \
  50. cmake \
  51. libargon2-dev \
  52. libbrotli-dev \
  53. libcurl4-openssl-dev \
  54. libonig-dev \
  55. libreadline-dev \
  56. libsodium-dev \
  57. libsqlite3-dev \
  58. libssl-dev \
  59. libxml2-dev \
  60. zlib1g-dev \
  61. && \
  62. apt-get clean
  63. WORKDIR /go/src/app
  64. COPY --link go.mod go.sum ./
  65. RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get
  66. WORKDIR /go/src/app/caddy
  67. COPY --link caddy/go.mod caddy/go.sum ./
  68. RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get
  69. WORKDIR /go/src/app
  70. COPY --link *.* ./
  71. COPY --link caddy caddy
  72. COPY --link internal internal
  73. COPY --link testdata testdata
  74. # Install e-dant/watcher (necessary for file watching)
  75. WORKDIR /usr/local/src/watcher
  76. RUN curl -s https://api.github.com/repos/e-dant/watcher/releases/latest | \
  77. grep tarball_url | \
  78. awk '{ print $2 }' | \
  79. sed 's/,$//' | \
  80. sed 's/"//g' | \
  81. xargs curl -L | \
  82. tar xz --strip-components 1 && \
  83. cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && \
  84. cmake --build build && \
  85. cmake --install build && \
  86. ldconfig
  87. # See https://github.com/docker-library/php/blob/master/8.3/bookworm/zts/Dockerfile#L57-L59 for PHP values
  88. ENV CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $PHP_CFLAGS"
  89. ENV CGO_CPPFLAGS=$PHP_CPPFLAGS
  90. ENV CGO_LDFLAGS="-L/usr/local/lib -lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS"
  91. RUN echo $CGO_LDFLAGS
  92. WORKDIR /go/src/app/caddy/frankenphp
  93. RUN GOBIN=/usr/local/bin go install -tags 'nobadger,nomysql,nopgx' -ldflags "-w -s -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" && \
  94. setcap cap_net_bind_service=+ep /usr/local/bin/frankenphp && \
  95. cp Caddyfile /etc/caddy/Caddyfile && \
  96. frankenphp version
  97. WORKDIR /go/src/app
  98. FROM common AS runner
  99. ENV GODEBUG=cgocheck=0
  100. # copy watcher shared library
  101. COPY --from=builder /usr/local/lib/libwatcher* /usr/local/lib/
  102. # fix for the file watcher on arm
  103. RUN apt-get install -y --no-install-recommends libstdc++6 && \
  104. apt-get clean && \
  105. ldconfig
  106. COPY --from=builder /usr/local/bin/frankenphp /usr/local/bin/frankenphp
  107. RUN setcap cap_net_bind_service=+ep /usr/local/bin/frankenphp && \
  108. frankenphp version