Google Cloud Run Automation

Hi out there!

I'm trying to build a CI/CD pipeline from JetBrains Space to Google Cloud Platform. 

Basically I just need to build and then deploy a Docker image, but I am totally lost in the specifics of the *.kts DSL (I'm coming from YAML-based GitHub Actions).

Could you please provide me with some guidance on how to wrap up two commands and set the pipeline up?

When deploying manually from my machine I simply use these two commands one right after another and it's done:

1. Builds an image and submits to Google Cloud Docker Registry

gcloud builds submit --tag gcr.io/PROJECT-ID/helloworld

2. Deploys the image to the bucket

gcloud run deploy --image gcr.io/PROJECT-ID/helloworld --platform managed

Source: https://cloud.google.com/run/docs/quickstarts/build-and-deploy#node.js

5
2 comments

2 years later and not a single comment to help?

I guess Space is not very friendly to Google Cloud Platform or the Go language. 

Since I can find ZERO documentation on building a Go program or deploying to Google Cloud Platform/Google App Engine Standard.

0

Hey Jarrod,

I managed to build my own CI/CD pipeline using traditional shell scripts rather than these fancy KotlinScript automations
Hers is what your sample code would look like to build an image, push it to gcr.io and then deploy it to GKE k8s cluster (however, you can replace this step and deploy to App Engine or Cloud Run):

.space.kts

/**
* JetBrains Space Automation
* This Kotlin-script file lets you automate build activities
* For more info, see https://www.jetbrains.com/help/space/automation.html
*/

job("build and deploy: testing") {
startOn {
gitPush {
branchFilter {
+"refs/heads/testing"
}
}
}

container(displayName = "Google Cloud SDK", image = "google/cloud-sdk:latest") {

env["GCP_ENVIRONMENT"] = "testing"
env["GCP_SA_KEY"] = Secrets("gcp_sa_key")
env["GCP_SA_NAME"] = Params("gcp_sa_name")
env["GCP_PROJECT"] = Params("gcp_project")
env["GCP_REGION"] = Params("gcp_region")

shellScript {
content = """
printf "%s" "${'$'}GCP_SA_KEY" > ./gcloud.json
sh ./deployment.sh \
${'$'}JB_SPACE_GIT_REPOSITORY_NAME \
${'$'}GCP_ENVIRONMENT \
${'$'}GCP_SA_NAME \
${'$'}GCP_PROJECT \
${'$'}GCP_REGION \
${'$'}JB_SPACE_EXECUTION_NUMBER
"""
}
}
}
 

 

 

And the deployment.sh file

set -e

SERVICE_NAME="$1"
ENVIRONMENT="$2"
GCP_SA_NAME="$3"
GCP_PROJECT="$4"
GCP_REGION="$5"
BUILD_NUMBER="$6"

echo "----------------------------------------------------------------"
echo "\nProject name: $SERVICE_NAME \nBranch: $ENVIRONMENT"
echo "\nProject ID: $GCP_PROJECT \nRegion: $GCP_REGION"
echo "----------------------------------------------------------------"

# Setting up authentication for GKE v1.26
# Read more: https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke)
export USE_GKE_GCLOUD_AUTH_PLUGIN=True

echo "\nActivate service account..."
gcloud auth activate-service-account \
--key-file=./gcloud.json\
--project=$GCP_PROJECT

echo "\nConfigure gcloud cli..."
gcloud config set account $GCP_SA_NAME
gcloud config set project $GCP_PROJECT

echo "\nBuild image..."
gcloud builds submit --tag gcr.io/$GCP_PROJECT/$SERVICE_NAME --timeout=30m || true

echo "\nDeploy to Google Kubernetes Engine..."
gcloud container clusters get-credentials $ENVIRONMENT --region "$GCP_REGION"
kubectl apply -f k8s/$ENVIRONMENT/
kubectl rollout restart statefulset $SERVICE_NAME-deployment

echo "----------------------------------------------------------------"
echo "\nSuccessfully deployed $SERVICE_NAME version-0.$BUILD_NUMBER-$ENVIRONMENT"
echo "----------------------------------------------------------------"

 

0

Please sign in to leave a comment.