This sets up a Postgres DB and Hasura container as a long-running instance that restarts automatically on failure
- Spin up your SQL DB:
gcloud sql instances create "$db_instance" --database-version=POSTGRES_11 --zone="${project_zone}" --tier=db-g1-small --storage-type=SSD --maintenance-window-day=sunday --maintenance-window-hour=00
- Then set up your Hasura instance:
gcloud compute instances create-with-container "$hasura_instance" --container-image="hasura/graphql-engine:latest" --machine-type=e2-micro --container-env-file="./hasura.env" --container-env HASURA_GRAPHQL_ADMIN_SECRET="$hasura_admin_secret",HASURA_GRAPHQL_ACCESS_KEY="$hasura_admin_secret",HASURA_GRAPHQL_DATABASE_URL="postgres://hasurauser:${hasura_db_pw}@${sql_ip}:5432/postgres" --zone="${project_zone}" --container-restart-policy=always --tags="http-server" --address="${hasura_fixed_ext_ip}"
- You will additionally need to patch the SQL DB to allow the console to change firewall rules with:
yes | gcloud sql instances patch "$db_instance" --authorized-networks="$shell_ip"
- And then you need to allow Hasura to connect to the SQL DB:
gcloud sql users set-password hasurauser --instance="$db_instance" --password="$db_pw"
- Local development with Docker-Compose (has some test containers)
- Test deployment on Google Cloud (runs just long enough to execute the same test containers)
- Prod deployment on Google Cloud
Steps 2 and 3 run with the above scripts, whereas step 1 is docker-compose
Step 2 looks onerous, but there are differences between Google Cloud SQL and local Postgres that have broken Hasura before
However the upsides of having a managed DB greatly outweigh the downsides overall, imho
A g1-small DB in Google Cloud, which is very badly advertised, doesn't go above 5% usage even with about 20 semi-complicated transactions per second
it's aobut $1 per day IIRC
check out the E2 instances for compute also. Very cheap
- This is all from a chat with a helpful person online