Skip to content

Commit

Permalink
DBTP-457 Use dbt-copilot-python to set ALLOWED_HOSTS & DATABASES in D…
Browse files Browse the repository at this point in the history
…BT PaaS (#461)

What it says in the title, plus it should remain compatible with GOV.UK
PaaS.
  • Loading branch information
WillGibson authored Sep 22, 2023
1 parent 3d2acd1 commit aa2b54f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
35 changes: 34 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
26 changes: 19 additions & 7 deletions src/config/settings/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit aa2b54f

Please sign in to comment.