├── webapp ├── django_environments │ ├── __init__.py │ ├── settings │ │ ├── __init__.py │ │ ├── dev.py │ │ └── base.py │ ├── wsgi.py │ └── urls.py ├── requirements │ ├── base.txt │ └── dev.txt ├── manage.py └── Dockerfile ├── base.yml ├── .env └── docker-compose.yml /webapp/django_environments/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /webapp/django_environments/settings/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /webapp/requirements/base.txt: -------------------------------------------------------------------------------- 1 | django==1.9.6 2 | psycopg2==2.6.1 3 | -------------------------------------------------------------------------------- /webapp/requirements/dev.txt: -------------------------------------------------------------------------------- 1 | -r base.txt 2 | 3 | django-debug-toolbar==1.4 4 | django-extensions==1.6.7 5 | -------------------------------------------------------------------------------- /webapp/django_environments/settings/dev.py: -------------------------------------------------------------------------------- 1 | from .base import * 2 | 3 | INSTALLED_APPS += [ 4 | 'django_extensions', 5 | 'debug_toolbar', 6 | ] 7 | 8 | -------------------------------------------------------------------------------- /base.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | 3 | services: 4 | db: 5 | image: postgres:9.5 6 | env_file: .env 7 | volumes: 8 | - db_data:/var/lib/postgresql/data/pgdata 9 | 10 | web: 11 | build: 12 | context: ./webapp 13 | env_file: .env 14 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | POSTGRES_DB=mydb 2 | POSTGRES_USER=example 3 | POSTGRES_PASSWORD=secret 4 | PGDATA=/var/lib/postgresql/data/pgdata 5 | DJANGO_SETTINGS_MODULE=django_environments.settings.dev 6 | DJANGO_SECRET_KEY='_!5ci4u1e+g-th_+)l0)9ep^n-_f+3knt%k_4yywee4^(a5(6^' 7 | DB_HOST=db 8 | DB_PORT=5432 9 | -------------------------------------------------------------------------------- /webapp/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_environments.settings") 7 | 8 | from django.core.management import execute_from_command_line 9 | 10 | execute_from_command_line(sys.argv) 11 | -------------------------------------------------------------------------------- /webapp/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.5 2 | 3 | ARG DJANGO_ENV 4 | 5 | ENV PYTHONUNBUFFERED=1 6 | ENV WEBAPP_DIR=/webapp 7 | 8 | RUN mkdir $WEBAPP_DIR 9 | 10 | WORKDIR $WEBAPP_DIR 11 | 12 | ADD requirements/base.txt $WEBAPP_DIR/ 13 | ADD requirements/$DJANGO_ENV.txt $WEBAPP_DIR/ 14 | 15 | RUN pip install -r $DJANGO_ENV.txt 16 | 17 | ADD . $WEBAPP_DIR/ 18 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | 3 | services: 4 | db: 5 | extends: 6 | file: base.yml 7 | service: db 8 | 9 | web: 10 | extends: 11 | file: base.yml 12 | service: web 13 | build: 14 | args: 15 | - DJANGO_ENV=dev 16 | command: python manage.py runserver 0.0.0.0:8000 17 | volumes: 18 | - ./webapp:/webapp 19 | ports: 20 | - "8000:8000" 21 | depends_on: 22 | - db 23 | 24 | volumes: 25 | db_data: 26 | external: true 27 | -------------------------------------------------------------------------------- /webapp/django_environments/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for django_environments project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_environments.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /webapp/django_environments/urls.py: -------------------------------------------------------------------------------- 1 | """django_environments URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/1.9/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.conf.urls import url, include 14 | 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 15 | """ 16 | from django.conf.urls import url 17 | from django.contrib import admin 18 | 19 | urlpatterns = [ 20 | url(r'^admin/', admin.site.urls), 21 | ] 22 | -------------------------------------------------------------------------------- /webapp/django_environments/settings/base.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for django_environments project. 3 | 4 | Generated by 'django-admin startproject' using Django 1.9.6. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.9/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/1.9/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY') 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | ] 41 | 42 | MIDDLEWARE_CLASSES = [ 43 | 'django.middleware.security.SecurityMiddleware', 44 | 'django.contrib.sessions.middleware.SessionMiddleware', 45 | 'django.middleware.common.CommonMiddleware', 46 | 'django.middleware.csrf.CsrfViewMiddleware', 47 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 48 | 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'django_environments.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'django_environments.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/1.9/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.postgresql', 80 | 'NAME': os.environ.get('POSTGRES_DB'), 81 | 'USER': os.environ.get('POSTGRES_USER'), 82 | 'PASSWORD': os.environ.get('POSTGRES_PASSWORD'), 83 | 'HOST': os.environ.get('DB_HOST'), 84 | 'PORT': os.environ.get('DB_PORT'), 85 | } 86 | } 87 | 88 | 89 | # Password validation 90 | # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators 91 | 92 | AUTH_PASSWORD_VALIDATORS = [ 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 95 | }, 96 | { 97 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 98 | }, 99 | { 100 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 101 | }, 102 | { 103 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 104 | }, 105 | ] 106 | 107 | 108 | # Internationalization 109 | # https://docs.djangoproject.com/en/1.9/topics/i18n/ 110 | 111 | LANGUAGE_CODE = 'en-us' 112 | 113 | TIME_ZONE = 'UTC' 114 | 115 | USE_I18N = True 116 | 117 | USE_L10N = True 118 | 119 | USE_TZ = True 120 | 121 | 122 | # Static files (CSS, JavaScript, Images) 123 | # https://docs.djangoproject.com/en/1.9/howto/static-files/ 124 | 125 | STATIC_URL = '/static/' 126 | --------------------------------------------------------------------------------