Skip to content

Commit

Permalink
⚙ Fix 3 Maintainability issues in Dockerfile #5
Browse files Browse the repository at this point in the history
  • Loading branch information
yezz123 committed Aug 1, 2021
1 parent dae6ae8 commit dcfcafe
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions Dockerfile
@@ -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

1 comment on commit dcfcafe

@yezz123
Copy link
Owner Author

@yezz123 yezz123 commented on dcfcafe Aug 1, 2021

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

Please sign in to comment.