Skip to content

Commit

Permalink
Fast as f***
Browse files Browse the repository at this point in the history
  • Loading branch information
mlabarrere committed May 5, 2021
1 parent 1c3b178 commit edb97d0
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit edb97d0

Please sign in to comment.