Skip to content

hosting-cli(gcp): add --cpu, --memory, --min-instances flags#6552

Merged
Kastier1 merged 4 commits into
mainfrom
simon/gcp-cloud-run-resources
May 22, 2026
Merged

hosting-cli(gcp): add --cpu, --memory, --min-instances flags#6552
Kastier1 merged 4 commits into
mainfrom
simon/gcp-cloud-run-resources

Conversation

@Kastier1
Copy link
Copy Markdown
Contributor

Summary

  • Adds --cpu, --memory, and --min-instances flags to reflex deploy --gcp. They forward to the deploy script via CPU, MEMORY, and MIN_INSTANCES env vars.
  • The restricted env in _run_deploy_script (allowlist-only) means callers couldn't override these from their shell — they have to come through CLI flags.
  • Defaults match the previously hard-coded values (1 / 1Gi / 1), so the no-args behavior is unchanged.
  • Requires the matching backend change so the script honors the new env vars: reflex-dev/flexgen#3735

Test plan

  • pytest tests/units/reflex_cli/v2/test_gcp.py (22 passed locally, includes 2 new tests covering custom values and defaults)
  • Smoke deploy with --cpu 2 --memory 2Gi --min-instances 0 once the flexgen PR is merged, and confirm the rendered gcloud run deploy line uses them.

🤖 Generated with Claude Code

Forward the new CPU / MEMORY / MIN_INSTANCES env vars to the deploy
script so users can override the Cloud Run resource allocation. The
restricted env in `_run_deploy_script` means callers couldn't override
these from their shell — they have to come through the CLI flags.

Defaults match the previously hard-coded values (1 / 1Gi / 1).

Requires the matching backend change in flexgen
(reflex-dev/flexgen#3735) so the deploy script honors the new env vars.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Kastier1 Kastier1 requested a review from a team as a code owner May 21, 2026 22:03
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 21, 2026

Greptile Summary

This PR adds --cpu, --memory, and --min-instances CLI flags to reflex deploy --gcp, forwarding them as CPU, MEMORY, and MIN_INSTANCES environment variables into the deploy script. Defaults (1, 1Gi, 1) match the previously hard-coded values, so existing behavior is unchanged.

  • New flags are wired through deploy_command into deploy_env and passed via env_overrides to _run_deploy_script, following the same pattern as existing env vars like GCP_PROJECT and VERSION.
  • Two new unit tests verify both custom values and default passthrough for the new flags.

Confidence Score: 4/5

Safe to merge; the new flags follow existing patterns and defaults preserve current behavior, with the only risk being invalid user input surfacing later inside gcloud rather than at the CLI.

The implementation is straightforward and correct. The only concerns are that --min-instances accepts any string (negative numbers, non-integers) and --cpu/--memory have no format validation, meaning bad input passes through to gcloud silently. These are UX gaps, not functional regressions.

The --cpu and --memory option declarations in gcp.py (lines 143–161) would benefit from input validation before the PR is merged.

Important Files Changed

Filename Overview
packages/reflex-hosting-cli/src/reflex_cli/v2/gcp.py Adds --cpu, --memory, --min-instances CLI options forwarded as env vars to the deploy script; no input validation on the new flags.
tests/units/reflex_cli/v2/test_gcp.py Adds two new tests covering custom flag values and default values for the new resource flags; both are well-structured and complete.

Reviews (1): Last reviewed commit: "hosting-cli(gcp): add --cpu, --memory, -..." | Re-trigger Greptile

Comment thread packages/reflex-hosting-cli/src/reflex_cli/v2/gcp.py
Comment thread packages/reflex-hosting-cli/src/reflex_cli/v2/gcp.py Outdated
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 21, 2026

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing simon/gcp-cloud-run-resources (894e1b0) with main (6bb44d5)

Open in CodSpeed

Kastier1 and others added 2 commits May 21, 2026 15:26
Per Greptile review on #6552:
- Rename CPU / MEMORY / MIN_INSTANCES env vars to CLOUD_RUN_CPU /
  CLOUD_RUN_MEMORY / CLOUD_RUN_MIN_INSTANCES to avoid ambient shell-var
  shadowing (the bash `:=` expansion in the deploy script would pick up
  any ambient value with these short names). The flexgen-side script
  was renamed in the companion PR.
- Validate --min-instances at the CLI via `click.IntRange(min=0)` so
  garbage input fails fast with a helpful error instead of bubbling up
  as an opaque gcloud error.

Skipping format validation on --cpu and --memory: the set of valid
Cloud Run values varies by execution-environment generation, so a
client-side regex risks rejecting valid input. Let gcloud be the
authority on what it accepts.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
adhami3310
adhami3310 previously approved these changes May 21, 2026
@Kastier1 Kastier1 merged commit d611a5d into main May 22, 2026
70 checks passed
@Kastier1 Kastier1 deleted the simon/gcp-cloud-run-resources branch May 22, 2026 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants