Google Cloud access

View Source

You will need to be given access to the environments before being able to access our cloud instances. This should be done as part of your onboarding, but reach out to #devops on Slack otherwise.

gcloud

gcloud is required for interfacing with our application deployments. Follow the instructions here to install.

Configs

Once installed run the following:

gcloud auth login
gcloud config set project vetspire-app

Upon running the above. Your default browser will open up to request authorization to add gcloud permissions to your @vetspire account. Go through the flow and accept. If your browser does not open up, check the console. A new link is generated and presented to you that you can use to login.

Checking configs

The following commands should run without failure if you've been given the necessary credentials to deploy.

# dev
gcloud container clusters get-credentials vetspire-dev-api --zone us-central1-c

# staging
gcloud container clusters get-credentials vetspire-api-staging --zone us-central1-c

# production
gcloud container clusters get-credentials vetspire-api-prod --zone us-central1

You may also see an error about gke-gcloud-auth-plugin. You can fix that by running the following

gcloud components install gke-gcloud-auth-plugin

Remote Access

Backend

One of the strengths of the BEAM (The VM supporting Erlang & Elixir) is the ability to poke and prod a running deployed system for running commands manually, debugging, and code patching.

This is especially useful when confirming bugs which seem to only appear for a specific org/location/invoice/encounter, where it isn't feasible to reproduce the issue easily locally, or when you want to test a tentative patch for a hotfix scenario (i.e., increasing a query timeout).

To aide in doing this easily, a helper script is provided as part of the backend, which you can find in the api/ directory. Simply cd into said directory and try running the following commands:

./scripts/connect dev
./scripts/connect dev datasync
./scripts/connect dev vetspire_admin

./scripts/connect staging
./scripts/connect staging datasync
./scripts/connect staging vetspire_admin

./scripts/connect prod
./scripts/connect prod datasync
./scripts/connect prod vetspire_admin

The first argument to ./scripts/connect is the environment you want to connect to. Currently, Vetspire is deployed to three environments:

  1. dev (aka testdev), which is where any code merged to master will deploy to
  2. staging (aka stg), which is where any code merged to staging will deploy to
  3. prod, which is where any code merged to production will deploy to

The script will automatically change your locally checked out cluster, and connect to the first available pod of the type requested.

The second argument to ./scripts/connect is the application type you'd like to connect to. While not a formal microservice architecture, the BEAM allows us to have several different deployments dedicated to running different applications built atop the same core. Today, we deploy three different applications:

  1. vetspire_api, the GraphQL API (and background job running) where 95% of the day-to-day business logic behind Vetspire lives
  2. vetspire_admin, the admin portal where SSO users can obtain login links to production sites
  3. datasync, an app which is responsible for importing legacy data from clients as part of a new location's onboarding procedure (to migrate all their existing medical records from their source system -> Vetspire)

The latter two applications build on top of vetspire_api, and due to fewer dependant users (especially for vetspire_admin), these are preferred places to connect when debugging/hot-code reloading.

By default, if no second argument is provided, ./scripts/connect will default the application to vetspire_admin. This is to reduce the impact of accidentally hot-code reloading broken code onto the production environment.

In case you explicitly want to do this, please provide vetspire_api as the second argument to the invocation of this script.

You can hot-code reload patched versions of modules by simply making local modifications for a given module and copy & pasting said module into your remote-connected iEX terminal. Please note that any changes you make are persisted until the pod you're on is restarted, so only do this on the vetspire_api app if you know what you're doing!!.