From 64daa06e090be9f570d4a4a5b280793ed4720373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 26 Dec 2020 09:00:08 +0200 Subject: [PATCH 1/3] Add support for pre-built docker image (update only app layer) --- Dockerfile | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index ede5fcbcb..a0b906338 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,8 +3,10 @@ # also modifying source, would not need to rebuild extensions layer. # Author: Elan Ruusamäe -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 @@ -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 \ @@ -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 @@ -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 @@ -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/ @@ -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 @@ -112,8 +119,13 @@ WORKDIR $APPDIR EXPOSE 80 CMD ["sh", "-c", "nginx && exec php-fpm"] VOLUME "/run/nginx" - -COPY --from=stage-ext-mongodb /build / COPY --from=build --chown=www-data /cache ./cache/ + +# runtime image from last release +FROM xhgui/xhgui:latest AS runtime-prebuilt + +# build final image +FROM runtime-$BUILD_SOURCE AS runtime + COPY --from=build /vendor ./vendor/ COPY --from=build /app ./ From 8d35be3c6b435183c7a6550ceb386f26a58c3cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 26 Dec 2020 09:13:06 +0200 Subject: [PATCH 2/3] Use BUILD_SOURCE=prebuilt to use layers from previous release The --cache-from seems to have no effect in GitHub actions, so switch to manual layers specification. --- .github/workflows/docker.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 06d47b756..7bdc20d90 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -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 From a7daebcc6e26ffb02ee92fd8448ea159aa20edb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 26 Dec 2020 09:18:20 +0200 Subject: [PATCH 3/3] Prune previous app when using prebuilt image This ensures that files removed on a branch do have effect --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a0b906338..c3c6b16e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -119,13 +119,14 @@ WORKDIR $APPDIR EXPOSE 80 CMD ["sh", "-c", "nginx && exec php-fpm"] VOLUME "/run/nginx" -COPY --from=build --chown=www-data /cache ./cache/ # 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 ./