gcloud run deploy defaults to source deployment if you don't supply
Behind the scenes, this command uses Google Cloud
buildpacks and Cloud Build to
automatically build container images from your source code without having to
install Docker on your machine or set up buildpacks or Cloud Build. That
is, the single command described above does what would otherwise require the
gcloud builds submit
gcloud run deploy commands.
Note that source deployments use Artifact Registry to
store built containers. If your project doesn't already have an Artifact Registry
repository with the name
cloud-run-source-deploy in the region you are
deploying to, this feature automatically creates an Artifact Registry
repository with the name
If a Dockerfile is present in the source code directory, the uploaded source code is built using that Dockerfile. If no Dockerfile is present in the source code directory, Google Cloud buildpacks automatically detects the language you are using and fetches the dependencies of the code to make a production-ready container image, using a secure base image managed by Google. (Each time you deploy, any needed security fixes are automatically picked up from the base image.)
In addition to sources with a Dockerfile, deploying from source supports the following languages:
- .NET Core
Read more details about supported language versions at the Google platforms buildpack repository.
Limitations of this feature
- Deploy from source uses Artifact Registry, so this feature is only available in regions supported by Artifact Registry.
- Deploying from source using
gcloud run deploy --sourceis a convenience feature, and does not allow full customization of the build. For more control, build the container image using Cloud Build, for example, using
gcloud builds submit, and then deploy the container image using, for example,
gcloud run deploy --image)
Before you start
Make sure you have set up a new project for Cloud Run as described in the setup page.
Permissions required to deploy
To deploy from source, you need permissions to build, store the built container image and deploy.
You must have ONE of the following:
- Owner role
- Editor role
The following set of roles:
To deploy from source code:
Change to your source directory. Note that the source directory doesn't require a Dockerfile, but if a Dockerfile is present it will be used.
Build and deploy your application:
gcloud run deploy SERVICE --source .
SERVICEwith the name you want for your service.
Respond to any prompts to install required APIs by responding
ywhen prompted. You only need to do this once for a project. Respond to other prompts by supplying the platform and region, if you haven't set defaults for these as described in the setup page.
Wait for the build and deploy to complete. When finished, a message similar to this one is displayed:
Service [my-app] revision [my-app-00000-xxx] has been deployed and is serving 100 percent of traffic. Service URL: https://my-app-texampleq-uc.a.run.app
Upon deployment, note that this service revision serves 100% of traffic.
Automating building from source
As a best practice for avoiding unversioned changes in local source, Google recommends that you automatically deploy when changes are pushed to your Git repository. To make this easier, you can connect and configure continuous deployment to your Cloud Run service. By connecting your GitHub repositories to Cloud Run, you can configure builds and deploy your repositories without writing Dockerfiles or build files.
To configure automated builds, set up automation as described in the continuous builds page, making sure you choose the option for building source with Buildpacks.
After you deploy a new service, you can do the following:
- Gradual rollouts, rollback revisions, traffic migration
- View service logs
- Monitor service performances
- Set memory limits
- Set environment variables
- Change service concurrency
- Manage the service
- Manage service revisions
You can automate the builds and deployments of your Cloud Run services using Cloud Build Triggers: