diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ee1853a..1001e373 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,6 @@ env: POSTGRES_DB: postgres POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres GOOGLE_APPLICATION_CREDENTIALS: "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}" DJANGO_GCP_STORAGE_BUCKET_NAME: ${{ secrets.DJANGO_GCP_STORAGE_BUCKET_NAME }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/config/settings/base.py b/config/settings/base.py index 713f9237..5d5d0859 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -13,11 +13,6 @@ APPS_DIR = ROOT_DIR / "pepfar_mle" env = environ.Env() -# >>> from urllib.parse import quote_plus -# >>> host = '/cloudsql/sghi-307909:europe-west1:clinical-instance' -# >>> quote_plus(host) -# '%2Fcloudsql%2Fsghi-307909%3Aeurope-west1%3Aclinical-instance' -# >>> if os.environ.get("GOOGLE_CLOUD_PROJECT", None): project_id = os.environ.get("GOOGLE_CLOUD_PROJECT") client = secretmanager.SecretManagerServiceClient() @@ -26,7 +21,6 @@ payload = client.access_secret_version(name=name).payload.data.decode("UTF-8") env.read_env(io.StringIO(payload)) print("set env from secrets...") - print(f'database settings: {env.db("DATABASE_URL")}') # GENERAL # ------------------------------------------------------------------------------ @@ -53,8 +47,17 @@ # DATABASES # ------------------------------------------------------------------------------ # https://docs.djangoproject.com/en/dev/ref/settings/#databases -DATABASES = {"default": env.db("DATABASE_URL")} -DATABASES["default"]["ATOMIC_REQUESTS"] = True +DATABASES = { + "default": { + "NAME": env.str("POSTGRES_DB"), + "USER": env.str("POSTGRES_USER"), + "PASSWORD": env.str("POSTGRES_PASSWORD"), + "HOST": env.str("POSTGRES_HOST"), + "PORT": env.str("POSTGRES_PORT"), + "ENGINE": "django.db.backends.postgresql", + "ATOMIC_REQUESTS": True, + } +} # URLS # ------------------------------------------------------------------------------ diff --git a/config/settings/production.py b/config/settings/production.py index cfc8bbc1..f778ff6e 100644 --- a/config/settings/production.py +++ b/config/settings/production.py @@ -18,7 +18,6 @@ # DATABASES # ------------------------------------------------------------------------------ -DATABASES["default"] = env.db("DATABASE_URL") # noqa F405 DATABASES["default"]["ATOMIC_REQUESTS"] = True # noqa F405 DATABASES["default"]["CONN_MAX_AGE"] = env.int("CONN_MAX_AGE", default=60) # noqa F405 diff --git a/config/settings/test.py b/config/settings/test.py index 5bc61654..feebcc62 100644 --- a/config/settings/test.py +++ b/config/settings/test.py @@ -79,4 +79,8 @@ def require_env(name: str) -> str: # ensure that environment variables that are needed to run tests successfully are present require_env("GOOGLE_APPLICATION_CREDENTIALS") require_env("DJANGO_GCP_STORAGE_BUCKET_NAME") -require_env("DATABASE_URL") +require_env("POSTGRES_DB") +require_env("POSTGRES_USER") +require_env("POSTGRES_PASSWORD") +require_env("POSTGRES_HOST") +require_env("POSTGRES_PORT") diff --git a/entrypoint b/entrypoint index 88e3ab53..3e14e425 100644 --- a/entrypoint +++ b/entrypoint @@ -4,23 +4,6 @@ set -o errexit set -o pipefail set -o nounset -if [ -z "${POSTGRES_USER}" ]; then - base_postgres_image_default_user='postgres' - export POSTGRES_USER="${base_postgres_image_default_user}" -fi -echo "Set/checked POSTGRES_USER..." - -# omit the port when running on App Engine, Cloud Run etc -if [ -z "${INSTANCE_CONNECTION_NAME}" ]; then - export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}" - echo "Set up database URL for running in Cloud SQL (Unix Socket)" -else - export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}/${POSTGRES_DB}" - echo "Set up database URL for running outside Cloud SQL (host and port)" -fi - -echo "Database URL: ${DATABASE_URL}" - postgres_ready() { python << END import sys