
You have several ways to deploy to Cloud Run:
- give Cloud Run an image
- give Cloud Run your source code with a dockerfile
- give Cloud Run your source code without a dockerfile (uses buildpacks)
and now there’s a 4th way…
4. give Cloud Run with your files (binaries or source) and tell Cloud Run to skip the build.
Instead of building a container image from source, you can provide Cloud Run with a pre-packaged archive of your application. Cloud Run then runs this archive directly on a base image (e.g. nodejs24 or osonly24 — see full list here).
You should see dramatically faster deployment times.
Let’s see this in action…
Overview
Let’s deploy a Node.js Express app to Cloud Run in seconds by using the–no-build flag.
Because –no-build dynamically mounts your code at runtime, Cloud Run automatically uses the latest nodejs24 base image every time your container starts. In other words, you get automatic base image updates by default.
Step 1: Create the App
Initialize the project: Open a terminal and create a new directory for the app.
mkdir express-app && cd express-app
npm init -y
Create the code: Create an index.js file and paste in a basic Express server.
import express from 'express';
const app = express();
app.get('/', (req, res) => {
const name = process.env.NAME || 'World';
res.send(`Hello ${name}!`);
});
const port = parseInt(process.env.PORT) || 8080;
app.listen(port, () => {
console.log(`helloworld: listening on port ${port}`);
});
Create a package.json file
{
"name": "helloworld",
"description": "Simple hello world sample in Node",
"version": "1.0.0",
"private": true,
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index.js"
},
"engines": {
"node": ">=16.0.0"
},
"author": "Google LLC",
"license": "Apache-2.0",
"dependencies": {
"express": "^5.2.1"
}
}
Step 2: Install your Local Dependencies
Since you are skipping Cloud Build, Google will not run npm install in the cloud. Your node_modules folder must exist locally so it can be zipped and sent to Cloud Run.
Install your dependencies locally:
npm install
Step 3: The Initial Deploy
Deploy the app to Cloud Run with the –no-build flag.
Note the –command and –args flags. These flags replace the ENTRYPOINT and CMD instructions you would normally have to put into a Dockerfile.
Run this command and make sure to watch the deployment time…
gcloud beta run deploy hello-no-build \
--source . \
--no-build \
--base-image nodejs24 \
--command node \
--args index.js \
--allow-unauthenticated
Step 4: “Fast Follow” with a Bug Fix
Let’s now make a change…
Open your index.js and change the response text to something new, like “let’s go!” and save the file.
Now deploy again running the same gcloud beta run deploy command from Step 3.
Watch the deployment time… it only takes seconds to have your new changes up and running.
Next time
We’ll look at deploying a binary on the os-only base image.
Deploy to Cloud Run while skipping the build was originally published in Google Cloud – Community on Medium, where people are continuing the conversation by highlighting and responding to this story.
Source Credit: https://medium.com/google-cloud/deploy-to-cloud-run-while-skipping-the-build-bac860380460?source=rss—-e52cf94d98af—4
