Skip to content
Snippets Groups Projects
Commit e6852d6c authored by Rafael László's avatar Rafael László :speech_balloon:
Browse files

production Dockerfile and script

parent 8dd38463
No related branches found
No related tags found
1 merge request!2Dev
# pull official base image
FROM python:3.8.0
FROM python:3.8.1
# set work directory
WORKDIR /usr/src/app
......
###########
# BUILDER #
###########
# pull official base image
FROM python:3.8.1 as builder
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# 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
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 entrypoint-prod.sh
COPY ./src/entrypoint.prod.sh $APP_HOME
# 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
# run entrypoint.sh
ENTRYPOINT ["/home/app/kszkepzes-backend/entrypoint.prod.sh"]
\ No newline at end of file
#!/bin/sh
if [ "$DJANGO_SETTINGS_MODULE" = "kszkepzes.settings.production" ]
then
echo "Waiting for postgres..."
while ! nc -z $DB_HOST $DB_PORT; do
sleep 0.1
done
echo "PostgreSQL started"
fi
exec "$@"
\ No newline at end of file
#!/bin/sh
if [ "$DATABASE" = "postgres" ]
if [ "$DJANGO_SETTINGS_MODULE" = "kszkepzes.settings.production" ]
then
echo "Waiting for postgres..."
......
......@@ -6,7 +6,7 @@ ALLOWED_HOSTS = ['*']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'ENGINE': os.getenv('DB_ENGINE', 'django.db.backends.postgresql'),
'NAME': os.getenv('DB_NAME', 'kszkepzes'),
'USER': os.getenv('DB_USER'),
'PASSWORD': os.getenv('DB_PASSWORD'),
......
......@@ -3,7 +3,7 @@ import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kszkepzes.settings.production")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kszkepzes.settings.local")
try:
from django.core.management import execute_from_command_line
except ImportError:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment