You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(hosting-cli): use cloudbuild.yaml instead of symlinks for gcp deploy
The Dockerfile no longer touches disk anywhere near the user's source —
it's embedded (base64) as an inline `docker build` step inside a Cloud
Build config written to a tempfile, and the flexgen script's
`gcloud builds submit --tag X .` invocation is rewritten in-memory to
`--config="${REFLEX_CLOUDBUILD_YAML}" --substitutions=_IMAGE="${IMAGE}"`.
The script runs with cwd = the user's source dir, so the user's tree is
the Cloud Build upload context. No temp dir of symlinks, no source-tree
mutation. The cloudbuild.yaml tempfile is removed after the deploy.
If `gcloud builds submit` can't be located in the manifest's script
(format drift on flexgen's side), the rewrite errors out clearly so the
breakage surfaces immediately rather than half-running.
Verified end-to-end against a real GCP project: 1m53s Cloud Build, new
Cloud Run revision deployed and serving traffic, source Dockerfile
timestamp unchanged, tempfile cleaned up.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/hosting/deploy-to-gcp.md
+14-13Lines changed: 14 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ import reflex as rx
4
4
5
5
# Deploy to GCP Cloud Run
6
6
7
-
The `reflex cloud deploy --gcp` command deploys a Reflex app to your own [Google Cloud Run](https://cloud.google.com/run) service. Reflex Cloud fetches a Cloud Run-ready Dockerfile and a `gcloud` deploy script, writes the Dockerfile into your project, and runs the script against the Google Cloud project you specify. The image is built on Cloud Build (so it works from any host OS, including Apple Silicon) and pushed to Artifact Registry.
7
+
The `reflex cloud deploy --gcp` command deploys a Reflex app to your own [Google Cloud Run](https://cloud.google.com/run) service. Reflex Cloud fetches a Cloud Run-ready Dockerfile and a `gcloud` deploy script, wraps the Dockerfile inside a [Cloud Build config (`cloudbuild.yaml`)](https://cloud.google.com/build/docs/build-config-file-schema), and runs the script against the Google Cloud project you specify. The image is built on Cloud Build (so it works from any host OS, including Apple Silicon) and pushed to Artifact Registry. Your project tree is never modified — the Dockerfile lives only inside the build config that's submitted to Cloud Build.
8
8
9
9
```md alert info
10
10
# Enterprise tier only.
@@ -40,9 +40,12 @@ reflex cloud deploy --gcp \
40
40
The CLI will:
41
41
42
42
1. Authenticate against Reflex Cloud and fetch the deploy manifest (Dockerfile + `gcloud` script).
43
-
2. Print the manifest so you can review it.
44
-
3. Write a `Dockerfile` into your project (after asking, if one already exists).
45
-
4. Ask for confirmation, then run the `gcloud` script: enable the required APIs, create the Artifact Registry repository, build the image on Cloud Build, and deploy a public Cloud Run service.
43
+
2. Generate a `cloudbuild.yaml` that embeds the Dockerfile as a build step, write it to a tempfile, and rewrite the script's `gcloud builds submit` invocation to use `--config="$REFLEX_CLOUDBUILD_YAML"`.
44
+
3. Print the (rewritten) script so you can review it.
45
+
4. Ask for confirmation, then run the script with `cwd=` your source directory: enable the required APIs, create the Artifact Registry repository, build the image on Cloud Build (which materializes the Dockerfile inside the build step from the `cloudbuild.yaml`), and deploy a public Cloud Run service.
46
+
5. Delete the tempfile after the script finishes.
47
+
48
+
Your source tree is never written to — if you have an existing `Dockerfile` in `--source`, it's left in place and ignored. The flexgen Dockerfile only exists inside the `cloudbuild.yaml` tempfile (and inside the Cloud Build job).
46
49
47
50
When it's done, you'll get a service URL like `https://my-reflex-app-<project-number>.us-central1.run.app`.
48
51
@@ -56,11 +59,10 @@ When it's done, you'll get a service URL like `https://my-reflex-app-<project-nu
56
59
|`--service-name`|`reflex-app`| Cloud Run service name. |
57
60
|`--ar-repo`|`reflex`| Artifact Registry repository name (created on first deploy). |
58
61
|`--version`| UTC timestamp (`YYYYMMDD-HHMMSS`) | Image version tag. |
59
-
|`--source`|`.`| Directory containing the Reflex app and into which the Dockerfile is written. |
60
-
|`--overwrite-dockerfile`|_off_| Overwrite an existing `Dockerfile` without prompting. |
62
+
|`--source`|`.`| Directory containing the Reflex app. Uploaded to Cloud Build as the build context; the source tree itself is not modified. |
|`--interactive / --no-interactive`|`--interactive`| Whether to prompt before overwriting the Dockerfile and running the script. |
63
-
|`--dry-run`|_off_| Print the manifestwithout writing the Dockerfile or running the script. |
64
+
|`--interactive / --no-interactive`|`--interactive`| Whether to prompt before running the deploy script. |
65
+
|`--dry-run`|_off_| Print the manifest, the generated `cloudbuild.yaml`, and the rewritten script without writing the tempfile or running the script. |
64
66
|`--loglevel`|`info`| Log verbosity. |
65
67
66
68
## What gets created in your GCP project
@@ -83,7 +85,7 @@ Re-running the command pushes a new image tag and rolls the Cloud Run service fo
83
85
84
86
The CLI runs the deploy script under a **restricted environment**. Only an explicit allowlist of host variables is forwarded to `bash` — things like `PATH`, `HOME`, `CLOUDSDK_*`, `DOCKER_*`, and proxy/TLS variables. Unrelated host secrets such as `AWS_*`, `GITHUB_TOKEN`, or arbitrary user variables are **not** forwarded, so a tampered or compromised manifest cannot exfiltrate them.
85
87
86
-
You can preview the exact script and Dockerfile before anything runs by using `--dry-run`:
88
+
You can preview the rewritten script, generated `cloudbuild.yaml`, and Dockerfile before anything runs by using `--dry-run`:
87
89
88
90
```bash
89
91
reflex cloud deploy --gcp \
@@ -93,18 +95,17 @@ reflex cloud deploy --gcp \
93
95
94
96
## Non-interactive use (CI)
95
97
96
-
For automated pipelines, pass `--no-interactive`, an explicit `--token`, and `--overwrite-dockerfile`:
98
+
For automated pipelines, pass `--no-interactive` and an explicit `--token`:
97
99
98
100
```bash
99
101
reflex cloud deploy --gcp \
100
102
--gcp-project "$GCP_PROJECT_ID" \
101
103
--service-name my-reflex-app \
102
104
--token "$REFLEX_TOKEN" \
103
-
--no-interactive \
104
-
--overwrite-dockerfile
105
+
--no-interactive
105
106
```
106
107
107
-
In non-interactive mode the CLI will not prompt — it will refuse to overwrite an existing `Dockerfile` unless `--overwrite-dockerfile` is set, and it will exit non-zero if a token cannot be resolved.
108
+
In non-interactive mode the CLI will not prompt, and it will exit non-zero if a token cannot be resolved.
0 commit comments