From ca1b17863c28ed46fecdf9156a67f2938ca25279 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 21 Mar 2020 08:56:48 +0100 Subject: [PATCH] Split Dockerfile into multiple stages, making the build be independent and then the released image just copy files from it --- Dockerfile | 25 ++++++++++++++----------- docker/README.md | 1 - 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3a65fd8e..96733933 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ -FROM php:7.4.2-alpine3.11 -LABEL maintainer="Alejandro Celaya " +FROM php:7.4.2-alpine3.11 as base ARG SHLINK_VERSION=2.0.5 ENV SHLINK_VERSION ${SHLINK_VERSION} @@ -36,17 +35,21 @@ RUN wget https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8 rm msodbcsql17_17.5.1.1-1_amd64.apk && \ rm mssql-tools_17.5.1.1-1_amd64.apk -# Install shlink -COPY . . -COPY --from=composer:1.9.3 /usr/bin/composer ./composer.phar -RUN rm -rf ./docker && \ - php composer.phar install --no-dev --optimize-autoloader --prefer-dist --no-progress --no-interaction && \ - php composer.phar clear-cache && \ - rm composer.* -# Add shlink to the path to ease running it after container is created +# Install shlink +FROM base as builder +COPY . . +COPY --from=composer:1.10.1 /usr/bin/composer ./composer.phar +RUN php composer.phar install --no-dev --optimize-autoloader --prefer-dist --no-progress --no-interaction && \ + sed -i "s/%SHLINK_VERSION%/${SHLINK_VERSION}/g" config/autoload/app_options.global.php + + +# Prepare final image +FROM base +LABEL maintainer="Alejandro Celaya " + +COPY --from=builder /etc/shlink . RUN ln -s /etc/shlink/bin/cli /usr/local/bin/shlink -RUN sed -i "s/%SHLINK_VERSION%/${SHLINK_VERSION}/g" config/autoload/app_options.global.php # Expose swoole port EXPOSE 8080 diff --git a/docker/README.md b/docker/README.md index 699c1c75..f8e596ce 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,6 +1,5 @@ # Shlink Docker image -[![Docker build status](https://img.shields.io/docker/build/shlinkio/shlink.svg?style=flat-square)](https://hub.docker.com/r/shlinkio/shlink/) [![Docker pulls](https://img.shields.io/docker/pulls/shlinkio/shlink.svg?style=flat-square)](https://hub.docker.com/r/shlinkio/shlink/) This image provides an easy way to set up [shlink](https://shlink.io) on a container-based runtime.