Introducing a single command to build and deploy to Cloud Run
Ahmet Alp Balkan
Senior Developer Advocate
Group Product Manager
Our vision for Cloud Run is simple: enable developers to run their source code on a fully managed autoscaling infrastructure with a domain name secured with HTTPS. But until now, deploying to Cloud Run required at least two separate steps:
Packaging your code into a container image
Deploying this container image to Cloud Run
Although container images have become an industry standard for packaging, deploying, and scaling software, not every developer wants to learn how containers work or how to build their apps (written in their favorite language) into a container image.
Today, we’re offering a convenient single command to build and deploy your code to Cloud Run:
gcloud beta run deploy --source=[DIRECTORY]
This command combines the power of Google Cloud Buildpacks, which let you automatically build container images from your source code, with Cloud Build, which builds container images remotely without having to install Docker on your machine.
This new experience supports two build modes; both happen remotely and neither requires Docker to be installed on your machine:
Dockerfileis present in the directory then uploaded source code will be built with it.
Dockerfileis present in the directory then buildpacks automatically detects the language you are using, fetches the dependencies of the code, and makes a production-ready container image out of it.
Then, build and deploy this application (which doesn't have a Dockerfile) with a single command:
This single command takes you from source code to a URL ready to receive production traffic using Cloud Run.
How does it work?
This new command is simply a shortcut for “
gcloud builds submit” and “
gcloud run deploy --image=[...]”.
In this case, our sample Python application does not have a Dockerfile. Buildpacks automatically determines that this is a Python application, then it determines the application’s dependencies from the
requirements.txt file. Finally, it looks at the
Procfile to determine how to start this Python server.
As part of this process, buildpacks chooses a secure base image for your container image. This way, you don’t have to worry about managing a base image, as it’s maintained actively by Google; your next deployment will automatically pick up security fixes if needed.
By running this command,
gcloud sends an on-demand build job that runs remotely on Cloud Build. As a developer, you don’t have to worry about having the tooling to build the container image locally, or how to transform your code into a container image.
In fact, if you are a developer who commonly runs “
docker build -t […]” followed by “
docker push”, you can simply replace your local Docker workflow with Cloud Build by running:
gcloud builds submit -t [...]
which builds and pushes the resulting image to Artifact Registry, without even having to run Docker locally on your machine.
Automate building from source
Deploying source code from your local machine is a great way to kick the tires, but not a best practice long term—the local source might contain unversioned changes. We recommend automatically deploying when changes are pushed to your Git repository. To help with that, we previously released a way to easily 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, while deploying a new Cloud Run service, choose “Continuously deploy new revisions from a source repository”, connect your repo, then choose the option for building source with Google Cloud Buildpacks:
After setting this up, changes pushed to the branch you configured will automatically be built on Cloud Build and deployed to Cloud Run securely. You can monitor the status and history of these builds right on the Google Cloud Console where you see your Cloud Run service.
We are excited to see you give this new feature a try and see how buildpacks automatically convert your application code into a container image that you can then deploy to Cloud Run. Maybe you don’t need that Dockerfile anymore! We’re eager to hear your feedback on the Google Cloud Buildpacks project via GitHub. To help shape the future of Cloud Run, participate in our research studies.