cargo run
- Install Google Cloud SDK
- Ensure you have access to the Container Registrar service account in GCP IAM & Admin
- Run
gcloud auth loginusing an account with access to the Container Registrar - Run
docker tag tcmoore/bend-api-service gcr.io/{PROJECT_ID}/api-service(You can find the project id here) - Run
docker push gcr.io/bend-330614/api-service
Note that bend-db indicates the Cloud SQL instance, while bend_db indicates the postgres database name
- Create a new Postgres instance in Cloud SQL and store the root password somewhere secure
- Wait for the instance to boot up, then connect:
- Run
gcloud sql connect bend-db --user=postgres --project PROJECT_IDand enter your password - You can now run
diesel setup
- Using:
DATABASE_URL=postgres://postgres:{ROOT_PASSWORD}@{YOUR_DB_PUBLIC_IP}/bend_db
- Run
gcloud sql connect bend-db --user=postgres --project PROJECT_IDand enter your password - You can now run migrations for 5 minutes with Diesel with
diesel migration run
- Using:
DATABASE_URL=postgres://postgres:{ROOT_PASSWORD}@{YOUR_DB_PUBLIC_IP}/bend-db
Steps to connect to Cloud SQL from the api service in the cloud environment:
- Ensure that a service account exists with the Cloud SQL Client permissions
- Deploy a new revision of the Cloud Run instance with a Connection enabled (in the Connections tab) to the SQL instance
- In Cloud Run, the DATABASE_URL must take a slightly different form to support the unix socket path
postgres://{USER}:{PASSWORD}@?host=/cloudsql/{CLOUD_SQL_CONNECTION_NAME}&dbname=bend_db
See Official Docs for additional details.