Developing your service

This page describes a few things you need to know to get started in developing a service for Cloud Run.

Code requirements

You must meet the following requirements when you develop a service:

  • The service must listen for requests. You can configure the port on which requests are sent. Inside Cloud Run instances, the value of the PORT environment variable always reflects the port to which requests are sent. Your code should check for the existence of this PORT environment variable and if it is present, should listen on it to maximize portability.
  • The service must be stateless. It cannot rely on a persistent local state.
  • If the service performs background activities outside the scope of request handling it must use the instance-based billing setting in order to have CPU allocated outside of the standard request cycle.
  • If your service uses NFS, it must use the second generation execution environment.

You can find more details about these constraints in the Container runtime contract.

Programming language support

Cloud Run source deployment conveniently supports multiple language runtimes, each of which is available through container base images provided by Google Cloud's buildpacks. You can also use other programming languages or frameworks, as long as the source code is in an OCI-compliant image.

The build and deploy quickstarts provides samples in many popular languages.

Using a web server

You can use a web server to listen on the required port, and to process and route incoming requests. For example, Node.js developers can use Express.js, Python developers can use Flask, Ruby developers can use Sinatra, and so forth.

Containerizing your code

See Containerize your code for details.

Design Cloud Run apps with Gemini assistance

You can get AI-powered help from Gemini Cloud Assist chat to design applications optimally. With Gemini Cloud Assist, you can discover the most suitable configurations and strategies for deploying your applications on Cloud Run, ensuring efficient resource utilization and seamless operation.

To use Gemini Cloud Assist from the Google Cloud console, do the following:

  1. Ensure that Gemini Cloud Assist is set up for your Google Cloud user account and project.

  2. Set up your Cloud Run development environment in your Google Cloud project and ensure you have the appropriate deployment permissions.

  3. Go to the Cloud Run page in the Google Cloud console.

    Go to Cloud Run

  4. In the console toolbar, select a Google Cloud project. Use a project associated with a project ID you submitted after you were granted access to Gemini Cloud Assist.

  5. Click spark Open or close Gemini AI chat.

    The Gemini panel opens.

  6. If necessary, click Accept if you agree to the terms.

  7. If you have a question about a specific application, provide context by going to the page that shows your resource before asking your question. When generating a response, Gemini includes information about the current console page and project.

  8. Enter a prompt in the Gemini panel.

    The following table provide some example prompts for using Gemini Cloud Assist with Cloud Run.

For more details, see the following resources:

What's next