From 99b8c7a2b5bf5bd78dd69bba6002c8274c2cb674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 24 Feb 2021 23:21:41 +0100 Subject: [PATCH 1/4] Use official PHP image based on Alpine Linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This swaps the base image so that we can have: * faster builds * smaller images * more secure and up-to-date dependencies Signed-off-by: Luís Cobucci --- Dockerfile | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 43d88e3e..8df970d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM composer:2 AS composer -FROM ubuntu:20.04 +FROM php:8.0-alpine COPY --from=composer /usr/bin/composer /usr/bin/composer @@ -15,21 +15,10 @@ LABEL "maintainer"="https://github.com/laminas/technical-steering-committee/" WORKDIR /app -RUN apt update \ - && apt install -y software-properties-common \ - && add-apt-repository -y ppa:ondrej/php \ - && apt install -y \ - git \ - gnupg \ - libzip-dev \ - zip \ - php8.0-cli \ - php8.0-curl \ - php8.0-mbstring \ - php8.0-readline \ - php8.0-xml \ - php8.0-zip \ - && apt clean +RUN apk add --no-cache git gnupg libzip \ + && apk add --no-cache --virtual .build-deps libzip-dev \ + && docker-php-ext-install zip \ + && apk del .build-deps ADD composer.json /app/composer.json ADD composer.lock /app/composer.lock From cb3306cdbeaa810438fb72343c6652ce40a50097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 24 Feb 2021 23:26:25 +0100 Subject: [PATCH 2/4] Use COPY over ADD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's recommended to use `COPY` instead of `ADD` because it's much simpler and avoids unexpected behaviour - `ADD` can also do things like uncompressing files and remote requests. More info: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#add-or-copy Signed-off-by: Luís Cobucci --- Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8df970d7..36ade346 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,16 +20,15 @@ RUN apk add --no-cache git gnupg libzip \ && docker-php-ext-install zip \ && apk del .build-deps -ADD composer.json /app/composer.json -ADD composer.lock /app/composer.lock +COPY composer.* /app/ RUN COMPOSER_CACHE_DIR=/dev/null composer install --no-dev --no-autoloader # @TODO https://github.com/laminas/automatic-releases/issues/8 we skip `.git` for now, as it isn't available in the build environment # @TODO https://github.com/laminas/automatic-releases/issues/9 we skip `.git` for now, as it isn't available in the build environment #ADD .git /app/.git -ADD bin /app/bin -ADD src /app/src +COPY bin /app/bin/ +COPY src /app/src/ RUN composer install -a --no-dev From 99bb2812ec863c714b52bc7ed9b566fcb0e28787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 24 Feb 2021 23:30:57 +0100 Subject: [PATCH 3/4] Avoid trying to re-install dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We only need to dump the autoloader at this stage, so it's unnecessary to do anything beyond that. Signed-off-by: Luís Cobucci --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 36ade346..2ee97743 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,6 +30,6 @@ RUN COMPOSER_CACHE_DIR=/dev/null composer install --no-dev --no-autoloader COPY bin /app/bin/ COPY src /app/src/ -RUN composer install -a --no-dev +RUN composer dump-autoload -a --no-dev ENTRYPOINT ["/app/bin/console.php"] From 144704b43abeccc53ed60124d42081603e9c2efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 25 Feb 2021 09:41:16 +0100 Subject: [PATCH 4/4] Build image using BuildKit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BuildKit is an optimised builder for docker. Although it isn't enabled by default, it helps to speed up the process even more and it's quite stable at this point. More info: https://docs.docker.com/develop/develop-images/build_enhancements/ Signed-off-by: Luís Cobucci --- .github/workflows/docker-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 477bff2b..2298413c 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -18,4 +18,4 @@ jobs: uses: "actions/checkout@v2" - name: "Docker Build" - run: "docker build ." + run: "DOCKER_BUILDKIT=1 docker build ."