Visual Studio Code, Google Cloud Run and Multipass
I recently wrote a story about how using Canonical’s
multipass can provide a WSL-like isolated development environment on MacOS and Linux. I am a rather big fan of simple deployment and CI/CD, hence wanted to see if I could integrate Google Cloud Run deployment through Visual Studio Code on Multipass. Good news is that it is actually quite painless.
If you haven’t read my primer on getting set up with Multipass yet, head over to here and check it out. Also, this guide assumes you have already created a working Google Cloud Run deployment, if not, have a look at this guide by Google. Once you have all of these components set up, let’s look at how we can configure a simple CI/CD pipeline using Visual Studio Code and Cloud Run.
First things first, launch a Visual Studio Code Remote SSH connection to your Multipass virtual machine. Then we need to install an extension to the remote instance, called Google Cloud Code. Cloud Code makes interacting with Google Cloud Run through Visual Studio Code extremely simple. Install the extension, and authenticate yourself with your Google Cloud project accordingly. The great thing about installing this remotely (within the VM) is that the configuration and credentials are unique to that Multipass instance. No more re-authenticating necessary!
Once this is setup, we need to install Docker in the Multipass instance, so that Cloud Code can build your project and deploy it to Google Cloud Platform. There are a few commands that we need to run here:
$ sudo apt-get update
$ sudo apt-get install \
software-properties-common$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Once Docker has been installed, we need to do one last step that if not performed, will cause permissions errors when connecting to Docker’s build socket.
sudo chmod 666 /var/run/docker.sock
We can now restart the Docker daemon:
sudo systemctl restart docker
Now the machine has been configured to use Cloud Run with the correct credentials, and has a Docker build engine set up, we can proceed to deploy our application through the Cloud Code extension.
Simply click the Cloud Code tab at the bar at the bottom of Visual Studio Code:
This will guide you through the project to deploy to. Click Begin Deployment to deploy.