Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create backend production server for django #30

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.7

ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE uwpath_backend.settings
ENV DJANGO_SETTINGS_MODULE uwpath_backend.local
WORKDIR /opt/oracle
RUN apt-get update && \
apt-get install -y libaio1 unzip wget
Expand All @@ -15,7 +15,6 @@ RUN wget https://download.oracle.com/otn_software/linux/instantclient/instantcli
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install psycopg2-binary==2.8.6
RUN pip install -r requirements.txt
COPY . /code/
ENV PATH /code/:$PATH
Expand Down
10 changes: 10 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.7
ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE uwpath_backend.dev
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
ENV PATH /code/:$PATH
EXPOSE $PORT
10 changes: 10 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.7
ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE uwpath_backend.prod
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
ENV PATH /code/:$PATH
EXPOSE $PORT
11 changes: 5 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ services:
container_name: uwpath_backend
build: .
command: bash -c "
python manage.py migrate
&& python manage.py runserver 0.0.0.0:8000
python manage.py migrate &&
gunicorn uwpath_backend.wsgi --bind 0.0.0.0:$PORT
"
# volumes:
# - ./Wallet_uwpathparallel:/code/Wallet_uwpathparallel
Expand All @@ -16,11 +16,10 @@ services:
- uwpath_db_network
- uwpath_backend_network
environment:
- DB_HOST=db
- SECRET_KEY=7ldnlu_gz*&vx&=4)q3#74ih@nzx*owgeu^=*katjqpbb-s1sk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok to expose this secret key like this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be okay, we could throw env variable in there.

- DJANGO_ENV=prod
- UWPATH_ENVIRONMENT=docker
# - SECRET_KEY=7ldnlu_gz*&vx&=4)q3#74ih@nzx*owgeu^=*katjqpbb-s1sk
# - DJANGO_SETTINGS_MODULE=uwpath_backend.dev
# - TNS_ADMIN=/code/Wallet_uwpathparallel

networks:
uwpath_db_network:
external: true
Expand Down
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'uwpath_backend.settings')
#os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'uwpath_backend.production')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ django-cors-headers==3.3.0
postgres==3.0.0
gunicorn==20.0.4
cx_Oracle == 8.3.0
psycopg2-binary==2.8.6
2 changes: 1 addition & 1 deletion uwpath_backend/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'uwpath_backend.settings')
#os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'uwpath_backend.settings.__init__')

application = get_asgi_application()

183 changes: 183 additions & 0 deletions uwpath_backend/dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
"""
Django settings for uwpath_backend project.

Generated by 'django-admin startproject' using Django 3.0.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""


import os


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))



# HTTPS Settings
#SESSION_COOKIE_SECURE = True
#CSRF_COOKIE_SECURE = True
#SECURE_SSL_REDIRECT = True

# HSTS Settings
#SECURE_HSTS_SECONDS = 31536000 # 1 year
#SECURE_HSTS_PRELOAD = True
#SECURE_HSTS_INCLUDE_SUBDOMAINS = True


#STATIC_URL = '/static/'
#STATIC_ROOT = '/code/static/'


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['0.0.0.0', '127.0.0.1', 'localhost', 'backend', 'parallel.uwpath.com']


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app.apps.UwpathConfig',
'rest_framework',
'corsheaders'
]

MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'uwpath_backend.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'uwpath_backend.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': os.getenv("ORACLE_DSN"),
'USER': os.getenv("DB_USER"),
'PASSWORD': os.getenv("DB_PASS"),
'HOST': os.getenv("DB_HOST"),
'PORT': os.getenv("DB_PORT")
}
}


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'


STATICFILES_DIRS = [
'app/static/',
]


STATIC_ROOT = os.path.join(BASE_DIR, "static/")

# Note for emails to work please set up env variables. Note: You might need to restart your computer

# For sending emails
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL = os.environ.get('UWPath_Email_Account')
SERVER_EMAIL = os.environ.get('UWPath_Email_Account')
EMAIL_HOST = os.environ.get('UWPath_Host')
EMAIL_PORT = 587
EMAIL_HOST_USER = os.environ.get('UWPath_Email_Account')
EMAIL_HOST_PASSWORD = os.environ.get('UWPath_Email_Password')
EMAIL_USE_TLS = True

REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
)
}

CORS_ORIGIN_ALLOW_ALL=True

CORS_ORIGIN_WHITELIST = [
'http://localhost:8000',
'http://localhost:8080',
'http://127.0.0.1:8000',
'http://0.0.0.0:8000',
'http://129.153.61.57',
'http://parallel.uwpath.com',
]
Loading