From 0e139f6b4b1891933e9690d848dfbf179c93c5fe Mon Sep 17 00:00:00 2001 From: Jody Zhou Date: Mon, 18 Jul 2022 14:54:23 -0400 Subject: [PATCH 1/6] created prod, dev, and int environment for django backend --- Dockerfile | 1 - Dockerfile.int | 11 ++ Dockerfile.prod | 11 ++ app/view.py | 2 +- docker-compose.yml | 6 +- manage.py | 2 +- requirements.txt | 2 +- uwpath_backend/asgi.py | 2 +- uwpath_backend/base_settings.py | 11 ++ uwpath_backend/{settings.py => dev.py} | 2 +- uwpath_backend/int.py | 181 ++++++++++++++++++++++++ uwpath_backend/prod.py | 182 +++++++++++++++++++++++++ uwpath_backend/production.py | 182 +++++++++++++++++++++++++ uwpath_backend/wsgi.py | 2 +- 14 files changed, 588 insertions(+), 9 deletions(-) create mode 100644 Dockerfile.int create mode 100644 Dockerfile.prod create mode 100644 uwpath_backend/base_settings.py rename uwpath_backend/{settings.py => dev.py} (98%) create mode 100644 uwpath_backend/int.py create mode 100644 uwpath_backend/prod.py create mode 100644 uwpath_backend/production.py diff --git a/Dockerfile b/Dockerfile index 0b5777b..a0f6d5c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ FROM python:3.7 ENV PYTHONUNBUFFERED 1 -ENV DJANGO_SETTINGS_MODULE uwpath_backend.settings RUN mkdir /code WORKDIR /code COPY requirements.txt /code/ diff --git a/Dockerfile.int b/Dockerfile.int new file mode 100644 index 0000000..293d678 --- /dev/null +++ b/Dockerfile.int @@ -0,0 +1,11 @@ +FROM python:3.7 +ENV PYTHONUNBUFFERED 1 +ENV DJANGO_SETTINGS_MODULE uwpath_backend.int +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 +EXPOSE 8000 \ No newline at end of file diff --git a/Dockerfile.prod b/Dockerfile.prod new file mode 100644 index 0000000..3064ff2 --- /dev/null +++ b/Dockerfile.prod @@ -0,0 +1,11 @@ +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 psycopg2-binary==2.8.6 +RUN pip install -r requirements.txt +COPY . /code/ +ENV PATH /code/:$PATH +EXPOSE 8000 \ No newline at end of file diff --git a/app/view.py b/app/view.py index 9112f0c..70abc34 100644 --- a/app/view.py +++ b/app/view.py @@ -10,7 +10,7 @@ from app.serializer import AppSerializer from app.views.communication_view import Communications_List from app.views.requirement_view import Requirements_List -from uwpath_backend import settings +from uwpath_backend.base_settings import settings from django.db.models import Q from django.core import serializers diff --git a/docker-compose.yml b/docker-compose.yml index 3a7db7d..1048b97 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,8 +4,8 @@ services: web: 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:8000 " volumes: - .:/code @@ -15,6 +15,8 @@ services: - dataparsing_default environment: - DB_HOST=db + - SECRET_KEY=7ldnlu_gz*&vx&=4)q3#74ih@nzx*owgeu^=*katjqpbb-s1sk + - DJANGO_ENV=prod networks: dataparsing_default: external: true \ No newline at end of file diff --git a/manage.py b/manage.py index 177465b..be397b0 100644 --- a/manage.py +++ b/manage.py @@ -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: diff --git a/requirements.txt b/requirements.txt index 8f748bc..b4d3a65 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,4 @@ djangorestframework==3.11.0 djangorestframework-jsonapi==3.0.0 django-cors-headers==3.3.0 postgres==3.0.0 -gunicorn==20.0.4 +gunicorn==20.0.4 \ No newline at end of file diff --git a/uwpath_backend/asgi.py b/uwpath_backend/asgi.py index d3aaa97..35a5018 100644 --- a/uwpath_backend/asgi.py +++ b/uwpath_backend/asgi.py @@ -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() diff --git a/uwpath_backend/base_settings.py b/uwpath_backend/base_settings.py new file mode 100644 index 0000000..86ee398 --- /dev/null +++ b/uwpath_backend/base_settings.py @@ -0,0 +1,11 @@ +import os + + +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 \ No newline at end of file diff --git a/uwpath_backend/settings.py b/uwpath_backend/dev.py similarity index 98% rename from uwpath_backend/settings.py rename to uwpath_backend/dev.py index 03e8878..40f2b09 100644 --- a/uwpath_backend/settings.py +++ b/uwpath_backend/dev.py @@ -21,7 +21,7 @@ # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '7ldnlu_gz*&vx&=4)q3#74ih@nzx*owgeu^=*katjqpbb-s1sk' +SECRET_KEY = os.getenv("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True diff --git a/uwpath_backend/int.py b/uwpath_backend/int.py new file mode 100644 index 0000000..a4ea979 --- /dev/null +++ b/uwpath_backend/int.py @@ -0,0 +1,181 @@ +""" +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', '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.postgresql', + 'NAME': 'postgres' if os.getenv("DB_NAME") is None else os.getenv("DB_NAME"), + 'USER': 'postgres' if os.getenv("DB_USER") is None else os.getenv("DB_USER"), + 'PASSWORD': '1234' if os.getenv("DB_PASS") is None else os.getenv("DB_PASS"), + 'HOST': 'db' if os.getenv("DB_HOST") is None else os.getenv("DB_HOST"), + 'PORT': '5432' if os.getenv("DB_PORT") is None else 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', +] diff --git a/uwpath_backend/prod.py b/uwpath_backend/prod.py new file mode 100644 index 0000000..f147225 --- /dev/null +++ b/uwpath_backend/prod.py @@ -0,0 +1,182 @@ +""" +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', '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.postgresql', + 'NAME': 'postgres' if os.getenv("DB_NAME") is None else os.getenv("DB_NAME"), + 'USER': 'postgres' if os.getenv("DB_USER") is None else os.getenv("DB_USER"), + 'PASSWORD': '1234' if os.getenv("DB_PASS") is None else os.getenv("DB_PASS"), + 'HOST': 'db' if os.getenv("DB_HOST") is None else os.getenv("DB_HOST"), + 'PORT': '5432' if os.getenv("DB_PORT") is None else 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', +] diff --git a/uwpath_backend/production.py b/uwpath_backend/production.py new file mode 100644 index 0000000..f147225 --- /dev/null +++ b/uwpath_backend/production.py @@ -0,0 +1,182 @@ +""" +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', '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.postgresql', + 'NAME': 'postgres' if os.getenv("DB_NAME") is None else os.getenv("DB_NAME"), + 'USER': 'postgres' if os.getenv("DB_USER") is None else os.getenv("DB_USER"), + 'PASSWORD': '1234' if os.getenv("DB_PASS") is None else os.getenv("DB_PASS"), + 'HOST': 'db' if os.getenv("DB_HOST") is None else os.getenv("DB_HOST"), + 'PORT': '5432' if os.getenv("DB_PORT") is None else 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', +] diff --git a/uwpath_backend/wsgi.py b/uwpath_backend/wsgi.py index 4c31f8e..5fce3b9 100644 --- a/uwpath_backend/wsgi.py +++ b/uwpath_backend/wsgi.py @@ -11,6 +11,6 @@ from django.core.wsgi import get_wsgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'uwpath_backend.settings') +#os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'uwpath_backend.production') application = get_wsgi_application() From 2b5dcc7275a296370b52b95a0189aaacaf4a3205 Mon Sep 17 00:00:00 2001 From: Jody Zhou Date: Mon, 18 Jul 2022 23:37:25 -0400 Subject: [PATCH 2/6] modifies settings --- app/view.py | 2 +- uwpath_backend/base_settings.py | 11 --- uwpath_backend/settings.py | 155 ++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 12 deletions(-) delete mode 100644 uwpath_backend/base_settings.py create mode 100644 uwpath_backend/settings.py diff --git a/app/view.py b/app/view.py index 70abc34..9112f0c 100644 --- a/app/view.py +++ b/app/view.py @@ -10,7 +10,7 @@ from app.serializer import AppSerializer from app.views.communication_view import Communications_List from app.views.requirement_view import Requirements_List -from uwpath_backend.base_settings import settings +from uwpath_backend import settings from django.db.models import Q from django.core import serializers diff --git a/uwpath_backend/base_settings.py b/uwpath_backend/base_settings.py deleted file mode 100644 index 86ee398..0000000 --- a/uwpath_backend/base_settings.py +++ /dev/null @@ -1,11 +0,0 @@ -import os - - -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 \ No newline at end of file diff --git a/uwpath_backend/settings.py b/uwpath_backend/settings.py new file mode 100644 index 0000000..8af6943 --- /dev/null +++ b/uwpath_backend/settings.py @@ -0,0 +1,155 @@ +""" +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__))) + + +# 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") + + +ALLOWED_HOSTS = ['0.0.0.0', '127.0.0.1', 'localhost', 'backend'] + + +# 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.postgresql', + 'NAME': 'postgres' if os.getenv("DB_NAME") is None else os.getenv("DB_NAME"), + 'USER': 'postgres' if os.getenv("DB_USER") is None else os.getenv("DB_USER"), + 'PASSWORD': '1234' if os.getenv("DB_PASS") is None else os.getenv("DB_PASS"), + 'HOST': '127.0.0.1' if os.getenv("DB_HOST") is None else os.getenv("DB_HOST"), + 'PORT': '5432' if os.getenv("DB_PORT") is None else 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/', +] + +# 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', +] \ No newline at end of file From f3100701db38ea2bd91e3103e91bb38b1ff5a33f Mon Sep 17 00:00:00 2001 From: Jody Zhou Date: Wed, 27 Jul 2022 00:48:31 -0400 Subject: [PATCH 3/6] modified docker file --- Dockerfile | 1 + uwpath_backend/int.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a0f6d5c..c5ec7b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ FROM python:3.7 ENV PYTHONUNBUFFERED 1 +ENV DJANGO_SETTINGS_MODULE uwpath_backend.dev RUN mkdir /code WORKDIR /code COPY requirements.txt /code/ diff --git a/uwpath_backend/int.py b/uwpath_backend/int.py index a4ea979..dfb82c0 100644 --- a/uwpath_backend/int.py +++ b/uwpath_backend/int.py @@ -43,7 +43,7 @@ # 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', 'uwpath.com'] +ALLOWED_HOSTS = ['0.0.0.0', '127.0.0.1', 'localhost', 'backend', 'parallel.uwpath.com'] # Application definition From eaa603d7e2ac4bcfa0475dcd42193d7ffc7afb7e Mon Sep 17 00:00:00 2001 From: Jody Zhou Date: Wed, 27 Jul 2022 10:29:06 -0400 Subject: [PATCH 4/6] added cors whitelist --- uwpath_backend/int.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/uwpath_backend/int.py b/uwpath_backend/int.py index dfb82c0..a5c82ed 100644 --- a/uwpath_backend/int.py +++ b/uwpath_backend/int.py @@ -178,4 +178,6 @@ 'http://localhost:8080', 'http://127.0.0.1:8000', 'http://0.0.0.0:8000', + 'http://129.153.61.57', + 'http://parallel.uwpath.com', ] From fa565b3024a08586038156098a929d00e0f0cad4 Mon Sep 17 00:00:00 2001 From: Jody Zhou <56443135+JodyZ0203@users.noreply.github.com> Date: Sat, 17 Sep 2022 14:40:55 -0400 Subject: [PATCH 5/6] Changes to docker file and removed duplicate files --- Dockerfile | 1 - Dockerfile.int | 3 +-- Dockerfile.prod | 3 +-- docker-compose.yml | 2 +- requirements.txt | 1 + uwpath_backend/dev.py | 12 ++++++------ uwpath_backend/int.py | 12 ++++++------ uwpath_backend/prod.py | 12 ++++++------ 8 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index 086414c..6577eb2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Dockerfile.int b/Dockerfile.int index 293d678..0034aca 100644 --- a/Dockerfile.int +++ b/Dockerfile.int @@ -4,8 +4,7 @@ ENV DJANGO_SETTINGS_MODULE uwpath_backend.int 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 -EXPOSE 8000 \ No newline at end of file +EXPOSE $PORT \ No newline at end of file diff --git a/Dockerfile.prod b/Dockerfile.prod index 3064ff2..a140571 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -4,8 +4,7 @@ ENV DJANGO_SETTINGS_MODULE uwpath_backend.prod 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 -EXPOSE 8000 \ No newline at end of file +EXPOSE $PORT \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 5399db4..37a0c49 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: build: . command: bash -c " python manage.py migrate && - gunicorn uwpath_backend.wsgi --bind 0.0.0.0:8000 + gunicorn uwpath_backend.wsgi --bind 0.0.0.0:$PORT " # volumes: # - ./Wallet_uwpathparallel:/code/Wallet_uwpathparallel diff --git a/requirements.txt b/requirements.txt index deb988e..427e070 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file diff --git a/uwpath_backend/dev.py b/uwpath_backend/dev.py index 40f2b09..beae33a 100644 --- a/uwpath_backend/dev.py +++ b/uwpath_backend/dev.py @@ -80,12 +80,12 @@ DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'postgres' if os.getenv("DB_NAME") is None else os.getenv("DB_NAME"), - 'USER': 'postgres' if os.getenv("DB_USER") is None else os.getenv("DB_USER"), - 'PASSWORD': '1234' if os.getenv("DB_PASS") is None else os.getenv("DB_PASS"), - 'HOST': 'db' if os.getenv("DB_HOST") is None else os.getenv("DB_HOST"), - 'PORT': '5432' if os.getenv("DB_PORT") is None else os.getenv("DB_PORT"), + '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") } } diff --git a/uwpath_backend/int.py b/uwpath_backend/int.py index a5c82ed..8ea885c 100644 --- a/uwpath_backend/int.py +++ b/uwpath_backend/int.py @@ -97,12 +97,12 @@ DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'postgres' if os.getenv("DB_NAME") is None else os.getenv("DB_NAME"), - 'USER': 'postgres' if os.getenv("DB_USER") is None else os.getenv("DB_USER"), - 'PASSWORD': '1234' if os.getenv("DB_PASS") is None else os.getenv("DB_PASS"), - 'HOST': 'db' if os.getenv("DB_HOST") is None else os.getenv("DB_HOST"), - 'PORT': '5432' if os.getenv("DB_PORT") is None else os.getenv("DB_PORT"), + '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") } } diff --git a/uwpath_backend/prod.py b/uwpath_backend/prod.py index f147225..06b8386 100644 --- a/uwpath_backend/prod.py +++ b/uwpath_backend/prod.py @@ -98,12 +98,12 @@ DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'postgres' if os.getenv("DB_NAME") is None else os.getenv("DB_NAME"), - 'USER': 'postgres' if os.getenv("DB_USER") is None else os.getenv("DB_USER"), - 'PASSWORD': '1234' if os.getenv("DB_PASS") is None else os.getenv("DB_PASS"), - 'HOST': 'db' if os.getenv("DB_HOST") is None else os.getenv("DB_HOST"), - 'PORT': '5432' if os.getenv("DB_PORT") is None else os.getenv("DB_PORT"), + '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") } } From db4699b52913a91ce76218518759ab8a907208fd Mon Sep 17 00:00:00 2001 From: Jody Zhou <56443135+JodyZ0203@users.noreply.github.com> Date: Sat, 17 Sep 2022 14:46:46 -0400 Subject: [PATCH 6/6] modified int to dev and dev to local to follow the naming changes. --- Dockerfile | 2 +- Dockerfile.int => Dockerfile.dev | 2 +- uwpath_backend/dev.py | 27 +++++++++++++++++++++++++-- uwpath_backend/{int.py => local.py} | 27 ++------------------------- 4 files changed, 29 insertions(+), 29 deletions(-) rename Dockerfile.int => Dockerfile.dev (79%) rename uwpath_backend/{int.py => local.py} (89%) diff --git a/Dockerfile b/Dockerfile index 6577eb2..7dd746c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM python:3.7 ENV PYTHONUNBUFFERED 1 -ENV DJANGO_SETTINGS_MODULE uwpath_backend.dev +ENV DJANGO_SETTINGS_MODULE uwpath_backend.local WORKDIR /opt/oracle RUN apt-get update && \ apt-get install -y libaio1 unzip wget diff --git a/Dockerfile.int b/Dockerfile.dev similarity index 79% rename from Dockerfile.int rename to Dockerfile.dev index 0034aca..a2222d0 100644 --- a/Dockerfile.int +++ b/Dockerfile.dev @@ -1,6 +1,6 @@ FROM python:3.7 ENV PYTHONUNBUFFERED 1 -ENV DJANGO_SETTINGS_MODULE uwpath_backend.int +ENV DJANGO_SETTINGS_MODULE uwpath_backend.dev RUN mkdir /code WORKDIR /code COPY requirements.txt /code/ diff --git a/uwpath_backend/dev.py b/uwpath_backend/dev.py index beae33a..8ea885c 100644 --- a/uwpath_backend/dev.py +++ b/uwpath_backend/dev.py @@ -13,10 +13,27 @@ 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/ @@ -24,9 +41,9 @@ SECRET_KEY = os.getenv("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False -ALLOWED_HOSTS = ['0.0.0.0', '127.0.0.1', 'localhost', 'backend'] +ALLOWED_HOSTS = ['0.0.0.0', '127.0.0.1', 'localhost', 'backend', 'parallel.uwpath.com'] # Application definition @@ -128,10 +145,14 @@ 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 @@ -157,4 +178,6 @@ 'http://localhost:8080', 'http://127.0.0.1:8000', 'http://0.0.0.0:8000', + 'http://129.153.61.57', + 'http://parallel.uwpath.com', ] diff --git a/uwpath_backend/int.py b/uwpath_backend/local.py similarity index 89% rename from uwpath_backend/int.py rename to uwpath_backend/local.py index 8ea885c..beae33a 100644 --- a/uwpath_backend/int.py +++ b/uwpath_backend/local.py @@ -13,27 +13,10 @@ 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/ @@ -41,9 +24,9 @@ SECRET_KEY = os.getenv("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = True -ALLOWED_HOSTS = ['0.0.0.0', '127.0.0.1', 'localhost', 'backend', 'parallel.uwpath.com'] +ALLOWED_HOSTS = ['0.0.0.0', '127.0.0.1', 'localhost', 'backend'] # Application definition @@ -145,14 +128,10 @@ 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 @@ -178,6 +157,4 @@ 'http://localhost:8080', 'http://127.0.0.1:8000', 'http://0.0.0.0:8000', - 'http://129.153.61.57', - 'http://parallel.uwpath.com', ]