From 2969d637c584f2d7c212beecf73dc866c85fe150 Mon Sep 17 00:00:00 2001 From: rlacko <rlacko@sch.bme.hu> Date: Thu, 6 Feb 2020 12:37:33 +0100 Subject: [PATCH] better Dockerfile.prod --- Dockerfile.prod | 66 +++++++++---------------------------------------- 1 file changed, 11 insertions(+), 55 deletions(-) diff --git a/Dockerfile.prod b/Dockerfile.prod index 75831f0..4c6147f 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -1,71 +1,27 @@ -########### -# BUILDER # -########### - -# pull official base image -FROM python:3.8.1 as builder - -# set work directory -WORKDIR /usr/src/app +FROM python:3.8.1 -# set environment variables ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 +ENV TZ Europe/Budapest -# install dependencies -RUN apt-get -y update -RUN apt-get install -y python python-pip python-dev python-django-extensions postgresql-client netcat -RUN apt-get -y update && apt-get -y autoremove - -# lint -RUN pip install --upgrade pip -RUN pip install flake8 -COPY ./src /usr/src/app/ -#RUN flake8 --max-line-length=125 --exclude=kszkepzes,migrations . - -# install dependencies -COPY ./requirements/production.txt /usr/src/app/requirements.txt -RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt - -######### -# FINAL # -######### - -# pull official base image -FROM python:3.8.1 - -# create directory for the app user -RUN mkdir -p /home/app - -# create the app user -RUN groupadd app && useradd -g app app - -# create the appropriate directories -ENV HOME=/home/app -ENV APP_HOME=/home/app/kszkepzes-backend -RUN mkdir $APP_HOME -RUN mkdir $APP_HOME/staticfiles -RUN mkdir $APP_HOME/mediafiles +ENV HOME /home/app +ENV APP_HOME /home/app/kszkepzes-backend +RUN groupadd app && useradd -g app app && \ +mkdir -p /home/app && mkdir $APP_HOME && \ +mkdir $APP_HOME/staticfiles && mkdir $APP_HOME/mediafiles WORKDIR $APP_HOME -# install dependencies -RUN apt-get -y update && apt-get install netcat -y -COPY --from=builder /usr/src/app/wheels /wheels -COPY --from=builder /usr/src/app/requirements.txt . -RUN pip install --upgrade pip -RUN pip install --no-cache /wheels/* +COPY ./requirements/production.txt requirements.txt -# copy entrypoint-prod.sh -COPY ./src/entrypoint.prod.sh $APP_HOME +RUN apt-get -y update && apt-get install -y python python-pip python-dev python-django-extensions postgresql-client netcat +RUN pip install -r requirements.txt -# copy project COPY ./src $APP_HOME -# chown all the files to the app user RUN chown -R app:app $APP_HOME -# change to the app user USER app EXPOSE 8000 + CMD ["gunicorn" "kszkepzes.wsgi:application" "--bind" "0.0.0.0:8000"] -- GitLab