Skip to content
Snippets Groups Projects
Commit 12880493 authored by florimondmanca's avatar florimondmanca
Browse files

add volume to persist data

parent 8e687a26
No related branches found
No related tags found
1 merge request!1Dockerize app and update TravisCI file
from python:3.6
EXPOSE 8000
ENV PYTHONUNBUFFERED=0
ADD . /oser-backend
WORKDIR /oser-backend/oser_backend
# Debug only
RUN ls
RUN echo "Content of oser-backend/ directory:"; ls ..
RUN echo "Content of oser_backend/ directory:"; ls
# Install dependencies
RUN pip3 install -r ../requirements.txt
RUN pip3 install gunicorn
# Collect static files
RUN python3 manage.py collectstatic --noinput
# Setup database
RUN python3 manage.py makemigrations
RUN python3 manage.py migrate
RUN python3 manage.py initadmin
CMD sh ../start.sh
......@@ -8,6 +8,8 @@ services:
container_name: django_01
expose:
- "8000" # port where the Django app runs
volumes:
- data:/oser-backend
restart: on-failure
# Nginx server
......@@ -23,3 +25,7 @@ services:
depends_on:
- gunicorn
restart: on-failure
# create a volume to enable persisting data
volumes:
data:
# Allows to write http://gunicorn to point to the Gunicorn server (see below)
upstream gunicorn {
ip_hash;
server gunicorn:8000;
}
server {
server_name web;
listen 8000;
# Log files locations
access_log /var/log/nginx/guni-access.log;
error_log /var/log/nginx/guni-error.log info;
location /static/ {
# Serve static files collected by Django's collectstatic command
# which are located in the /static/ folder
# Serve static files collected by Django's collectstatic command,
# located in the static folder.
autoindex on;
alias /static/;
}
location /media/ {
# Serve user uploaded media, uploaded to the media folder.
autoindex on;
alias /media/;
}
location / {
# Pass requests to the Gunicorn server running the Django app
proxy_pass http://gunicorn;
proxy_pass http://gunicorn:8000;
# Send full host in header (default is service name, i.e. gunicorn).
# Ensures that absolute URLs on Django app are accessible (e.g. in
# discoverable API).
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
#!/usr/bin/env bash
# Collect static files
python manage.py collectstatic
# Initialize database
python manage.py makemigrations
python manage.py migrate
# Initialize admin users
python manage.py initadmin
# Run server
exec gunicorn oser_backend.wsgi:application \
--bind 0.0.0.0:8000 \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment