Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to PSQL DB setup #334

Merged
merged 18 commits into from
Nov 2, 2024
19 changes: 16 additions & 3 deletions .github/actions/deploy_gcloud/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ inputs:
database-host:
description: Database host
required: true
database-name:
description: Database name
required: true
database-password:
description: Database password
required: true
django-secret:
description: Django secret
required: true
Expand Down Expand Up @@ -112,8 +118,8 @@ runs:
pip install -t lib --upgrade "git+https://github.com/ocadotechnology/rapid-router@${RAPID_ROUTER_BRANCH}#egg=rapid-router"
fi

pip install -t lib django-anymail[amazon_ses]
pip install -t lib google-auth==1.*
pip install -t lib psycopg2==2.9.10

# Install custom common package after everything else if deploying a specific portal branch to ensure the
# changes from common come through
Expand All @@ -139,6 +145,12 @@ runs:

sudo mkdir /cloudsql
sudo chown runner:runner /cloudsql

# Start PSQL service
sudo systemctl start postgresql

# Check PSQL status
sudo systemctl status postgresql

# Start Cloud SQL Proxy and migrate
/tmp/cloud_sql_proxy -dir=/cloudsql &
Expand All @@ -147,7 +159,7 @@ runs:
is_sql_proxy_ready=0
for i in {1..30}; do
echo "Waiting for cloudsql-proxy to be ready $i/30"
if mysqladmin -S /cloudsql/decent-digit-629:europe-west1:db ping; then
if pg_isready --host=/cloudsql/decent-digit-629:europe-west1:db-new --port=5432; then
echo "cloudsql-proxy is ready"
is_sql_proxy_ready=1
break
Expand Down Expand Up @@ -179,8 +191,9 @@ runs:
VERSION: ${{ inputs.version }}
CLOUDSDK_CORE_DISABLE_PROMPTS: "1"
CLOUDSDK_PYTHON_SITEPACKAGES: "1"
DATABASE_NAME: cfl_${{env.DATABASE_POSTFIX}}
DATABASE_NAME: ${{ inputs.database-name }}
DATABASE_HOST: ${{ inputs.database-host }}
DATABASE_PASSWORD: ${{ inputs.database-password }}
CACHE_PREFIX: ${{ env.MODULE_NAME }}-
AWS_ACCESS_KEY_ID: ${{ inputs.aws-access-key-id }}
AWS_SECRET_ACCESS_KEY: ${{ inputs.aws-secret-access-key }}
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/deploy_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ jobs:
env:
APP_ID: decent-digit-629
NODE_ENV: production
DB_PORT: 3306
DB_PORT: 5432
GKE_ZONE: europe-west1-b
MODULE_NAME: default
VERSION: ${{ github.run_number }}
DATABASE_POSTFIX: ${{ secrets.DATABASE_POSTFIX }}
permissions:
id-token: 'write'
steps:
Expand Down Expand Up @@ -48,6 +47,8 @@ jobs:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
database-host: ${{ secrets.DATABASE_HOST }}
database-name: ${{ secrets.DATABASE_NAME }}
database-password: ${{ secrets.DATABASE_PASSWORD }}
django-secret: ${{ secrets.DJANGO_SECRET }}
django-portal-contact-form-email: ${{ secrets.DJANGO_PORTAL_CONTACT_FORM_EMAIL }}
dotmailer-create-contact-url: ${{ secrets.DOTMAILER_CREATE_CONTACT_URL }}
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/deploy_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ jobs:
env:
APP_ID: decent-digit-629
NODE_ENV: production
DB_PORT: 3306
DB_PORT: 5432
GKE_ZONE: europe-west1-b
MODULE_NAME: dev
VERSION: ${{ github.run_number }}
DATABASE_POSTFIX: ${{ secrets.DATABASE_POSTFIX }}
permissions:
id-token: 'write'
steps:
Expand Down Expand Up @@ -58,6 +57,8 @@ jobs:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
database-host: ${{ secrets.DATABASE_HOST }}
database-name: ${{ secrets.DATABASE_NAME }}
database-password: ${{ secrets.DATABASE_PASSWORD }}
django-secret: ${{ secrets.DJANGO_SECRET }}
django-portal-contact-form-email: ${{ secrets.DJANGO_PORTAL_CONTACT_FORM_EMAIL }}
dotmailer-create-contact-url: ${{ secrets.DOTMAILER_CREATE_CONTACT_URL }}
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/deploy_staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ jobs:
env:
APP_ID: decent-digit-629
NODE_ENV: production
DB_PORT: 3306
DB_PORT: 5432
GKE_ZONE: europe-west1-b
MODULE_NAME: staging
VERSION: ${{ github.run_number }}
DATABASE_POSTFIX: ${{ secrets.DATABASE_POSTFIX }}
permissions:
id-token: 'write'
steps:
Expand Down Expand Up @@ -48,6 +47,8 @@ jobs:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
database-host: ${{ secrets.DATABASE_HOST }}
database-name: ${{ secrets.DATABASE_NAME }}
database-password: ${{ secrets.DATABASE_PASSWORD }}
django-secret: ${{ secrets.DJANGO_SECRET }}
django-portal-contact-form-email: ${{ secrets.DJANGO_PORTAL_CONTACT_FORM_EMAIL }}
dotmailer-create-contact-url: ${{ secrets.DOTMAILER_CREATE_CONTACT_URL }}
Expand Down
1 change: 1 addition & 0 deletions app.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ env_variables:
CACHE_PREFIX: '${CACHE_PREFIX}'
DATABASE_NAME: '${DATABASE_NAME}'
DATABASE_HOST: '${DATABASE_HOST}'
DATABASE_PASSWORD: '${DATABASE_PASSWORD}'
RECAPTCHA_PRIVATE_KEY: '${RECAPTCHA_PRIVATE_KEY}'
RECAPTCHA_PUBLIC_KEY: '${RECAPTCHA_PUBLIC_KEY}'
DJANGO_PORTAL_CONTACT_FORM_EMAIL: '${DJANGO_PORTAL_CONTACT_FORM_EMAIL}'
Expand Down
1 change: 0 additions & 1 deletion django_site/pipeline_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# Application definition

INSTALLED_APPS = (
"anymail",
"deploy",
"game",
"pipeline",
Expand Down
5 changes: 3 additions & 2 deletions django_site/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@

DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"ENGINE": "django.db.backends.postgresql",
"HOST": os.getenv("DATABASE_HOST"),
"NAME": os.getenv("DATABASE_NAME"),
"USER": "root",
"USER": "postgres",
"PASSWORD": os.getenv("DATABASE_PASSWORD"),
"ATOMIC_REQUESTS": True,
}
}
Expand Down
1 change: 1 addition & 0 deletions generate_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"django-redis==4.11.*",
"google-cloud-logging==1.*",
"google-auth==1.*",
"psycopg2==2.9.10"
]
)

Expand Down
Loading