Skip to content

Commit

Permalink
Merge pull request #407 from perftools/pre-build-docker
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc authored Dec 26, 2020
2 parents 0881f3a + a7daebc commit fdeac1a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:

- name: Docker build
run: |
docker pull xhgui/xhgui:latest
docker build --cache-from=xhgui/xhgui:latest .
docker build --build-arg=BUILD_SOURCE=prebuilt .
# vim:ft=yaml:et:ts=2:sw=2
31 changes: 22 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# also modifying source, would not need to rebuild extensions layer.
# Author: Elan Ruusamäe <glen@pld-linux.org>

FROM alpine:3.12 AS base
# build (build from source), prebuilt (use copy from last release image)
ARG BUILD_SOURCE=build

FROM alpine:3.12 AS base
ENV PHP_INI_DIR /etc/php7

# ext-mongodb: build and stage
Expand All @@ -23,7 +25,7 @@ COPY --from=build-ext-mongodb /usr/lib/php7/modules/mongodb.so .
RUN strip *.so && chmod a+rx *.so

# php-fpm runtime
FROM base AS php
FROM base AS php-build
RUN set -x \
&& apk add --no-cache \
nginx \
Expand All @@ -32,10 +34,11 @@ RUN set -x \
php-fpm \
php-json \
php-pdo \
php-session \
php-pdo_mysql \
php-pdo_pgsql \
php-pdo_sqlite \
php-phar \
php-session \
# Use www-data uid from alpine also present in docker php images
&& adduser -u 82 -D -S -G www-data www-data \
# Tweak php-fpm config
Expand Down Expand Up @@ -63,6 +66,10 @@ RUN set -x \
&& ln -s /dev/stderr /var/log/nginx/error.log \
&& php -m

FROM xhgui/xhgui:latest AS php-prebuilt
# "php" alias
FROM php-$BUILD_SOURCE AS php

# prepare sources
FROM scratch AS source
WORKDIR /app
Expand All @@ -73,9 +80,7 @@ WORKDIR /app/vendor
# install composer vendor
FROM php AS build
# extra deps for composer
RUN apk add --no-cache \
php-phar \
&& php -m
RUN apk add --no-cache php-phar
WORKDIR /app
ARG COMPOSER_FLAGS="--no-interaction --no-suggest --ansi --no-dev"
COPY --from=composer:1.10 /usr/bin/composer /usr/bin/
Expand Down Expand Up @@ -103,8 +108,10 @@ RUN mv vendor /

RUN install -d /cache -m 700

# build runtime image
FROM php
# runtime image from current build
FROM php AS runtime-build
COPY --from=stage-ext-mongodb /build /

ARG APPDIR=/var/www/xhgui
ARG WEBROOT=$APPDIR/webroot
WORKDIR $APPDIR
Expand All @@ -113,7 +120,13 @@ EXPOSE 80
CMD ["sh", "-c", "nginx && exec php-fpm"]
VOLUME "/run/nginx"

COPY --from=stage-ext-mongodb /build /
# runtime image from last release
FROM xhgui/xhgui:latest AS runtime-prebuilt
RUN rm -rf $(pwd)

# build final image
FROM runtime-$BUILD_SOURCE AS runtime

COPY --from=build --chown=www-data /cache ./cache/
COPY --from=build /vendor ./vendor/
COPY --from=build /app ./

0 comments on commit fdeac1a

Please sign in to comment.