A new Gitpod template for Google Cloud

Jean-Phi Baconnais - Apr 12 '23 - - Dev Community

📚 My projects on Google Cloud Platform

Some of my projects are deployed on Google Cloud Platform. Mainly in Java, I deployed a lot of functions on Cloud function. This service is so useful for quickly deploying a short function in the cloud. Sometimes I also deploy applications with App engine, it scans your application, detects the language and deploys it without any configuration. Handy for deploying a component without creating and configuring any Docker file.
Since 2019, another service has been created, its Cloud Run. This serverless platform allows you to deploy containers easily. Before 2022, I only used it for one test.

🚀 The discovery of Cloud Seed

In 2022, I discovered Cloud Seed, a new GitLab project whose objective is to deploy faster on GCP. If you don’t know Cloud Seed, I suggest you read my Cheatsheet I created last year.

Gitpod Cheatsheet

I explain this project in the programmez.com magazine (in French) and in a blog post that will be published at the end of April on Zenika’s blog.

With the Cloud Seed project, I migrated some of my applications to Cloud Run.

🧩 Cloud code, a VsCode extension for GCP

Last year, during an event organized by Zenika and Google, Julien Landuré presented Cloud Code, a project available as an extension on VsCode and Intellij.

With this one, you can easily see your Cloud Run services, check their configuration and open logs without leaving your IDE. Great!

Cloud code in VsCode

🍑 My daily use with Gitpod

And as you may already know, I often use Gitpod to develop. It's a Cloud Development Environment. I will not explain in this blog post what Gitpod is, I will let you read this cheatsheet and this video I made for the Gitpod event in Paris in January.

Gitpod Cheatsheet

⚙️ A Google Cloud template for Gitpod

Every time I open a project in Gitpod, I have to install the gcloud CLI, configure it with the secret of my GCP project. Do these steps once in a while, why not, but several times a day, it’s so boring.

With Gitpod, we can use the .gitpod.yml file to configure our workspaces.

How do this ?

First step, the gcloud installation. As we can see on the Google documentation, gcloud can be installed with a curl command and the execution of a sh script :

curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-394.0.0-linux-x86_64.tar.gz
tar -xf google-cloud-cli-394.0.0-linux-x86_64.tar.gz
./google-cloud-sdk/install.sh
Enter fullscreen mode Exit fullscreen mode

To get a “gcloud” command available, I created an alias : alias gcloud=/workspace/google-cloud-sdk/bin/gcloud

The last step is the authentication of your project. To avoid setting your service key on the project and visible to all, a good way is to define and set variables on your Gitpod profile.

Gitpod Variables

After doing that, you can use it to initialize a json file with this command : echo $GCP_SERVICE_KEY | base64 -d > .gcloud-conf.json.
This file should not be published on GitLab, it’s added on the .gitignore file.

With this file, you can authenticate and configure the project saved also in your Gitpod variable :

gcloud auth activate-service-account --key-file .gcloud-conf.json
gcloud config set project $GCP_PROJECT
Enter fullscreen mode Exit fullscreen mode

If you are interested in this configuration, you can find it on this repository. It’s an open source project, so feel free to comment or add any suggestion.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .