Repository: carpentries/amy

Issue:
Prepare GitHub action for deploying to ECR and running Cloudformation template
1. Prepare GitHub action for deploying to ECR: https://docs.github.com/en/actions/deployment/deploying-to-your-cloud-provider/deploying-to-amazon-elastic-container-service
2. Prepare GitHub action for running Cloudformation template: https://github.com/marketplace/actions/aws-cloudformation-deploy-cloudformation-stack-action-for-github-actions


Discussion:

Resolving patch:
diff --git a/config/settings.py b/config/settings.py
--- a/config/settings.py
+++ b/config/settings.py
@@ -2,8 +2,6 @@
 Django settings for AMY project.
 """
 
-import json
-import os
 from pathlib import Path
 
 from django.core.exceptions import ImproperlyConfigured
@@ -19,7 +17,11 @@
     AMY_DEBUG=(bool, True),
     AMY_SITE_ID=(int, 2),
     AMY_ALLOWED_HOSTS=(list, ["amy.carpentries.org"]),
-    DATABASE_URL=(str, "postgres://amy:amypostgresql@localhost/amy"),
+    AMY_DATABASE_HOST=(str, "localhost"),
+    AMY_DATABASE_PORT=(int, 5432),
+    AMY_DATABASE_NAME=(str, "amy"),
+    AMY_DATABASE_USER=(str, "amy"),
+    AMY_DATABASE_PASSWORD=(str, "amypostgresql"),
     AMY_RECAPTCHA_PUBLIC_KEY=(str, "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"),
     AMY_RECAPTCHA_PRIVATE_KEY=(str, "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe"),
     AMY_SOCIAL_AUTH_GITHUB_KEY=(str, ""),
@@ -84,20 +86,18 @@
 # -----------------------------------------------------------------------------
 # https://docs.djangoproject.com/en/dev/ref/settings/#databases
 
-if "DATABASE_JSON" in env:
-    # If database credentials are provided via AWS Secrets Manager secret JSON, then
-    # decompose it and create a database URL.
-    database_json = json.loads(env("DATABASE_JSON"))
-    database_url = (
-        f"postgres://{database_json['username']}:{database_json['password']}"
-        f"@{database_json['host']}:{database_json['port']}/{database_json['dbname']}"
-    )
-    os.environ["DATABASE_URL"] = database_url
-
 DATABASES = {
-    "default": env.db(),
+    "default": {
+        "ENGINE": "django.db.backends.postgresql",
+        "NAME": env("AMY_DATABASE_NAME"),
+        "USER": env("AMY_DATABASE_USER"),
+        "PASSWORD": env("AMY_DATABASE_PASSWORD"),
+        "HOST": env("AMY_DATABASE_HOST"),
+        "PORT": env("AMY_DATABASE_PORT"),
+        "ATOMIC_REQUESTS": True,
+    }
 }
-DATABASES["default"]["ATOMIC_REQUESTS"] = True
+
 # Default primary key field type
 # https://docs.djangoproject.com/en/dev/ref/settings/#default-auto-field
 DEFAULT_AUTO_FIELD = "django.db.models.AutoField"


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -59,7 +59,11 @@ jobs:
           exit 1;
         fi;
       env:
-        DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_amy
+        AMY_DATABASE_HOST: localhost
+        AMY_DATABASE_PORT: 5432
+        AMY_DATABASE_NAME: test_amy
+        AMY_DATABASE_USER: postgres
+        AMY_DATABASE_PASSWORD: postgres
 
     - name: Collect static files
       run: |
@@ -71,4 +75,9 @@ jobs:
     - name: Test
       run: pipenv run python manage.py test
       env:
-        DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_amy
+        AMY_DATABASE_HOST: localhost
+        AMY_DATABASE_PORT: 5432
+        AMY_DATABASE_NAME: test_amy
+        AMY_DATABASE_USER: postgres
+        AMY_DATABASE_PASSWORD: postgres
+