Skip to main content

Deploy to Google Cloud Run with Dagger


This documentation is for an older version of Dagger, which is no longer actively maintained.

We encourage you to upgrade and refer to the documentation for the most current version.

If you cannot upgrade to the latest version, please contact us in the help forum on Discord. When contacting us, please let us know why you cannot move to the latest version. From there, our team will work with you on your use case.

This tutorial illustrates how to use Dagger to build, push and deploy Docker images to Cloud Run.

Initialize a Dagger Project and Environment

(optional) Setup example app

You will need the local copy of the Dagger examples repository used in previous guides

git clone

Make sure that all commands are being run from the todoapp directory:

cd examples/todoapp

Organize your package

Let's create a new directory for our Cue package:

mkdir gcpcloudrun

Create a basic plan

package gcpcloudrun

import (

// Source code of the sample application
src: dagger.#Artifact & dagger.#Input

// GCR full image name
imageRef: string & dagger.#Input

image: docker.#Build & {
source: src

gcpConfig: gcp.#Config

creds: gcr.#Credentials & {
config: gcpConfig

push: docker.#Push & {
target: imageRef
source: image
auth: {
username: creds.username
secret: creds.secret

deploy: cloudrun.#Service & {
config: gcpConfig
image: push.ref

Set up the environment

Create a new environment

Let's create a project:

dagger init

Let's create an environment to run it:

dagger new 'gcpcloudrun' -p ./gcpcloudrun

Configure user inputs

dagger input dir src . -e gcpcloudrun
dagger input text todoapp -e gcpcloudrun
dagger input text imageRef<your-project>/todoapp -e gcpcloudrun
dagger input text gcpConfig.region us-west2 -e gcpcloudrun
dagger input text gcpConfig.project <your-project> -e gcpcloudrun
dagger input secret gcpConfig.serviceKey -f ./gcp-sa-key.json -e gcpcloudrun


Now that everything is set correctly, let's deploy on Cloud Run:

dagger up -e gcpcloudrun