From edb97d07bc8a0d0932deb3c7cb0a7a3ea30d3cec Mon Sep 17 00:00:00 2001 From: Mickael Labarrere <35226465+mlabarrere@users.noreply.github.com> Date: Wed, 5 May 2021 11:53:46 +0200 Subject: [PATCH] Fast as f*** --- Dockerfile | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/Dockerfile b/Dockerfile index b32a260..f7e69f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,29 @@ -# Use the official lightweight Python image. -# https://hub.docker.com/_/python +# ---- Base python ---- +FROM python:3.9 AS base +# Create app directory +WORKDIR /app -FROM python:buster +# ---- Dependencies ---- +FROM base AS dependencies +COPY requirements.txt ./ +# install app dependencies +RUN pip install -r requirements.txt -# Allow statements and log messages to immediately appear in the Knative logs -ENV PYTHONUNBUFFERED True +# ---- Copy Files/Build ---- +FROM dependencies AS build +WORKDIR /app +COPY . /app +# Build / Compile if required -# Copy local code to the container image. -ENV APP_HOME /app -WORKDIR $APP_HOME -COPY . ./ +# --- Release with Alpine ---- +FROM python:slim AS release +# Create app directory +WORKDIR /app -# Install apt-utils -#RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends apt-utils -# Upgrade Linux packages -RUN apt-get -y update && apt-get -y dist-upgrade && apt-get -y autoremove && apt-get -y autoclean -# Upgrade pip itself -RUN pip install --upgrade pip -# Upgrade to latests python packages -RUN pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U -# Install dependencies -RUN pip install -r requirements.txt +COPY --from=dependencies /app/requirements.txt ./ +COPY --from=dependencies /root/.cache /root/.cache -# Run the web service on container startup. Here we use the gunicorn -# webserver, with one worker process and 8 threads. -# For environments with multiple CPU cores, increase the number of workers -# to be equal to the cores available. -# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling. -CMD exec gunicorn --bind :$PORT --workers 4 --worker-class uvicorn.workers.UvicornWorker --threads 8 --timeout 0 main:app +# Install app dependencies +RUN pip install -r requirements.txt +COPY --from=build /app/ ./ +CMD exec gunicorn --bind :$PORT --workers 4 --worker-class uvicorn.workers.UvicornWorker --threads 8 --timeout 0 main:app \ No newline at end of file