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.
With the Cloud Seed project, I migrated some of my applications to Cloud Run.
With this one, you can easily see your Cloud Run services, check their configuration and open logs without leaving your IDE. Great!
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.
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
To get a “gcloud” command available, I created an alias :
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.
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
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.