Run Libretto workflows as Cloud Run Jobs, triggered from your API or a scheduler.Cloud Run Jobs are GCP’s managed container runtime for one-shot tasks. Each invocation spins up a fresh container, runs your workflow to completion, and exits. That’s a good fit for browser automations that take minutes rather than seconds.
Prerequisites
- A GCP project with billing enabled.
- Artifact Registry, Cloud Run, Cloud Build, and Secret Manager APIs enabled.
- A service account with access to the secrets your workflows need.
gcloudinstalled and authenticated locally.
Write a dispatcher entry point
A single image should be able to run any workflow in your package. The simplest way is a small Wire it up in
src/main.ts that reads two env vars (which workflow to run, and its JSON input) then calls into the workflow directly:package.json:Write the Dockerfile
Start from the official Playwright image so Chromium and all its dependencies are already present. The rest installs Add a
pnpm, copies your source, and hands off to the dispatcher on start:.dockerignore at the repo root so local state doesn’t leak into the image:Define the Cloud Run Job
Describe the job declaratively so you can version it alongside your code. The shape below matches what The
gcloud run jobs replace emits after you create a job through the console or CLI:serviceAccountName is what grants the job permission to read secrets, write to GCS, and so on. Scope it tightly.Inject credentials at runtime
Never bake credentials into the image. Read them from Secret Manager inside your workflow dispatcher:Grant the job’s service account
roles/secretmanager.secretAccessor on each secret it needs:Trigger the job
From your API (service-to-service), pass the workflow name and input as env var overrides so the dispatcher picks them up:From the CLI for ad-hoc runs:
Observability
- Logs:
gcloud logs read browser-agent-job —region=us-central1 - Execution history:
gcloud run jobs executions list —job=browser-agent-job —region=us-central1 - Session logs: upload
.libretto/sessions/<name>/logs.jsonlto GCS at the end of each run if you want to keep them beyond the job’s lifetime.