
In a preview post, I mentioned a 4th way to deploy to Cloud Run that skips the build. In today’s post, let’s talk about sending an entire binary to Cloud Run using the os-only image. The provided binaries are inserted into the os-only image, which is what Cloud Run uses.
Here’s what it looks like in the revision.

For more information, check out the Cloud Run documentation for no build deployments.
Example
This example below shows you how to build a Go microservice that accepts an image upload, applies a grayscale filter, and returns the modified image. You’ll build the microservice locally first. And then you’ll deploy the resulting binary to Cloud Run.
Step 1: The Go Code (main.go)
Create a file named main.go and drop in this code. It sets up a single /process endpoint to catch POST requests, decodes the image, converts the pixels, and encodes it back to JPEG.
package main
import (
"image"
"image/color"
"image/jpeg"
_ "image/png" // Allows decoding of PNG uploads
"log"
"net/http"
"os"
)
func processImage(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Only POST requests allowed", http.StatusMethodNotAllowed)
return
}
// Decode the uploaded image
img, _, err := image.Decode(r.Body)
if err != nil {
http.Error(w, "Failed to decode image", http.StatusBadRequest)
return
}
// Apply a pure-math grayscale filter
bounds := img.Bounds()
grayImg := image.NewGray(bounds)
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
grayImg.Set(x, y, color.GrayModel.Convert(img.At(x, y)))
}
}
// Return the newly processed JPEG
w.Header().Set("Content-Type", "image/jpeg")
jpeg.Encode(w, grayImg, &jpeg.Options{Quality: 90})
}
func main() {
http.HandleFunc("/process", processImage)
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Printf("Listening on port %s...", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}
Step 2: The Local Compile
Initialize your Go module and compile the binary specifically for Cloud Run’s Linux architecture.
go mod init image-processor
GOOS=linux GOARCH=amd64 go build -o server main.go
Step 3: The “Zip and Ship” Deploy
Push the compiled binary directly to the osonly24 base image without building a container.
gcloud beta run deploy image-processor \
--source . \
--no-build \
--base-image osonly24 \
--command ./server
Step 4: Test the service
Get the Service URL
SERVICE_URL=$(gcloud run services describe [SERVICE_NAME] \
--region=[REGION] \
--format="value(status.url)")
And send a photo to be grayscaled!
curl -X POST --data-binary "@pelican.jpg" \
$SERVICE_URL/process \
> grayscale-output.jpg
you should see a result similar to this… provided you are as obsessed with taking photos of pelicans like I am.

How to deploy your binary code 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/how-to-deploy-your-binary-code-to-cloud-run-while-skipping-the-build-7bfbfe0e3ee7?source=rss—-e52cf94d98af—4
