Install on Google Cloud Run

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.

Selecting a Storage Provider

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.

Before You Begin

This guide assumes you have completed the following tasks:

  • Signed up for Google Cloud
  • Installed the gcloud command line tool
  • Installed the beta plugin for the gcloud command line tool (this is how to set it up)
  • Created a (GCS) bucket for your go modules

Setup a GCS Bucket

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

Setup

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
$ gcloud auth login
$ gcloud auth configure-docker

You will then need to push a copy of the Athens docker image to your google cloud container registry.

Below is an example using v0.11.0, for the latest version, check out the latest Athens release

$ docker pull gomods/athens:v0.11.0

$ docker tag gomods/athens:v0.11.0 gcr.io/$GOOGLE_CLOUD_PROJECT/athens:v0.11.0

$ docker push gcr.io/$GOOGLE_CLOUD_PROJECT/athens:v0.11.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.11.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
Fork me on GitHub