diff --git a/README.md b/README.md index f58ed5dda..086006eb9 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ npm run build make first-use # ... use make up after this has run ``` -\* You will need SSO auth details to allow the project to run, but there are a lot of other details that would help make the experience better; ask another dev for their .env so that you can get a headstart +\* You will need SSO auth details (`AUTHBROKER_*` in your `.env` file) to allow the project to run, but there are a lot of other details that would help make the experience better; ask another dev for their .env so that you can get a head start. ## Run front end in watch mode diff --git a/package-lock.json b/package-lock.json index 329f5cb81..9c27e0e87 100644 --- a/package-lock.json +++ b/package-lock.json @@ -430,9 +430,9 @@ "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, "node_modules/caniuse-lite": { - "version": "1.0.30001466", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001466.tgz", - "integrity": "sha512-ewtFBSfWjEmxUgNBSZItFSmVtvk9zkwkl1OfRZlKA8slltRN+/C/tuGVrF9styXkN36Yu3+SeJ1qkXxDEyNZ5w==", + "version": "1.0.30001538", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001538.tgz", + "integrity": "sha512-HWJnhnID+0YMtGlzcp3T9drmBJUVDchPJ08tpUGFLs9CYlwWPH2uLgpHn8fND5pCgXVtnGS3H4QR9XLMHVNkHw==", "funding": [ { "type": "opencollective", @@ -441,6 +441,10 @@ { "type": "tidelift", "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" } ] }, diff --git a/package.json b/package.json index a111de87b..84d352f5b 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,10 @@ "clean": "rm -f ./assets/webpack_bundles/*" }, "browserslist": [ - "last 3 chrome versions", "last 1 firefox version", "last 1 safari version", "IE 11" + "last 3 chrome versions", + "last 1 firefox version", + "last 1 safari version", + "IE 11" ], "engines": { "npm": ">8.0.0", diff --git a/poetry.lock b/poetry.lock index 6e0ee8cd7..a8330c8e4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -870,6 +870,20 @@ files = [ {file = "cwcwidth-0.1.8.tar.gz", hash = "sha256:5adc034b7c90e6a8586bd046bcbf6004e35e16b0d7e31de395513a50d729bbf6"}, ] +[[package]] +name = "dbt-copilot-python" +version = "0.1.3" +description = "Helper functions to run Django and Flask applications in AWS Copilot/ECS." +optional = false +python-versions = ">=3.9,<4.0" +files = [ + {file = "dbt_copilot_python-0.1.3-py3-none-any.whl", hash = "sha256:d2dbb891af58889d578130f810efad86c947525fb61c6315bf0253f6d9297b00"}, + {file = "dbt_copilot_python-0.1.3.tar.gz", hash = "sha256:4d06ab9d12326ecd9fb017ef21c154bc51fc2f46cff19841e4f24b920f123afa"}, +] + +[package.dependencies] +requests = ">=2.31.0,<3.0.0" + [[package]] name = "defusedxml" version = "0.7.1" @@ -892,6 +906,21 @@ files = [ {file = "distlib-0.3.7.tar.gz", hash = "sha256:9dafe54b34a028eafd95039d5e5d4851a13734540f1331060d31c9916e7147a8"}, ] +[[package]] +name = "dj-database-url" +version = "2.1.0" +description = "Use Database URLs in your Django Application." +optional = false +python-versions = "*" +files = [ + {file = "dj-database-url-2.1.0.tar.gz", hash = "sha256:f2042cefe1086e539c9da39fad5ad7f61173bf79665e69bf7e4de55fa88b135f"}, + {file = "dj_database_url-2.1.0-py3-none-any.whl", hash = "sha256:04bc34b248d4c21aaa13e4ab419ae6575ef5f10f3df735ce7da97722caa356e0"}, +] + +[package.dependencies] +Django = ">=3.2" +typing-extensions = ">=3.10.0.0" + [[package]] name = "django" version = "4.1.10" @@ -1597,6 +1626,7 @@ files = [ {file = "greenlet-2.0.2-cp27-cp27m-win32.whl", hash = "sha256:6c3acb79b0bfd4fe733dff8bc62695283b57949ebcca05ae5c129eb606ff2d74"}, {file = "greenlet-2.0.2-cp27-cp27m-win_amd64.whl", hash = "sha256:283737e0da3f08bd637b5ad058507e578dd462db259f7f6e4c5c365ba4ee9343"}, {file = "greenlet-2.0.2-cp27-cp27mu-manylinux2010_x86_64.whl", hash = "sha256:d27ec7509b9c18b6d73f2f5ede2622441de812e7b1a80bbd446cb0633bd3d5ae"}, + {file = "greenlet-2.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d967650d3f56af314b72df7089d96cda1083a7fc2da05b375d2bc48c82ab3f3c"}, {file = "greenlet-2.0.2-cp310-cp310-macosx_11_0_x86_64.whl", hash = "sha256:30bcf80dda7f15ac77ba5af2b961bdd9dbc77fd4ac6105cee85b0d0a5fcf74df"}, {file = "greenlet-2.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:26fbfce90728d82bc9e6c38ea4d038cba20b7faf8a0ca53a9c07b67318d46088"}, {file = "greenlet-2.0.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:9190f09060ea4debddd24665d6804b995a9c122ef5917ab26e1566dcc712ceeb"}, @@ -1605,6 +1635,7 @@ files = [ {file = "greenlet-2.0.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:76ae285c8104046b3a7f06b42f29c7b73f77683df18c49ab5af7983994c2dd91"}, {file = "greenlet-2.0.2-cp310-cp310-win_amd64.whl", hash = "sha256:2d4686f195e32d36b4d7cf2d166857dbd0ee9f3d20ae349b6bf8afc8485b3645"}, {file = "greenlet-2.0.2-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:c4302695ad8027363e96311df24ee28978162cdcdd2006476c43970b384a244c"}, + {file = "greenlet-2.0.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:d4606a527e30548153be1a9f155f4e283d109ffba663a15856089fb55f933e47"}, {file = "greenlet-2.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c48f54ef8e05f04d6eff74b8233f6063cb1ed960243eacc474ee73a2ea8573ca"}, {file = "greenlet-2.0.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a1846f1b999e78e13837c93c778dcfc3365902cfb8d1bdb7dd73ead37059f0d0"}, {file = "greenlet-2.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3a06ad5312349fec0ab944664b01d26f8d1f05009566339ac6f63f56589bc1a2"}, @@ -1634,6 +1665,7 @@ files = [ {file = "greenlet-2.0.2-cp37-cp37m-win32.whl", hash = "sha256:3f6ea9bd35eb450837a3d80e77b517ea5bc56b4647f5502cd28de13675ee12f7"}, {file = "greenlet-2.0.2-cp37-cp37m-win_amd64.whl", hash = "sha256:7492e2b7bd7c9b9916388d9df23fa49d9b88ac0640db0a5b4ecc2b653bf451e3"}, {file = "greenlet-2.0.2-cp38-cp38-macosx_10_15_x86_64.whl", hash = "sha256:b864ba53912b6c3ab6bcb2beb19f19edd01a6bfcbdfe1f37ddd1778abfe75a30"}, + {file = "greenlet-2.0.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:1087300cf9700bbf455b1b97e24db18f2f77b55302a68272c56209d5587c12d1"}, {file = "greenlet-2.0.2-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:ba2956617f1c42598a308a84c6cf021a90ff3862eddafd20c3333d50f0edb45b"}, {file = "greenlet-2.0.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fc3a569657468b6f3fb60587e48356fe512c1754ca05a564f11366ac9e306526"}, {file = "greenlet-2.0.2-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8eab883b3b2a38cc1e050819ef06a7e6344d4a990d24d45bc6f2cf959045a45b"}, @@ -1642,6 +1674,7 @@ files = [ {file = "greenlet-2.0.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:b0ef99cdbe2b682b9ccbb964743a6aca37905fda5e0452e5ee239b1654d37f2a"}, {file = "greenlet-2.0.2-cp38-cp38-win32.whl", hash = "sha256:b80f600eddddce72320dbbc8e3784d16bd3fb7b517e82476d8da921f27d4b249"}, {file = "greenlet-2.0.2-cp38-cp38-win_amd64.whl", hash = "sha256:4d2e11331fc0c02b6e84b0d28ece3a36e0548ee1a1ce9ddde03752d9b79bba40"}, + {file = "greenlet-2.0.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:8512a0c38cfd4e66a858ddd1b17705587900dd760c6003998e9472b77b56d417"}, {file = "greenlet-2.0.2-cp39-cp39-macosx_11_0_x86_64.whl", hash = "sha256:88d9ab96491d38a5ab7c56dd7a3cc37d83336ecc564e4e8816dbed12e5aaefc8"}, {file = "greenlet-2.0.2-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:561091a7be172ab497a3527602d467e2b3fbe75f9e783d8b8ce403fa414f71a6"}, {file = "greenlet-2.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:971ce5e14dc5e73715755d0ca2975ac88cfdaefcaab078a284fea6cfabf866df"}, @@ -3916,4 +3949,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "576b320d7a8a4c37fcefec26fd5663179033c01910210ff3571ba6c4b687c227" +content-hash = "ba8c87d1a3414c2d52b43b991f6cc535ebb104f512adabc0d8751ab115006554" diff --git a/pyproject.toml b/pyproject.toml index 1427edca3..0921bb219 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,6 +56,8 @@ boto3 = "^1.26.115" pyjwt = { extras = ["crypto"], version = "^2.6.0" } django-taggit = "^3.1.0" django-celery-beat = "^2.5.0" +dbt-copilot-python = "^0.1.3" +dj-database-url = "^2.1.0" [tool.poetry.group.dev.dependencies] poetry = "^1.4.2" diff --git a/requirements.txt b/requirements.txt index a008e620a..3e95db9b1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,7 +21,9 @@ colorama==0.4.6 ; python_version >= "3.11" and python_version < "4.0" and platfo crispy-forms-gds==0.2.4 ; python_version >= "3.11" and python_version < "4.0" cron-descriptor==1.4.0 ; python_version >= "3.11" and python_version < "4.0" cryptography==41.0.3 ; python_version >= "3.11" and python_version < "4.0" +dbt-copilot-python==0.1.3 ; python_version >= "3.11" and python_version < "4.0" defusedxml==0.7.1 ; python_version >= "3.11" and python_version < "4.0" +dj-database-url==2.1.0 ; python_version >= "3.11" and python_version < "4.0" django-audit-log-middleware==0.0.4 ; python_version >= "3.11" and python_version < "4.0" django-celery-beat==2.5.0 ; python_version >= "3.11" and python_version < "4.0" django-chunk-upload-handlers==0.0.13 ; python_version >= "3.11" and python_version < "4.0" @@ -88,6 +90,7 @@ soupsieve==2.4.1 ; python_version >= "3.11" and python_version < "4.0" sqlparse==0.4.4 ; python_version >= "3.11" and python_version < "4.0" telepath==0.3.1 ; python_version >= "3.11" and python_version < "4.0" tweepy==4.14.0 ; python_version >= "3.11" and python_version < "4.0" +typing-extensions==4.7.1 ; python_version >= "3.11" and python_version < "4.0" tzdata==2023.3 ; python_version >= "3.11" and python_version < "4.0" urllib3==1.26.16 ; python_version >= "3.11" and python_version < "4" vine==5.0.0 ; python_version >= "3.11" and python_version < "4.0" diff --git a/src/config/settings/base.py b/src/config/settings/base.py index 5a42c464c..fa946c6ab 100644 --- a/src/config/settings/base.py +++ b/src/config/settings/base.py @@ -1,8 +1,12 @@ import os import sys +import dj_database_url import environ import sentry_sdk +from dbt_copilot_python.database import database_url_from_env +from dbt_copilot_python.network import setup_allowed_hosts +from dbt_copilot_python.utility import is_copilot from django.urls import reverse_lazy from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.redis import RedisIntegration @@ -89,7 +93,7 @@ # Allow all hosts # (this application will always be run behind a PaaS router or locally) -ALLOWED_HOSTS = ["*"] +ALLOWED_HOSTS = setup_allowed_hosts(["*"]) # Set up Django LOCAL_APPS = [ @@ -213,14 +217,22 @@ WSGI_APPLICATION = "config.wsgi.application" -if "postgres" in VCAP_SERVICES: - DATABASE_URL = VCAP_SERVICES["postgres"][0]["credentials"]["uri"] +if is_copilot(): + DATABASES = { + "default": dj_database_url.config( + default=database_url_from_env("DATABASE_CREDENTIALS") + ) + } else: - DATABASE_URL = os.getenv("DATABASE_URL") + if "postgres" in VCAP_SERVICES: + DATABASE_URL = VCAP_SERVICES["postgres"][0]["credentials"]["uri"] + else: + DATABASE_URL = os.getenv("DATABASE_URL") + + DATABASES = { + "default": env.db(), + } -DATABASES = { - "default": env.db(), -} if "UK_STAFF_LOCATIONS_DATABASE_URL" in env: DATABASES["uk_staff_locations"] = env.db("UK_STAFF_LOCATIONS_DATABASE_URL")