Accelerating Development for Cloud Run with Cloud Code

Accelerating Development for Cloud Run with Cloud Code

When developing services for a fully managed container platform Cloud Run, you will most likely get tired of constantly switching between the code editor, the terminal, and the Google Cloud Console. Moreover, you still have to run the same commands many times, with each deployment. CloudCode is a set of tools that includes everything you need to write, debug and deploy cloud applications. It improves the efficiency of Google Cloud development by using plugins for popular development environments such as VS Code and IntelliJ. With it, you can easily develop in Cloud Run. More details under the cut.

Cloud Run and Cloud Code integration makes it easy to create new Cloud Run services in your own development environment. You can run services on your local machine, quickly iterate and debug them, then deploy them to Cloud Run and easily manage and update them.

Note from the author. At the Google Cloud Next 2020 OnAir virtual conference, we announced several new features and services designed to accelerate the delivery and development of applicationsand Cloud platform for application modernization (Cloud Application Modernization Platform or CAMP).

Creating New Cloud Run Services

At first glance, containerization and serverless services may seem overly complex. If you're just getting started with Cloud Run, check out the updated list of Cloud Run examples in Cloud Code. The examples are available in Java, NodeJS, Python, Go, and .NET. Based on them, you can immediately start writing your own code, taking into account all the recommendations.

All examples include a Dockerfile so you don't have to spend time figuring out container configurations. If you are migrating an existing service to Cloud Run, then you may not have worked with Dockerfiles yet. It's OK! Cloud Code service has support Google Cloud Buildpack Objects, allowing you to containerize the service directly in the code. This does not require a Dockerfile. Cloud Code contains everything you need to deploy your service to Cloud Run.

Accelerating Development for Cloud Run with Cloud Code

Develop and debug Cloud Run services on-premises

Before deploying a service to Google Cloud, you'll likely want to try it out on your own machine to see how it works, make any necessary edits, and debug any bugs. When developing, Cloud Run services need to be constantly built and deployed to the cloud to test changes in a representative Cloud Run environment. It is also possible to debug code locally by attaching a debugger, however, since this is not done on a per-container basis, you will need to install the tools locally. You can run a container locally using Docker, but the command required to do this is too long and does not reflect the specifics of a production environment.

Cloud Code provides a Cloud Run emulator that allows you to develop and debug Cloud Run services locally. According to ExplorationAccording to a DevOps Research and Assessment (DORA) study, teams that performed well in delivering software were 7 times less likely to fail when making changes than teams that were less efficient. With the ability to quickly iterate code locally and debug it in a representative environment, you can quickly find bugs early in development rather than during continuous integration or, worse, in production.

When you run code in the Cloud Run emulator, you can enable view mode. Every time you save files, your service will be redeployed to the emulator for continuous development.

First launch of Cloud Run Emulator:
Accelerating Development for Cloud Run with Cloud Code

Debugging Cloud Run services with Cloud Code is the same as debugging in the development environment you are used to. Run "Debug on Cloud Run Emulator" in VS Code environment (or choose "Cloud Run: Run Locally" configuration and run "Debug" command in IntelliJ environment) and just set code breakpoints. Once a breakpoint is activated in your container, you will be able to switch between commands, hover over variable properties, and check logs from within the container.

Debugging Cloud Run service with Cloud Code in VS Code and IntelliJ idea:
Accelerating Development for Cloud Run with Cloud Code
Accelerating Development for Cloud Run with Cloud Code

Deploying a Service in Cloud Run

Once you've tested all the changes you've made to the code for the Cloud Run service on-premises, the next step is to create a container and deploy it to Cloud Run.

Deploying a service from a development environment is easy. We've added all the options you need to set up the service before deployment. When you click Deploy, Cloud Code will execute all required commands to create a container image, deploy it to Cloud Run, and pass the URL to the service.

Service Deployment in Cloud Run:
Accelerating Development for Cloud Run with Cloud Code

Cloud Run Service Management

With Cloud Code in VS Code, you can view version and service history with a single click. This feature has been moved from the Cloud Console to the development environment so you don't have to constantly switch. The browse page displays exactly the logs that are relevant to the versions and services selected in the Cloud Run Explorer.

Accelerating Development for Cloud Run with Cloud Code

You can also quickly find and view details of all managed Cloud Run services and Cloud Run services for Anthos in a given project using the Cloud Run Explorer. There you can also easily find out what percentage of traffic is being redirected and how much CPU resources are allocated.

Cloud Run explorer in VS Code and IntelliJ
Accelerating Development for Cloud Run with Cloud Code
Accelerating Development for Cloud Run with Cloud Code

By right-clicking on a version, you can view the URL of the service. In the Cloud Console, you can check the traffic or configure its redirection between services.

Beginning of work

We invite you to work with Cloud Code in Cloud Run to streamline your service deployment and logging processes. For more information, see the Cloud Run documentation for development environments Visual Studio Code ΠΈ JetBrains. If you haven't worked with these environments yet, first install Visual Studio Code or IntelliJ.

Join Google Cloud Next OnAir

I would also like to remind our readers that an online conference is taking place right now Google Cloud Next OnAir EMEA for which we have prepared content for both developers and solution architects and managers.

You can learn more about the sessions, speakers and access the content by registering for free at Next OnAir EMEA page. Along with the unique content that will be featured for Next OnAir EMEA, you will also get full access to over 250 sessions from the global part of Google Cloud Next '20: OnAir.

Source: habr.com

Add a comment