diff --git a/Makefile b/Makefile index 7043a8e8..724f9f17 100644 --- a/Makefile +++ b/Makefile @@ -113,3 +113,7 @@ dev-teardown: .PHONY: help help: ## display help page @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: deploy-gae +deploy-gae: + cd scripts/gae && gcloud app deploy diff --git a/docs/content/install/install-on-gae.md b/docs/content/install/install-on-gae.md new file mode 100644 index 00000000..72e5e206 --- /dev/null +++ b/docs/content/install/install-on-gae.md @@ -0,0 +1,51 @@ +--- +title: "Install on Google App Engine" +date: 2019-09-27T17:48:40+10:00 +draft: false +weight: 4 +--- + +[Google App Engine (GAE)](https://cloud.google.com/appengine/) is a Google service allows applications to be deployed without provisioning the underlying hardware. It is similar to Azure Container Engine which is covered in a [previous section](/install/install-on-aci). This guide will demonstrate how you can get Athens running on GAE. + +## 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](https://cloud.google.com/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](https://cloud.google.com/sdk/install) command line tool + +### Setup a GCS Bucket + +If you do not already have GCS bucket you can set one up using the [gsutil tool](https://cloud.google.com/storage/docs/gsutil). + +First select a [global region](https://cloud.google.com/about/locations/?tab=americas) 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. + +```console +$ gsutil mb -l europe-west-4 gs://some-bucket +``` + +## Setup + +First clone the Athens repository + +```console +$ git clone https://github.com/gomods/athens.git +``` + +There is already a Google Application Engine scaffold set up for you. Copy it into a new file and make changes to the environment variables. + +```console +$ cd athens +$ cp scripts/gae/app.sample.yaml scripts/gae/app.yaml +$ code scripts/gae/app.yaml +``` + +Once you have configured the environment variables you can deploy Athens as a GAE service. + +```console +$ make deploy-gae +``` diff --git a/docs/content/install/install-on-google-cloud-run.md b/docs/content/install/install-on-google-cloud-run.md new file mode 100644 index 00000000..f5c72a8e --- /dev/null +++ b/docs/content/install/install-on-google-cloud-run.md @@ -0,0 +1,71 @@ +--- +title: "Install on Google Cloud Run" +date: 2019-10-10T18:16:43+11:00 +draft: false +weight: 4 +--- + +[Google Cloud Run](https://cloud.google.com/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](https://knative.dev/) project. Deploying using Cloud Run is similar to deploying using [Google App Engine](/install/install-on-gae) 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](https://cloud.google.com/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](https://cloud.google.com/sdk/install) command line tool +- Installed the beta plugin for ghe gcloud command line tool ([this is how to set it up](https://cloud.google.com/run/docs/setup)) +- 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](https://cloud.google.com/storage/docs/gsutil). + +First select a [region](https://cloud.google.com/about/locations/?tab=americas) 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. + +```console +$ 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](https://cloud.google.com/about/locations/?tab=americas) 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.. + +```console +$ 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. + +```console +$ 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. + +```console +$ 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: + +```console +$ gcloud beta run services describe athens --platform managed --region $ATHENS_REGION | grep hostname +``` diff --git a/scripts/gae/.gitignore b/scripts/gae/.gitignore new file mode 100644 index 00000000..742f0087 --- /dev/null +++ b/scripts/gae/.gitignore @@ -0,0 +1 @@ +app.yaml \ No newline at end of file diff --git a/scripts/gae/Dockerfile b/scripts/gae/Dockerfile new file mode 100644 index 00000000..6326b014 --- /dev/null +++ b/scripts/gae/Dockerfile @@ -0,0 +1 @@ +FROM gomods/athens:v0.6.0 \ No newline at end of file diff --git a/scripts/gae/app.sample.yaml b/scripts/gae/app.sample.yaml new file mode 100644 index 00000000..36571535 --- /dev/null +++ b/scripts/gae/app.sample.yaml @@ -0,0 +1,44 @@ +# General settings +runtime: custom +env: flex +service: athens + +# Network settings +network: + instance_tag: athens + forwarded_ports: + - 3000/tcp + +# Compute settings +resources: + cpu: 1 + memory_gb: 0.6 + disk_size_gb: 100 + +# Health and liveness check settings +liveness_check: + path: "/healthz" + check_interval_sec: 30 + failure_threshold: 2 + success_threshold: 2 + +readiness_check: + path: "/readyz" + check_interval_sec: 5 + failure_threshold: 2 + success_threshold: 2 + app_start_timeout_sec: 10 + +# Scaling instructions +automatic_scaling: + min_num_instances: 1 + max_num_instances: 15 + cool_down_period_sec: 180 + cpu_utilization: + target_utilization: 0.6 + +# Environment variables configuring athens +env_variables: + ATHENS_STORAGE_TYPE: gcp + GOOGLE_CLOUD_PROJECT: GOOGLE_CLOUD_PROJECT + ATHENS_STORAGE_GCP_BUCKET: ATHENS_STORAGE_GCP_BUCKET