https://github.com/maxkrivich/cloudrun-example
Cloud Run example
https://github.com/maxkrivich/cloudrun-example
cloudrun gcp golang google-cloud-platform knative
Last synced: 3 months ago
JSON representation
Cloud Run example
- Host: GitHub
- URL: https://github.com/maxkrivich/cloudrun-example
- Owner: maxkrivich
- License: mit
- Archived: true
- Created: 2021-01-28T00:11:49.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-01-28T00:22:37.000Z (about 5 years ago)
- Last Synced: 2024-06-19T04:17:47.033Z (almost 2 years ago)
- Topics: cloudrun, gcp, golang, google-cloud-platform, knative
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cloud Run example
In this repo, you could find a simple example of a golang microservice that has been deployed on GCP Cloud Run. Cloud Run is built upon Knative and provides a high level of abstraction for deploying a container into either GKE or managed infrastructure by Google.


# How-to
Setup the project on the GCP
```bash
$ export PROJECT_ID=project-example
$ export ACCOUNT_NAME:=account-example
$ export SERVICE_NAME:=service-name
$ gcloud auth login
$ gcloud projects create $PROJECT_ID
$ gcloud config set project $PROJECT_ID
```
Enable Google APIs
```bash
$ gcloud services enable cloudbuild.googleapis.com run.googleapis.com containerregistry.googleapis.com
```
Create Service Accounts
```bash
$ gcloud iam service-accounts create dp_$ACCOUNT_NAME \
--description="Cloud Run deploy account" \
--display-name="Cloud-Run-Deploy"
$ gcloud iam service-accounts create rt_$ACCOUNT_NAME \
--description="Cloud Run runtime account" \
--display-name="Cloud-Run-Runtime"
$ gcloud projects add-iam-policy-binding $PROJECT_ID \
--member=serviceAccount:dp_$ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com \
--role=roles/run.admin
$ gcloud projects add-iam-policy-binding $PROJECT_ID \
--member=serviceAccount:dp_$ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com \
--role=roles/storage.admin
$ gcloud projects add-iam-policy-binding $PROJECT_ID \
--member=serviceAccount:dp_$ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com \
--role=roles/iam.serviceAccountUser
$ gcloud projects add-iam-policy-binding $PROJECT_ID \
--member=serviceAccount:rt_$ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com \
--role=roles/run.invoker
$ gcloud iam service-accounts keys create key.json \
--iam-account dp_$ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com
```
Deploy the container via CloudBuild
```bash
$ gcloud builds submit --config cloudbuild.yml --substitutions=_SERVICE_NAME=$SERVICE_NAME,_ACCOUNT_NAME=rt_$ACCOUNT_NAME
```
Deploy the container with buildpack
```bash
$ gcloud beta run deploy $PROJECT_ID --source .
```
## Links
https://github.com/ahmetb/cloud-run-faq
https://github.com/GoogleContainerTools/distroless
https://cloud.google.com/run/docs/how-to