Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚙ Fix 3 Maintainability issues in Dockerfile #5
- Loading branch information
Showing
1 changed file
with
25 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
# Pull base image | ||
FROM ubuntu:16.04 | ||
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8 | ||
FROM python:3.7 | ||
|
||
RUN apt-get update && apt-get upgrade -y | ||
# Set environment varibles | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
WORKDIR /app | ||
# Set the working directory for any subsequent | ||
WORKDIR /app/ | ||
|
||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONBUFFERED 1 | ||
# Copy Requirements to app folder | ||
COPY ./requirements.txt /app/requirements.txt | ||
|
||
COPY ./ /app | ||
# install gcc and update environment | ||
RUN apt-get update \ | ||
&& apt-get install gcc -y \ | ||
&& apt-get clean | ||
|
||
RUN apk add --no-cache --virtual .build-deps build-base \ | ||
libressl-dev libffi-dev gcc musl-dev python3-dev \ | ||
libc-dev libxslt-dev libxml2-dev bash \ | ||
postgresql-dev \ | ||
&& pip install --upgrade pip setuptools wheel \ | ||
&& pip install --no-cache-dir -r /app/requirements.txt \ | ||
&& rm -rf /root/.cache/pip | ||
# Run the pip command to install the requirements | ||
RUN pip install -r /app/requirements.txt \ | ||
&& rm -rf /root/.cache/pip | ||
|
||
# Copy files or folders from source to the dest path in the image's filesystem. | ||
COPY . /app/ | ||
|
||
# Set the environment variable key to the value value. | ||
ENV ACCESS_LOG=${ACCESS_LOG:-/proc/1/fd/1} | ||
ENV ERROR_LOG=${ERROR_LOG:-/proc/1/fd/2} | ||
|
||
# Configures the container to be run as an executable. | ||
ENTRYPOINT /usr/local/bin/gunicorn \ | ||
-b 0.0.0.0:80 \ | ||
-w 4 \ | ||
-k uvicorn.workers.UvicornWorker main:app \ | ||
--chdir /app \ | ||
--access-logfile "$ACCESS_LOG" \ | ||
--error-logfile "$ERROR_LOG" | ||
--error-logfile "$ERROR_LOG" | ||
|
||
# Define the network ports that this container will listen on at runtime. | ||
EXPOSE 8000 |
dcfcafe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CodeFactor found multiple issues last seen at dcfcafe:
Avoid use of cache directory with pip. Use
pip install --no-cache-dir <package>
Avoid additional packages by specifying
--no-install-recommends
Delete the apt-get lists after installing something