This repository has been archived by the owner on Aug 6, 2023. It is now read-only.
forked from dunglas/frankenphp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.alpine
147 lines (117 loc) · 3.82 KB
/
Dockerfile.alpine
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
FROM php:8.2.6-zts-alpine3.17 AS php
# Note that this image is based on the official PHP image, once https://github.com/php/php-src/pull/10141 is merged, this stage can be removed
RUN rm -Rf /usr/local/include/php/ /usr/local/lib/libphp.* /usr/local/lib/php/ /usr/local/php/
ENV PHPIZE_DEPS \
autoconf \
dpkg-dev dpkg \
file \
g++ \
gcc \
libc-dev \
make \
pkgconf \
re2c
RUN apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
argon2-dev \
coreutils \
curl-dev \
readline-dev \
libsodium-dev \
sqlite-dev \
openssl-dev \
libxml2-dev \
gnu-libiconv-dev \
linux-headers \
oniguruma-dev \
bison \
git
WORKDIR /usr/src
RUN tar xf php.tar.xz && \
cd php-8.2.6 && \
./configure \
--enable-embed \
--enable-zts \
--disable-zend-signals \
--enable-zend-max-execution-timers \
--enable-mysqlnd \
--enable-option-checking=fatal \
--with-mhash \
--with-pic \
--enable-ftp \
--enable-mbstring \
--with-password-argon2 \
--with-sodium=shared \
--with-pdo-sqlite=/usr \
--with-sqlite3=/usr \
--with-curl \
--with-iconv \
--with-openssl \
--with-readline \
--with-zlib \
--disable-phpdbg \
--with-config-file-path="$PHP_INI_DIR" \
--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" && \
make -j$(nproc) && \
make install && \
rm -Rf php-8.2.6 && \
php --version
RUN mkdir -p /tmp/lib && cd /usr/lib && \
ldd /usr/local/bin/php | grep '=> /usr/lib/' | cut -d' ' -f3 | sed 's#/usr/lib/##g' | xargs -I % cp --parents "%" /tmp/lib/
FROM golang:1.20.4-alpine AS builder
RUN apk add --no-cache gcc libc-dev
RUN apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
argon2-dev \
coreutils \
curl-dev \
gnu-libiconv-dev \
libsodium-dev \
libxml2-dev \
linux-headers \
oniguruma-dev \
openssl-dev \
readline-dev \
sqlite-dev
WORKDIR /go/src/app
COPY go.mod go.sum ./
RUN go mod download
COPY ./caddy/go.mod ./caddy/go.sum ./caddy/
RUN cd caddy && go mod download
COPY . .
# todo: automate this?
# see https://github.com/docker-library/php/blob/master/8.2-rc/bullseye/zts/Dockerfile#L57-L59 for php values
ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS" CGO_CFLAGS=$PHP_CFLAGS CGO_CPPFLAGS=$PHP_CPPFLAGS
COPY --from=php /usr/local/include/php/ /usr/local/include/php
COPY --from=php /usr/local/lib/libphp.* /usr/local/lib
RUN ln -s /usr/local/lib/libphp.so /usr/lib/libphp.so
WORKDIR /go/src/app/caddy/frankenphp
RUN go build && \
mv ./frankenphp /usr/local/bin/frankenphp && \
mv ./Caddyfile /etc/Caddyfile
WORKDIR /go/src/app
FROM php:8.2.6-zts-alpine3.17 AS final
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN mkdir -p /app/public
RUN echo '<?php phpinfo();' > /app/public/index.php
COPY --from=builder /usr/local/bin/frankenphp /usr/local/bin/frankenphp
COPY --from=builder /etc/Caddyfile /etc/Caddyfile
COPY --from=php /usr/local/include/php/ /usr/local/include/php
COPY --from=php /usr/local/lib/libphp.* /usr/local/lib
COPY --from=php /usr/local/lib/php/ /usr/local/lib/php
COPY --from=php /usr/local/php/ /usr/local/php
COPY --from=php /usr/local/bin/ /usr/local/bin
COPY --from=php /usr/src /usr/src
RUN sed -i 's/php/frankenphp run/g' /usr/local/bin/docker-php-entrypoint
WORKDIR /app
CMD [ "--config", "/etc/Caddyfile" ]
FROM alpine:3.17 AS slim
COPY --from=builder /usr/local/bin/frankenphp /usr/local/bin/frankenphp
COPY --from=builder /etc/Caddyfile /etc/Caddyfile
COPY --from=php /bin/sh /bin/
COPY --from=php /lib/ /lib/
COPY --from=php /tmp/lib/ /usr/lib/
COPY --from=final /app /app
COPY --from=final /usr/local/bin/docker-php-* /usr/local/bin/php /usr/local/bin/frankenphp /usr/local/bin/
WORKDIR /app
CMD [ "--config", "/etc/Caddyfile" ]