Google Cloud Run is a service that aims to bridge the gap between the maintainance benefits of serverless architecture and the flexibility of Kubernetes. It is built on top of the opensource Knative project. Deploying using Cloud Run is similar to deploying using Google App Engine with the benefits of a free tier and a simpler build process.
There is documentaion about how to use environment variables to configure a large number of storage providers; however, for this prarticular example we will use Google Cloud Storage(GCS) because it fits nicely with Cloud Run.
This guide assumes you have completed the following tasks:
If you do not already have GCS bucket you can set one up using the gsutil tool.
First select a region you would like to have your storage in. You can then create a bucket in that region using the following command substituting your in your region and bucket name.
$ gsutil mb -l europe-west-4 gs://some-bucket
Change the values of these environment variables to be appropriate for your application. For
GOOGLE_CLOUD_PROJECT, this needs to be the name of the project that has your cloud run deployment in it.
ATHENS_REGION should be the region that your cloud run instance will be in, and
GCS_BUCKET should be the Google Cloud Storage bucket that Athens will store module code and metadata in..
$ export GOOGLE_CLOUD_PROJECT=your-project $ export ATHENS_REGION=asia-northeast1 $ export GCS_BUCKET=your-bucket-name
You will then need to push a copy of the Athens docker image to your google cloud container registry.
$ docker pull gomods/athens:v0.6.0 $ docker tag gomods/athens:v0.6.0 gcr.io/$GOOGLE_CLOUD_PROJECT/athens:v0.6.0 $ gcloud builds submit --tag gcr.io/$GOOGLE_CLOUD_PROJECT/athens:v0.6.0
Once you have the container image in your registry you can use
gcloud to provision your Athens instance.
$ gcloud beta run deploy \ --image gcr.io/$GOOGLE_CLOUD_PROJECT/athens:v0.6.0 \ --platform managed \ --region $ATHENS_REGION \ --allow-unauthenticated \ --set-env-vars=ATHENS_STORAGE_TYPE=gcp \ --set-env-vars=GOOGLE_CLOUD_PROJECT=$GOOGLE_CLOUD_PROJECT \ --set-env-vars=ATHENS_STORAGE_GCP_BUCKET=$GCS_BUCKET \ athens
Once this command finishes is will provide a url to your instance, but you can always find this through the cli:
$ gcloud beta run services describe athens --platform managed --region $ATHENS_REGION | grep hostname