Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Issue Nekmo#1: Server project using docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekmo committed Oct 7, 2020
1 parent 5f87f61 commit bd065d5
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
!angular-django/projects
!angular-django/*.json
!django_demo/*.txt
!django_demo/*.py
!django_demo/demo
!django_demo/pokedex
!compose/
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ RUN mkdir -p /app
WORKDIR /app
COPY django_demo/requirements.txt .
RUN pip install -r requirements.txt
COPY compose/gunicorn/entrypoint.sh /
RUN chmod +x "/entrypoint.sh"
COPY django_demo ./

ENTRYPOINT ["/usr/local/bin/gunicorn"]
CMD ["-b", "0.0.0.0:8000", "demo.wsgi:application"]
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/usr/local/bin/gunicorn", "-b", "0.0.0.0:8000", "demo.wsgi:application"]


FROM node:14.12 as angular-build
Expand Down
11 changes: 11 additions & 0 deletions compose/gunicorn/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -o errexit
set -o pipefail
set -o nounset

python manage.py collectstatic --no-input
python manage.py migrate --no-input
python manage.py import_pokedex

exec "$@"
47 changes: 47 additions & 0 deletions conf/nginx/conf.d/demo.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
upstream demo-upstream {
ip_hash;
server gunicorn:8000;
}


server {
listen 80;

set_real_ip_from 172.16.0.0/12;
real_ip_header X-Forwarded-For;
real_ip_recursive on;

proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $http_x_real_ip;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_connect_timeout 300s;
proxy_read_timeout 300s;

location @backend {
proxy_pass http://demo-upstream;
}


location ^~ /static/ {
alias /static/;
}

location /media/ {
internal;
alias /media/; # note the trailing slash
}

location /api/ {
try_files $uri $uri/ @backend;
}

location / {
root /angular;
try_files $uri $uri/ /index.html;
}
}
7 changes: 4 additions & 3 deletions django_demo/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

DATA_DIRECTORY = os.environ.get('DATA_DIRECTORY', str(BASE_DIR))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
Expand Down Expand Up @@ -82,7 +82,7 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'NAME': os.path.join(DATA_DIRECTORY, 'db.sqlite3'),
}
}

Expand Down Expand Up @@ -124,3 +124,4 @@
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = '/static/'
3 changes: 3 additions & 0 deletions django_demo/requirements.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Django
django-rest-framework
django-filter
drf-writable-nested
gunicorn
requests
9 changes: 8 additions & 1 deletion django_demo/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
# pip-compile requirements.in
#
asgiref==3.2.10 # via django
certifi==2020.6.20 # via requests
chardet==3.0.4 # via requests
django-filter==2.4.0 # via -r requirements.in
django-rest-framework==0.1.0 # via -r requirements.in
django==3.1.1 # via -r requirements.in, djangorestframework
django==3.1.1 # via -r requirements.in, django-filter, djangorestframework
djangorestframework==3.11.1 # via django-rest-framework
drf-writable-nested==0.6.1 # via -r requirements.in
gunicorn==20.0.4 # via -r requirements.in
idna==2.10 # via requests
pytz==2020.1 # via django
requests==2.24.0 # via -r requirements.in
sqlparse==0.3.1 # via django
urllib3==1.25.10 # via requests

# The following packages are considered to be unsafe in a requirements file:
# setuptools
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ services:
context: .
dockerfile: ./Dockerfile
target: nginx-build
volumes:
- ./conf/nginx/conf.d:/etc/nginx/conf.d:ro
- ./data/nginx/log/:/var/log/nginx/
ports:
- 80:80

angular:
build:
Expand All @@ -25,3 +30,8 @@ services:
context: .
dockerfile: ./Dockerfile
target: gunicorn-build
environment:
DATA_DIRECTORY: /data
volumes:
- ./data/gunicorn/:/data/

0 comments on commit bd065d5

Please sign in to comment.