From ee9ef12a9e057baf38951ca4c9ac5363cddd693a Mon Sep 17 00:00:00 2001 From: Odin Vatne <odinjv@stud.ntnu.no> Date: Mon, 30 May 2022 18:18:21 -0700 Subject: [PATCH 1/9] Add files for heroku deployment --- Procfile | 1 + requirements.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 Procfile diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..6030f45 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn pas.wsgi \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index c496a00..dc7ea2c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ asgiref==3.4.1 Django==3.2.9 pytz==2021.3 sqlparse==0.4.2 +gunicorn==20.1.0 \ No newline at end of file -- GitLab From 4969f70bd8e1e2f57063d489b19695179a6d7a60 Mon Sep 17 00:00:00 2001 From: Odin Vatne <odinjv@stud.ntnu.no> Date: Mon, 30 May 2022 18:21:49 -0700 Subject: [PATCH 2/9] Fix missing static root declaration --- pas/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pas/settings.py b/pas/settings.py index 97aaee1..7289bad 100644 --- a/pas/settings.py +++ b/pas/settings.py @@ -121,6 +121,7 @@ USE_TZ = True # https://docs.djangoproject.com/en/3.2/howto/static-files/ STATIC_URL = '/static/' +STATIC_ROOT = '/static/' # Default primary key field type # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field -- GitLab From caa426d9e38024d9ff8afaf236da446596d94169 Mon Sep 17 00:00:00 2001 From: Odin Vatne <odinjv@stud.ntnu.no> Date: Mon, 30 May 2022 18:30:28 -0700 Subject: [PATCH 3/9] Static files configuration --- pas/settings.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pas/settings.py b/pas/settings.py index 7289bad..593ab57 100644 --- a/pas/settings.py +++ b/pas/settings.py @@ -20,10 +20,10 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-r0hfpfd#gt30%9tj!8@&%q2t&^m&s-qz7(o(qgj@qait@&25gc' +SECRET_KEY = 'B8ve2kye2D3@Vekezcye$#udghb#TK$hUMwX5vhbV@JBxqdXJ4BoA^%UdddRYswT' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False ALLOWED_HOSTS = [] @@ -86,18 +86,18 @@ DATABASES = { # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators # SECURITY WARNING: enable password validators in production. 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', - # }, + { + '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', + }, ] @@ -120,8 +120,8 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.2/howto/static-files/ +STATIC_ROOT = BASE_DIR / 'static' STATIC_URL = '/static/' -STATIC_ROOT = '/static/' # Default primary key field type # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field -- GitLab From 736ba4a21728146f720608187b48a0bd73984b75 Mon Sep 17 00:00:00 2001 From: Odin Vatne <odinjv@stud.ntnu.no> Date: Mon, 30 May 2022 18:43:51 -0700 Subject: [PATCH 4/9] add windows-compatible procfile --- Procfile.windows | 1 + 1 file changed, 1 insertion(+) create mode 100644 Procfile.windows diff --git a/Procfile.windows b/Procfile.windows new file mode 100644 index 0000000..4feca22 --- /dev/null +++ b/Procfile.windows @@ -0,0 +1 @@ +web: python manage.py runserver 0.0.0.0:5000 \ No newline at end of file -- GitLab From bfca26f232b515d1d87607b19c98d175700a5470 Mon Sep 17 00:00:00 2001 From: Odin Vatne <odinjv@stud.ntnu.no> Date: Mon, 30 May 2022 19:26:42 -0700 Subject: [PATCH 5/9] Add django-heroku to make things actually work --- pas/settings.py | 4 +++- requirements.txt | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pas/settings.py b/pas/settings.py index 593ab57..0a11cd0 100644 --- a/pas/settings.py +++ b/pas/settings.py @@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.2/ref/settings/ """ from pathlib import Path +import django_heroku # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -27,7 +28,6 @@ DEBUG = False ALLOWED_HOSTS = [] - # Application definition INSTALLED_APPS = [ @@ -129,3 +129,5 @@ STATIC_URL = '/static/' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' LOGIN_URL = '/login/' + +django_heroku.settings(locals()) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index dc7ea2c..fb32f48 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ asgiref==3.4.1 Django==3.2.9 pytz==2021.3 sqlparse==0.4.2 -gunicorn==20.1.0 \ No newline at end of file +gunicorn==20.1.0 +django-heroku==0.3.1 \ No newline at end of file -- GitLab From 5d8cbad4ce64495c839168b8443f2bf398c7255e Mon Sep 17 00:00:00 2001 From: Odin Vatne <odinjv@stud.ntnu.no> Date: Mon, 30 May 2022 19:52:17 -0700 Subject: [PATCH 6/9] Add migrations to procfile --- Procfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Procfile b/Procfile index 6030f45..72bd20b 100644 --- a/Procfile +++ b/Procfile @@ -1 +1,2 @@ +release: python manage.py migrate web: gunicorn pas.wsgi \ No newline at end of file -- GitLab From 7d3ba7a9455674a97be6c03e1c909660083cbff7 Mon Sep 17 00:00:00 2001 From: Odin Vatne <odinjv@stud.ntnu.no> Date: Mon, 30 May 2022 19:53:49 -0700 Subject: [PATCH 7/9] Remove overzealous password protection --- pas/settings.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/pas/settings.py b/pas/settings.py index 0a11cd0..a2b1b74 100644 --- a/pas/settings.py +++ b/pas/settings.py @@ -26,6 +26,7 @@ SECRET_KEY = 'B8ve2kye2D3@Vekezcye$#udghb#TK$hUMwX5vhbV@JBxqdXJ4BoA^%UdddRYswT' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False +#django_heroku overrides this with the correct value below ALLOWED_HOSTS = [] # Application definition @@ -86,18 +87,18 @@ DATABASES = { # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators # SECURITY WARNING: enable password validators in production. 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', - }, + # { + # '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', + # }, ] -- GitLab From 37450b264edcf0c63d5fb545237d8d09c70d5a1a Mon Sep 17 00:00:00 2001 From: odinjv <odinjv@stud.ntnu.no> Date: Tue, 31 May 2022 23:15:38 +0200 Subject: [PATCH 8/9] Add Heroku instructions to README --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 5b7ca3b..1443c16 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,18 @@ recommend setting up a virtual environment, using e.g. Python's `venv` module: * Install the required packages: `pip install -r requirements.txt` * Apply database migrations: `python manage.py migrate` * Optionally populate the database: `python manage.py populatedefaults` `python manage.py populatesamples` + * or `python manage.py loadcsvdata test_data/[data folder]` * Run the application: `python manage.py runserver` * This will make the application available on port 8000; visit it by going to https://localhost:8000/ in your browser. * Deactivate the virtual environment when you are done: `deactivate` + +## Heroku Deployment (for test administration) +* Install the Heroku CLI +* Open bash from the local repository root folder +* Run `heroku login` and log in +* Run `heroku create pasapp` to create a heroku app on your account +* Run `git push heroku [local branchname]:main` to push and deploy the app +* Run `heroku ps:scale web=1` to allocate one web server to the app +* Run `heroku run bash` to open a bash on the live server + * `python manage.py loadcsvdata test_data/[data folder]` to populate the server -- GitLab From aeefc904d96877936195b4ee3fbaad3afa55b5b7 Mon Sep 17 00:00:00 2001 From: odinjv <odinjv@stud.ntnu.no> Date: Thu, 2 Jun 2022 03:26:19 +0200 Subject: [PATCH 9/9] Revert unnecessary secret_key change --- pas/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pas/settings.py b/pas/settings.py index a2b1b74..42132d5 100644 --- a/pas/settings.py +++ b/pas/settings.py @@ -21,7 +21,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'B8ve2kye2D3@Vekezcye$#udghb#TK$hUMwX5vhbV@JBxqdXJ4BoA^%UdddRYswT' +SECRET_KEY = 'django-insecure-r0hfpfd#gt30%9tj!8@&%q2t&^m&s-qz7(o(qgj@qait@&25gc' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False -- GitLab