From 57f59d5219b1bfd2c5a0970790f3033631e4e846 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Fri, 9 Sep 2022 14:40:19 -0400 Subject: [PATCH 01/14] add models and admin for configs --- process_request/admin.py | 14 ++++++- .../migrations/0004_configlist_configpair.py | 31 +++++++++++++++ process_request/models.py | 38 +++++++++---------- 3 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 process_request/migrations/0004_configlist_configpair.py diff --git a/process_request/admin.py b/process_request/admin.py index 4185d36..16a4fbc 100644 --- a/process_request/admin.py +++ b/process_request/admin.py @@ -1,3 +1,13 @@ -# from django.contrib import admin +from django.contrib import admin -# Register your models here. +from .models import ConfigList, ConfigPair + + +class ConfigPairInline(admin.TabularInline): + fields = ('key', 'value', 'is_request_data_key') + model = ConfigPair + + +@admin.register(ConfigList) +class ConfigListAdmin(admin.ModelAdmin): + inlines = [ConfigPairInline] diff --git a/process_request/migrations/0004_configlist_configpair.py b/process_request/migrations/0004_configlist_configpair.py new file mode 100644 index 0000000..8af6970 --- /dev/null +++ b/process_request/migrations/0004_configlist_configpair.py @@ -0,0 +1,31 @@ +# Generated by Django 4.0.7 on 2022-09-09 18:22 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('process_request', '0003_auto_20211106_1625'), + ] + + operations = [ + migrations.CreateModel( + name='ConfigList', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ], + ), + migrations.CreateModel( + name='ConfigPair', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('key', models.CharField(help_text='Key for the configuration.', max_length=255)), + ('value', models.CharField(help_text='Value to assign to the configuration key.', max_length=255)), + ('is_request_data_key', models.BooleanField(default=False, help_text='If checked, uses the value provided as a key to get a value from the request data.')), + ('config_list', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='process_request.configlist')), + ], + ), + ] diff --git a/process_request/models.py b/process_request/models.py index 89dd500..dd7afc6 100644 --- a/process_request/models.py +++ b/process_request/models.py @@ -1,27 +1,27 @@ from django.contrib.auth.models import AbstractUser +from django.db import models class User(AbstractUser): + pass - archivist_group = [u"rac_archivists"] - donor_group = [u"rac_donors"] - researcher_group = [u"rac_researchers"] - AbstractUser._meta.get_field("email").blank = False - AbstractUser._meta.get_field("first_name").blank = False - AbstractUser._meta.get_field("last_name").blank = False - AbstractUser._meta.get_field("username").blank = False - - @property - def full_name(self): - """ - Return the first_name plus the last_name, with a space in between. - """ - full_name = '%s %s' % (self.first_name, self.last_name) - return full_name.strip() +class ConfigList(models.Model): + name = models.CharField(max_length=255) def __str__(self): - """ - Returns the full name and email of a user. - """ - return '{} <{}>'.format(self.full_name, self.email) + return self.name + + def get_defaults(self, request_data={}): + list = {} + for pair in self.configpair_set.all(): + value = request_data.get(pair.value) if pair.is_request_data_key else pair.value + list[pair.key] = value + return list + + +class ConfigPair(models.Model): + key = models.CharField(max_length=255, help_text="Key for the configuration.") + value = models.CharField(max_length=255, help_text="Value to assign to the configuration key.") + is_request_data_key = models.BooleanField(default=False, help_text="If checked, uses the value provided as a key to get a value from the request data.") + config_list = models.ForeignKey(ConfigList, on_delete=models.CASCADE) From db23e722e61b25071de1481ec0fc1d9965868ce7 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Fri, 9 Sep 2022 14:41:03 -0400 Subject: [PATCH 02/14] update user model --- ...er_email_alter_user_first_name_and_more.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 process_request/migrations/0005_alter_user_email_alter_user_first_name_and_more.py diff --git a/process_request/migrations/0005_alter_user_email_alter_user_first_name_and_more.py b/process_request/migrations/0005_alter_user_email_alter_user_first_name_and_more.py new file mode 100644 index 0000000..4102453 --- /dev/null +++ b/process_request/migrations/0005_alter_user_email_alter_user_first_name_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.0.7 on 2022-09-09 18:40 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('process_request', '0004_configlist_configpair'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='email', + field=models.EmailField(blank=True, max_length=254, verbose_name='email address'), + ), + migrations.AlterField( + model_name='user', + name='first_name', + field=models.CharField(blank=True, max_length=150, verbose_name='first name'), + ), + migrations.AlterField( + model_name='user', + name='last_name', + field=models.CharField(blank=True, max_length=150, verbose_name='last name'), + ), + ] From 3b9e00e3f9786fb2d3332938182dc7dfbcbc0f6a Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Fri, 9 Sep 2022 14:59:57 -0400 Subject: [PATCH 03/14] add data migrations --- .../migrations/0006_auto_20220909_1842.py | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 process_request/migrations/0006_auto_20220909_1842.py diff --git a/process_request/migrations/0006_auto_20220909_1842.py b/process_request/migrations/0006_auto_20220909_1842.py new file mode 100644 index 0000000..109b0f8 --- /dev/null +++ b/process_request/migrations/0006_auto_20220909_1842.py @@ -0,0 +1,61 @@ +# Generated by Django 4.0.7 on 2022-09-09 18:42 + +from django.db import migrations + +CONFIGURATIONS = [ + {"Duplication Defaults": [ + ("WebRequestForm", "PhotoduplicationRequest", False), + ("RequestType", "Copy", False), + ("Format", "format", True), + ("SpecialRequest", "questions", True), + ("SkipOrderEstimate", "Yes", False), + ]}, + {"Reading Room Defaults": [ + ("WebRequestForm", "DefaultRequest", False), + ("RequestType", "Loan", False), + ("ScheduledDate", "scheduledDate", True), + ("SpecialRequest", "questions", True) + ]}, + {"Request Defaults": [ + ("AeonForm", "EADRequest", False), + ("DocumentType", "Default", False), + ("GroupingIdentifier", "GroupingField", False), + ("GroupingOption_ItemInfo1", "Concatenate", False), + ("GroupingOption_ItemDate", "Concatenate", False), + ("GroupingOption_ItemTitle", "FirstValue", False), + ("GroupingOption_ItemAuthor", "FirstValue", False), + ("GroupingOption_ItemSubtitle", "FirstValue", False), + ("GroupingOption_ItemVolume", "FirstValue", False), + ("GroupingOption_ItemIssue", "Concatenate", False), + ("GroupingOption_ItemInfo2", "Concatenate", False), + ("GroupingOption_CallNumber", "FirstValue", False), + ("GroupingOption_ItemInfo3", "FirstValue", False), + ("GroupingOption_ItemCitation", "FirstValue", False), + ("GroupingOption_ItemNumber", "FirstValue", False), + ("GroupingOption_Location", "FirstValue", False), + ("GroupingOption_ItemInfo5", "FirstValue", False), + ("UserReview", "No", False), + ("SubmitButton", "Submit Request", False), + ]} +] + + +def add_configurations(apps, schema_editor): + ConfigList = apps.get_model('process_request', 'ConfigList') + ConfigPair = apps.get_model('process_request', 'ConfigPair') + for config in CONFIGURATIONS: + for k, v in config.items(): + config_list = ConfigList.objects.create(name=k) + for choice in v: + ConfigPair.objects.create(config_list=config_list, key=choice[0], value=choice[1], is_request_data_key=choice[2]) + + +class Migration(migrations.Migration): + + dependencies = [ + ('process_request', '0005_alter_user_email_alter_user_first_name_and_more'), + ] + + operations = [ + migrations.RunPython(add_configurations), + ] From 3696a095d83070ee9f730d0575c2a6a07c1ac72e Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Fri, 9 Sep 2022 15:12:14 -0400 Subject: [PATCH 04/14] implement config lists in AeonRequester --- process_request/routines.py | 57 +++++++++++-------------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/process_request/routines.py b/process_request/routines.py index 1e0bc8d..ee0a595 100644 --- a/process_request/routines.py +++ b/process_request/routines.py @@ -10,6 +10,7 @@ get_preferred_format, get_resource_creators, get_restricted_in_container, get_rights_info, get_size, get_url, list_chunks) +from .models import ConfigList class Processor(object): @@ -186,28 +187,15 @@ class AeonRequester(object): """Creates transactions in Aeon by sending data to the Aeon API.""" def __init__(self): - self.request_defaults = { - "AeonForm": "EADRequest", - "DocumentType": "Default", - "GroupingIdentifier": "GroupingField", - "GroupingOption_EADNumber": "FirstValue", - "GroupingOption_ItemInfo1": "Concatenate", - "GroupingOption_ItemDate": "Concatenate", - "GroupingOption_ItemTitle": "FirstValue", - "GroupingOption_ItemAuthor": "FirstValue", - "GroupingOption_ItemSubtitle": "FirstValue", - "GroupingOption_ItemVolume": "FirstValue", - "GroupingOption_ItemIssue": "Concatenate", - "GroupingOption_ItemInfo2": "Concatenate", - "GroupingOption_CallNumber": "FirstValue", - "GroupingOption_ItemInfo3": "FirstValue", - "GroupingOption_ItemCitation": "FirstValue", - "GroupingOption_ItemNumber": "FirstValue", - "GroupingOption_Location": "FirstValue", - "GroupingOption_ItemInfo5": "FirstValue", - "UserReview": "No", - "SubmitButton": "Submit Request", - } + self.request_defaults = self.get_config_defaults("Request Defaults") + + def get_config_defaults(self, list_name, request_data=None): + """Returns dictionary of configuration defaults for a named list.""" + try: + config_list = ConfigList.objects.get(name=list_name) + return config_list.get_defaults(request_data) + except ConfigList.DoesNotExist as e: + raise Exception(f"No ConfigList named {list_name} was found. Make sure a ConfigList matching that name is created in the Django Admin backend.") from e def get_request_data(self, request_type, baseurl, **kwargs): """Gets object data from ArchivesSpace and formats it for reading rooom @@ -248,16 +236,9 @@ def prepare_reading_room_request(self, items, request_data): Returns: data: Submission data for Aeon. """ - reading_room_defaults = { - "WebRequestForm": "DefaultRequest", - "RequestType": "Loan", - "ScheduledDate": request_data.get("scheduledDate"), - "SpecialRequest": request_data.get("questions"), - "Site": request_data.get("site"), - } - - request_data = self.parse_items(items) - return dict(**self.request_defaults, **reading_room_defaults, **request_data) + reading_room_defaults = self.get_config_defaults("Reading Room Defaults", request_data) + parsed_data = self.parse_items(items) + return dict(**self.request_defaults, **reading_room_defaults, **parsed_data) def prepare_duplication_request(self, items, request_data): """Maps duplication request data to Aeon fields. @@ -269,15 +250,9 @@ def prepare_duplication_request(self, items, request_data): Returns: data: Submission data for Aeon. """ - duplication_defaults = { - "WebRequestForm": "PhotoduplicationRequest", - "RequestType": "Copy", - "Format": request_data.get("format"), - "SpecialRequest": request_data.get("questions"), - "SkipOrderEstimate": "Yes", - } - request_data = self.parse_items(items, request_data.get("description", "")) - return dict(**self.request_defaults, **duplication_defaults, **request_data) + duplication_defaults = self.get_config_defaults("Duplication Defaults", request_data) + parsed_data = self.parse_items(items, request_data.get("description", "")) + return dict(**self.request_defaults, **duplication_defaults, **parsed_data) def parse_items(self, items, description=""): """Assigns item data to Aeon request fields. From 75a475ba33378a1dd4bf56717e5cd8944ff36440 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Fri, 9 Sep 2022 15:12:24 -0400 Subject: [PATCH 05/14] update tests --- process_request/tests.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/process_request/tests.py b/process_request/tests.py index bcedd1c..068e9d3 100644 --- a/process_request/tests.py +++ b/process_request/tests.py @@ -18,7 +18,6 @@ get_resource_creators, get_restricted_in_container, get_rights_info, get_rights_status, get_rights_text, get_size, indicator_to_integer, prepare_values) -from .models import User from .routines import AeonRequester, Mailer, Processor from .test_helpers import json_from_fixture, random_list, random_string from .views import (DeliverDuplicationRequestView, @@ -35,17 +34,6 @@ ) -class TestUsers(TestCase): - - def test_user(self): - user = User( - first_name="Patrick", - last_name="Galligan", - email="pgalligan@rockarch.org") - self.assertEqual(user.full_name, "Patrick Galligan") - self.assertEqual(str(user), "Patrick Galligan ") - - class TestHelpers(TestCase): @aspace_vcr.use_cassette("aspace_request.json") From e9655ae1eab82f05f20eba790f8569030403a974 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Mon, 26 Sep 2022 15:47:00 -0400 Subject: [PATCH 06/14] reate superuser if necessary --- README.md | 18 +++++++++++++++--- create_users.py | 14 ++++++++++++++ entrypoint.sh | 2 ++ request_broker/config.py.deploy | 3 +++ request_broker/config.py.example | 3 +++ request_broker/settings.py | 4 ++++ 6 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 create_users.py diff --git a/README.md b/README.md index 5c46519..1969f2f 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,21 @@ Or, if you want to remove all data ## Configuration -The request broker manages configuration by setting environment variables. These variables can be seen in `docker-compose.yml`. - -Deployment using the `docker-compose.prod.yml` or `docker-compose.dev.yml` files requires the presence of an `.env.prod` or `.env.dev` file in the root directory of the application. The environment variables included in those files should match the variables in `docker-compose.yml`, although the values assigned to those variables may change. +The request broker manages most configuration through environment variables. These +variables can be seen in `docker-compose.yml`. + +Configuration for request defaults is managed in the Django Admin UI. To access +this UI, you'll need to log in to the Admin backend (located at `/admin/`) +with a user account with the `is_staff` boolean set to `True`. If you're running +this application in a container and have the `DJANGO_SUPERUSER_USERNAME`, +`DJANGO_SUPERUSER_PASSWORD` and `DJANGO_SUPERUSER_EMAIL` variables set, a user +will be created on your behalf if a user with that username does not already exist. + +Deployment using the `docker-compose.prod.yml` or `docker-compose.dev.yml` files +requires the presence of an `.env.prod` or `.env.dev` file in the root directory +of the application. The environment variables included in those files should +match the variables in `docker-compose.yml`, although the values assigned to +those variables may change. ## Services diff --git a/create_users.py b/create_users.py new file mode 100644 index 0000000..fdf10d8 --- /dev/null +++ b/create_users.py @@ -0,0 +1,14 @@ +from django.conf import settings + +from process_request.models import User + +if all([ + getattr(settings, 'DJANGO_SUPERUSER_USERNAME', None), + getattr(settings, 'DJANGO_SUPERUSER_PASSWORD', None), + getattr(settings, 'DJANGO_SUPERUSER_EMAIL', None)]): + if not User.objects.filter(username=settings.DJANGO_SUPERUSER_USERNAME).exists(): + User.objects.create_superuser( + username=settings.DJANGO_SUPERUSER_USERNAME, + password=settings.DJANGO_SUPERUSER_PASSWORD, + email=settings.DJANGO_SUPERUSER_EMAIL, + is_staff=True) diff --git a/entrypoint.sh b/entrypoint.sh index dfe20d4..536eca5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -11,6 +11,8 @@ fi ./wait-for-it.sh db:5432 -- echo "Apply database migrations" python manage.py migrate +python manage.py shell < ./create_users.py + #Start server echo "Starting server" python manage.py runserver 0.0.0.0:${APPLICATION_PORT} diff --git a/request_broker/config.py.deploy b/request_broker/config.py.deploy index 9f38102..f2a31f0 100644 --- a/request_broker/config.py.deploy +++ b/request_broker/config.py.deploy @@ -2,6 +2,9 @@ DJANGO_DEBUG = ${DJANGO_DEBUG} DJANGO_SECRET_KEY = "${DJANGO_SECRET_KEY}" DJANGO_ALLOWED_HOSTS = ${DJANGO_ALLOWED_HOSTS} DJANGO_CORS_ALLOWED_ORIGINS = ${DJANGO_CORS_ALLOWED_ORIGINS} +DJANGO_SUPERUSER_USERNAME = "${DJANGO_SUPERUSER_USERNAME}" +DJANGO_SUPERUSER_PASSWORD = "${DJANGO_SUPERUSER_PASSWORD}" +DJANGO_SUPERUSER_EMAIL = "${DJANGO_SUPERUSER_EMAIL}" SQL_ENGINE = "${SQL_ENGINE}" SQL_DATABASE = "${SQL_DATABASE}" SQL_USER = "${SQL_USER}" diff --git a/request_broker/config.py.example b/request_broker/config.py.example index 9e8bf07..5d57aea 100644 --- a/request_broker/config.py.example +++ b/request_broker/config.py.example @@ -2,6 +2,9 @@ DJANGO_DEBUG = 1 # run Django in debug mode, which outputs stack traces to the DJANGO_SECRET_KEY = "obop2gifqn6wncaha^dt!w3an-%vkj_&1a@(w-2ci0))^o%#f4" # used by Django to create hashes DJANGO_ALLOWED_HOSTS = ['request-broker-web', 'localhost'] # hosts Django will respond to (list of strings) DJANGO_CORS_ALLOWED_ORIGINS = ['http://localhost:3000', 'http://rac-vch.ad.rockarchive.org:3001'] # hosts to add to the CORS Allowed-Origin header (list of strings) +DJANGO_SUPERUSER_USERNAME = "admin" # Username for superuser to log into Django Admin +DJANGO_SUPERUSER_PASSWORD = "password" # Password for superuser to log into Django Admin +DJANGO_SUPERUSER_EMAIL = "admin@example.org" # Email for superuser to log into Django Admin SQL_ENGINE = "django.db.backends.postgresql" # the database engine used by the application (one of django.db.backends) SQL_DATABASE = "request_broker_dev" # name of the application database SQL_USER = "postgres" # name of the application database user diff --git a/request_broker/settings.py b/request_broker/settings.py index e978cfd..4c6933f 100644 --- a/request_broker/settings.py +++ b/request_broker/settings.py @@ -133,6 +133,10 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' +DJANGO_SUPERUSER_USERNAME = config.DJANGO_SUPERUSER_USERNAME +DJANGO_SUPERUSER_PASSWORD = config.DJANGO_SUPERUSER_PASSWORD +DJANGO_SUPERUSER_EMAIL = config.DJANGO_SUPERUSER_EMAIL + # CORS settings CORS_ALLOWED_ORIGINS = config.DJANGO_CORS_ALLOWED_ORIGINS DIMES_HOSTNAME = config.DIMES_HOSTNAME From cc938b80fef63b467b2ee06e239c97bc0917e343 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Mon, 26 Sep 2022 15:48:06 -0400 Subject: [PATCH 07/14] add User admin --- process_request/admin.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/process_request/admin.py b/process_request/admin.py index 16a4fbc..b38d77a 100644 --- a/process_request/admin.py +++ b/process_request/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .models import ConfigList, ConfigPair +from .models import ConfigList, ConfigPair, User class ConfigPairInline(admin.TabularInline): @@ -11,3 +11,8 @@ class ConfigPairInline(admin.TabularInline): @admin.register(ConfigList) class ConfigListAdmin(admin.ModelAdmin): inlines = [ConfigPairInline] + + +@admin.register(User) +class UserAdmin(admin.ModelAdmin): + pass From 78659d3c53e2294c7b0d606a65d074d7f6f94157 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Mon, 26 Sep 2022 15:48:27 -0400 Subject: [PATCH 08/14] remove home link from admin ui --- request_broker/urls.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/request_broker/urls.py b/request_broker/urls.py index df92cfa..6cbe32e 100644 --- a/request_broker/urls.py +++ b/request_broker/urls.py @@ -21,6 +21,8 @@ DownloadCSVView, LinkResolverView, MailerView, ParseRequestView, PingView) +admin.site.site_url = None + urlpatterns = [ path("admin/", admin.site.urls), path("api/deliver-request/email", MailerView.as_view(), name="deliver-email"), From ec6d3b62eb7799429bf75d165ea31cde20f64827 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Fri, 30 Sep 2022 14:33:17 -0400 Subject: [PATCH 09/14] use UserAdmin --- process_request/admin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/process_request/admin.py b/process_request/admin.py index b38d77a..434a656 100644 --- a/process_request/admin.py +++ b/process_request/admin.py @@ -1,4 +1,5 @@ from django.contrib import admin +from django.contrib.auth.admin import UserAdmin from .models import ConfigList, ConfigPair, User @@ -14,5 +15,5 @@ class ConfigListAdmin(admin.ModelAdmin): @admin.register(User) -class UserAdmin(admin.ModelAdmin): +class UserAdmin(UserAdmin): pass From 79964fa12eb38c42118cd68981052570c2892c9c Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Fri, 30 Sep 2022 14:55:23 -0400 Subject: [PATCH 10/14] Force users to configure admin user; --- create_users.py | 3 +++ entrypoint.sh | 9 ++++++++- request_broker/config.py.example | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/create_users.py b/create_users.py index fdf10d8..f1a2cb6 100644 --- a/create_users.py +++ b/create_users.py @@ -1,4 +1,5 @@ from django.conf import settings +from django.core.exceptions import ImproperlyConfigured from process_request.models import User @@ -12,3 +13,5 @@ password=settings.DJANGO_SUPERUSER_PASSWORD, email=settings.DJANGO_SUPERUSER_EMAIL, is_staff=True) +else: + raise ImproperlyConfigured("Values for DJANGO_SUPERUSER_USERNAME, DJANGO_SUPERUSER_PASSWORD and DJANGO_SUPERUSER_EMAIL must be set in config.py") diff --git a/entrypoint.sh b/entrypoint.sh index 536eca5..64653cb 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + echo "Waiting for PostgreSQL..." # Create config.py if it doesn't exist @@ -11,7 +13,12 @@ fi ./wait-for-it.sh db:5432 -- echo "Apply database migrations" python manage.py migrate -python manage.py shell < ./create_users.py +# Create default users when running locally +# If this blows up, you likely need to add a DJANGO_SUPERUSER_USERNAME to config.py +if [ "$CI" != "true" ]; then + echo "Creating default users" + python manage.py shell < ./create_users.py +fi #Start server echo "Starting server" diff --git a/request_broker/config.py.example b/request_broker/config.py.example index 5d57aea..7df4583 100644 --- a/request_broker/config.py.example +++ b/request_broker/config.py.example @@ -2,7 +2,7 @@ DJANGO_DEBUG = 1 # run Django in debug mode, which outputs stack traces to the DJANGO_SECRET_KEY = "obop2gifqn6wncaha^dt!w3an-%vkj_&1a@(w-2ci0))^o%#f4" # used by Django to create hashes DJANGO_ALLOWED_HOSTS = ['request-broker-web', 'localhost'] # hosts Django will respond to (list of strings) DJANGO_CORS_ALLOWED_ORIGINS = ['http://localhost:3000', 'http://rac-vch.ad.rockarchive.org:3001'] # hosts to add to the CORS Allowed-Origin header (list of strings) -DJANGO_SUPERUSER_USERNAME = "admin" # Username for superuser to log into Django Admin +DJANGO_SUPERUSER_USERNAME = "" # Username for superuser to log into Django Admin DJANGO_SUPERUSER_PASSWORD = "password" # Password for superuser to log into Django Admin DJANGO_SUPERUSER_EMAIL = "admin@example.org" # Email for superuser to log into Django Admin SQL_ENGINE = "django.db.backends.postgresql" # the database engine used by the application (one of django.db.backends) From a5ee4c4641895cc660e365596bc8eb7198fbeabb Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Fri, 30 Sep 2022 15:07:21 -0400 Subject: [PATCH 11/14] better variable checking --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 64653cb..2c7b0bd 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -15,7 +15,7 @@ python manage.py migrate # Create default users when running locally # If this blows up, you likely need to add a DJANGO_SUPERUSER_USERNAME to config.py -if [ "$CI" != "true" ]; then +if [[ -z "${TRAVIS_CI}" ]]; then echo "Creating default users" python manage.py shell < ./create_users.py fi From 8e776ef40a2a6d5eace7269a68721ae5b2ad4249 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Fri, 30 Sep 2022 15:18:41 -0400 Subject: [PATCH 12/14] pass env variable to docker --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 172c25c..9ca6f84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ env: - CONTAINER: request-broker-web - APPLICATION_NAME: request_broker - APPLICATION_PORT: 80 + - TRAVIS_CI: true before_install: - cp ${APPLICATION_NAME}/config.py.example ${APPLICATION_NAME}/config.py - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin From ce141902e98670f26ce6887de711e900a5cc0d16 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Fri, 30 Sep 2022 15:28:29 -0400 Subject: [PATCH 13/14] keep attached for debug --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9ca6f84..83a80a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ env: before_install: - cp ${APPLICATION_NAME}/config.py.example ${APPLICATION_NAME}/config.py - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - - docker-compose up -d + - docker-compose up install: - ./wait-for-it.sh $CONTAINER:$APPLICATION_PORT -- docker-compose exec $CONTAINER pip install coverage - pip install pre-commit && pre-commit install From 9904835dc04df72a2f3853b93329ffa89923e58c Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Fri, 30 Sep 2022 16:50:52 -0400 Subject: [PATCH 14/14] pass env variable to docker-compose file --- .travis.yml | 2 +- docker-compose.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 83a80a0..9ca6f84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ env: before_install: - cp ${APPLICATION_NAME}/config.py.example ${APPLICATION_NAME}/config.py - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - - docker-compose up + - docker-compose up -d install: - ./wait-for-it.sh $CONTAINER:$APPLICATION_PORT -- docker-compose exec $CONTAINER pip install coverage - pip install pre-commit && pre-commit install diff --git a/docker-compose.yml b/docker-compose.yml index b6f5464..bc560d9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,7 @@ services: entrypoint: /code/entrypoint.sh environment: - APPLICATION_PORT=${APPLICATION_PORT:-8000} + - TRAVIS_CI=${TRAVIS_CI} volumes: - .:/code ports: