Last active
December 4, 2019 07:08
-
-
Save Weiyuan-Lane/4313f746a088094918a97107a2800b49 to your computer and use it in GitHub Desktop.
No more GUI for GCP speedrun! CLI is enough!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
project=$1 | |
billingId=$2 | |
# Create Project | |
gcloud projects create $project | |
# Variables to be used later on | |
projectId=`gcloud projects list --format="get(projectNumber)" --limit=1 --filter="projectId=$project"` | |
gaeRegion="us-central" | |
cloudRunRegion="us-central1" | |
# Attach billing account | |
gcloud beta billing projects link $project --billing-account=$billingId >> /dev/null 2>&1 | |
# Enable required APIs (Todo, add cloud run) | |
gcloud services enable run.googleapis.com appengine.googleapis.com cloudbuild.googleapis.com iam.googleapis.com \ | |
--project $project | |
# Attach IAM roles to Cloud Build service account | |
ROLES=(appengine.appAdmin appengine.serviceAdmin run.admin serverless.serviceAgent) | |
for role in "${ROLES[@]}"; do | |
gcloud projects add-iam-policy-binding $project \ | |
--member=serviceAccount:"$projectId@cloudbuild.gserviceaccount.com" \ | |
--role roles/$role \ | |
--project=$project | |
done | |
# Enable AppEngine | |
gcloud app create --region $gaeRegion --project $project | |
# Set config for Cloud Run | |
gcloud config set run/platform managed --project $project | |
gcloud config set run/region $cloudRunRegion --project $project | |
# Trigger CICD pipeline from CLI | |
gcloud builds submit . --config "cloudbuild.yaml" --project $project |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment