Skip to content

Commit f51f73f

Browse files
committed
Switch to chainguard docker image
1 parent 533b83e commit f51f73f

File tree

2 files changed

+48
-23
lines changed

2 files changed

+48
-23
lines changed

Dockerfile

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
1-
# https://github.com/s6n-labs/distroless-php/blob/main/Dockerfile
2-
3-
ARG TAG=8.4
4-
FROM php:${TAG} AS php
5-
6-
RUN mkdir -p /tmp/lib && cd /lib && \
7-
ldd /usr/local/bin/php | grep '=> /lib/' | cut -d' ' -f3 | sed 's#/lib/##g' | xargs -I % cp --parents "%" /tmp/lib/
8-
9-
RUN mkdir -p /tmp/usr/lib && cd /usr/lib && \
10-
ldd /usr/local/bin/php | grep '=> /usr/lib/' | cut -d' ' -f3 | sed 's#/usr/lib/##g' | xargs -I % cp --parents "%" /tmp/usr/lib/
11-
12-
FROM gcr.io/distroless/cc-debian12 AS runner
1+
FROM cgr.dev/chainguard/php:latest
132

143
ARG COMMIT=(local)
154
ENV COMMIT=$COMMIT
165
ARG LASTMOD=(local)
176
ENV LASTMOD=$LASTMOD
187

19-
ENV PORT=5000
20-
21-
COPY --from=php /bin/sh /bin/
22-
COPY --from=php /tmp/lib/ /lib/
23-
COPY --from=php /tmp/usr/lib/ /usr/lib/
24-
COPY --from=php /usr/local/lib/libphp.* /usr/local/lib/
25-
COPY --from=php /usr/local/bin/docker-php-* /usr/local/bin/php /usr/local/bin/
26-
COPY www /var/www
27-
28-
#CMD [ "/usr/local/bin/php", "-S", "0.0.0.0:$PORT", "-t", "/var/www" ]
29-
CMD exec /usr/local/bin/php -S 0.0.0.0:$PORT -t /var/www
8+
USER php
9+
COPY www /app/www
10+
COPY bin/start.php /app/bin/start.php
11+
ENV PORT=6000
12+
ENV LISTEN=0.0.0.0:$PORT
13+
EXPOSE 6000
14+
ENTRYPOINT [ "php", "/app/bin/start.php"]

bin/start.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env php
2+
<?php
3+
#
4+
# run php as a server. Needed since we cannot specify the -S parameter with ENV inside the Dockerfile
5+
#
6+
$host = '0.0.0.0';
7+
$port = getenv('PORT') ?: '5000';
8+
$docroot = __DIR__ . '/../www';
9+
$command = ['php', '-S', "$host:$port", '-t', $docroot];
10+
11+
$mac_php = sprintf("/usr/local/Cellar/php/%s/bin/php", phpversion());
12+
13+
if (is_executable("/usr/bin/php"))
14+
{
15+
$command[0] = "/usr/bin/php";
16+
}
17+
else if (is_executable("/usr/local/bin/php"))
18+
{
19+
$command[0] = "/usr/local/bin/php";
20+
}
21+
else if (is_executable($mac_php))
22+
{
23+
$command[0] = $mac_php;
24+
}
25+
26+
printf("PHP version %s\n", phpversion());
27+
28+
$descriptorspec = [
29+
0=>STDIN,
30+
1=>STDOUT,
31+
2=>STDERR
32+
];
33+
$process = proc_open($command, $descriptorspec, $pipes);
34+
printf("INFO: PHP server started on http://%s:%s (%s)\n", $host, $port, $process);
35+
36+
//this will wait for the subprocess to finish
37+
proc_close($process);
38+
printf("INFO: PHP server exiting\n");
39+
40+
?>

0 commit comments

Comments
 (0)