GCP – Streamlining Cloud Run development with Cloud Code
Editor’s note: At Google Cloud Next ‘20: OnAir, we announced several new features and services to help you accelerate your application delivery and development processes, as well as the Cloud Application Modernization Platform, or CAMP. Over the next couple of months, we’re diving deep into those announcements, covering everything from developer productivity, security and compliance, operational best practices and hybrid and multi-cloud. Stay tuned!
When developing services for Cloud Run, our fully managed container compute platform, chances are you find yourself moving back and forth between your code editor, terminal, and the Google Cloud Console. In addition to all that context switching, you probably run the same commands over and over each time you deploy those services. Cloud Code is a set of tools that has everything you need to write, debug, and deploy your cloud-native applications. It’s designed to make cloud-native development on Google Cloud more productive, with plugins for popular IDEs like VS Code and IntelliJ. And now, Cloud Code makes it easy to develop with Cloud Run by incorporating common workflows with your favorite IDE’s user interface.
Specifically, this new integration between Cloud Run and Cloud Code makes it easier to create new Cloud Run services in your IDE. Run, rapidly iterate on, and debug these services on your local machine, and then deploy them to Cloud Run. Then, once they’re running, it also helps you manage and update those Cloud Run services. Let’s take a closer look.
Create new Cloud Run services
Learning about containerization and serverless services can be overwhelming at first. If you’re new to Cloud Run, we’ve updated the Cloud Code built-in samples list with Cloud Run samples. Available in Java, NodeJS, Python, Go, and .NET languages, these samples give you a working base to build on, showing you best practices and easing the learning curve so you can jump right in to coding your service.
All our samples include a Dockerfile so you don’t have to spend time figuring out container configurations. If you’re bringing an existing service to Cloud Run, you may not be familiar with Dockerfiles. Not to worry! Cloud Code has built-in support for Google Cloud Buildpacks which containerize the service directly from code — no Dockerfile needed! Cloud Code ensures you have everything you need to deploy your service to Cloud Run.
Develop and debug Cloud Run services locally
Before deploying your service to Google Cloud, you probably want to try it out on your own machine to see what it does, make desired changes, and debug issues. When developing Cloud Run services, you have to constantly build and deploy to the cloud to test your latest changes in a representative Cloud Run environment. While you can debug your code locally by attaching debuggers, this is usually scoped to your code, not your entire container, meaning you need to install tooling locally. You can run your container locally with Docker, but the command is long and isn’t representative of a production environment.
Cloud Code now sets up a Cloud Run emulator for you so you can develop and debug your Cloud Run services locally. According to research conducted by DevOps Research and Assessment (DORA), teams that scored high regarding software delivery performance have change failure rates 7x lower compared to non-high performing teams. Having the ability to rapidly iterate on your code locally and debug it in a representative environment allows you to find errors faster and earlier in the development process, so you don’t discover them during CI, or worse, production.
When you run your code with the Cloud Run emulator, you have the option of turning on watch mode. Every time you save your files, your service is redeployed to the emulator, enabling continuous development.
Debugging your Cloud Run services with Cloud Code gives you the same debugging experience you’re used to with your IDE. When running the “Debug on Cloud Run Emulator” command in VS Code (or if you’re using IntelliJ, when you select the “Cloud Run: Run Locally” configuration then Debug”), simply place breakpoints in the margins of your code. Once you trigger a breakpoint in your container, you can step through statements, hover over variable properties, and check out the logs from your container.
Deploy your service to Cloud Run
Once you’ve tested the code changes you’ve made to your Cloud Run service locally, you’ll want to build your container and deploy your service to Cloud Run.
Deploying the service right from your IDE couldn’t be simpler once your Cloud Run service is ready. We’ve included all the options you need to appropriately configure your service for deployment. When you click “Deploy”, Cloud Code runs all the necessary commands to build your container image, deploy that image to Cloud Run, and return the URL to your service.
Manage Cloud Run services
Cloud Code makes viewing logs for each revision simpler by giving you access to revision and service logs with one click in VS Code. We’ve brought this functionality from the Cloud Console to your IDE to limit context switching between the two. The Logs Viewer focuses specifically on the Cloud Run service or revision you select from the Cloud Run explorer.
The Cloud Run explorer also lets you quickly view the details for all your project’s Cloud Run fully managed and Cloud Run for Anthos services. You can also easily access the percentage of traffic redirection and CPU allocation from the Cloud Run explorer.
By right clicking on your revisions, you can quickly access the URL of your service, or head to the Cloud Console to view your traffic or adjust traffic redirections between services.
Get started
We invite you to try out Cloud Run with Cloud Code to better streamline your deployment and logging workflows. To learn more, check out the Cloud Run documentation for Visual Studio Code and JetBrains IDEs. If you’re new to development with IDEs, you can take the first step by installing Visual Studio Code or IntelliJ.
Read More for the details.