From ae926d74fcc573b5b206814247f6d4425ef22a03 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Fri, 11 Sep 2020 09:36:41 +0000 Subject: [PATCH 1/3] Multi stage Docker build file. --- Dockerfile | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5f8971d..ee57185 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,23 @@ -FROM python:3-alpine +FROM python:3-alpine AS builder WORKDIR /usr/src/app COPY requirements.txt ./ -RUN apk --no-cache add gcc musl-dev libffi-dev openssl-dev libxml2-dev libxslt-dev file llvm-dev make g++ \ - && pip install --no-cache-dir wheel cryptography gunicorn pymysql \ - && pip install --no-cache-dir -r requirements.txt \ - && apk del gcc musl-dev libffi-dev openssl-dev file llvm-dev make g++ +# Build Dependencies +RUN apk --no-cache --virtual build-deps add gcc musl-dev libffi-dev openssl-dev libxml2-dev libxslt-dev file llvm-dev make g++ + +# Python Dependencies +RUN pip install --no-cache-dir --prefix=/install wheel cryptography gunicorn pymysql +RUN pip install --no-cache-dir --prefix=/install -r requirements.txt + +FROM python:3-alpine + +WORKDIR /usr/src/app + +# Runtime Dependencies +RUN apk --no-cache add libxml2 libxslt +COPY --from=builder /install /usr/local COPY . . From a89ff6b51baede982d9522e0c4047972efd50ee0 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Fri, 11 Sep 2020 09:43:49 +0000 Subject: [PATCH 2/3] Remove --virtual --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ee57185..8ff5eb0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /usr/src/app COPY requirements.txt ./ # Build Dependencies -RUN apk --no-cache --virtual build-deps add gcc musl-dev libffi-dev openssl-dev libxml2-dev libxslt-dev file llvm-dev make g++ +RUN apk --no-cache add gcc musl-dev libffi-dev openssl-dev libxml2-dev libxslt-dev file llvm-dev make g++ # Python Dependencies RUN pip install --no-cache-dir --prefix=/install wheel cryptography gunicorn pymysql From 9f551f03a852e556e58fba3bf7ff2a2eafc8764a Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Fri, 11 Sep 2020 12:48:06 +0000 Subject: [PATCH 3/3] Simplify image. --- Dockerfile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8ff5eb0..e7f2d0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,7 @@ -FROM python:3-alpine AS builder +FROM python:3-alpine AS base + +# Image to Build Dependencies +FROM base AS builder WORKDIR /usr/src/app @@ -11,7 +14,8 @@ RUN apk --no-cache add gcc musl-dev libffi-dev openssl-dev libxml2-dev libxslt-d RUN pip install --no-cache-dir --prefix=/install wheel cryptography gunicorn pymysql RUN pip install --no-cache-dir --prefix=/install -r requirements.txt -FROM python:3-alpine +# Runtime Environment Image +FROM base WORKDIR /usr/src/app