Skip to content

feat(template): add --var flag for non-interactive deploy#159

Merged
canyugs merged 2 commits intomainfrom
can/zea-8506-enable-fully-automated-template-deployment-via-var-flag
Jan 28, 2026
Merged

feat(template): add --var flag for non-interactive deploy#159
canyugs merged 2 commits intomainfrom
can/zea-8506-enable-fully-automated-template-deployment-via-var-flag

Conversation

@canyugs
Copy link
Contributor

@canyugs canyugs commented Jan 27, 2026

Summary

  • Add --var KEY=value flag to zeabur template deploy command
  • Enable fully automated template deployment in non-interactive mode (CI/CD)
  • Validate all required variables upfront in non-interactive mode with helpful error messages
  • Validate DOMAIN type variables for availability when using --var

Usage

# Deploy with all variables specified
zeabur template deploy -f template.yaml \
  --project-id <ID> \
  --var APP_NAME=myapp \
  --var PUBLIC_DOMAIN=mydomain

# Non-interactive mode shows missing variables
zeabur template deploy -f template.yaml --project-id <ID> -i=false
# ERROR: missing required variables in non-interactive mode:
#   --var APP_NAME=<value>  (The name of your application)
#   --var PUBLIC_DOMAIN=<value>  (Domain prefix for your app)

# Domain availability is validated
zeabur template deploy -f template.yaml --project-id <ID> --var PUBLIC_DOMAIN=taken-domain
# ERROR: domain taken-domain.zeabur.app is not available, please choose another one

Test plan

  • Non-interactive mode without --var shows all missing variables
  • Non-interactive mode with all --var flags deploys successfully
  • Non-interactive mode with partial --var shows only missing variables
  • DOMAIN type variables work correctly with --var
  • DOMAIN type variables are validated for availability
  • Taken domains return clear error message
  • Interactive mode still works (falls back to prompts for unprovided vars)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a new command-line flag (--var) to pass template variables during deployment, supporting multiple assignments.
    • Non-interactive mode now performs pre-flight validation and returns clear errors listing any missing template variables.
    • Variables supplied via the flag skip interactive prompts; DOMAIN-type values are validated and checked for availability before deployment.

✏️ Tip: You can customize this high-level summary in your review settings.

Allow template deploy to run without interactive prompts by passing
variables via --var flag. In non-interactive mode, missing variables
are reported upfront with helpful hints.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 27, 2026 06:29
@coderabbitai
Copy link

coderabbitai bot commented Jan 27, 2026

Walkthrough

Added a vars field to Options and a new --var CLI flag to supply template variables. In non-interactive mode, enforces that all template variables are provided. Supplied vars are consumed (with DOMAIN-type validation and availability checks) and skip interactive prompts.

Changes

Cohort / File(s) Summary
Template Variable CLI Support
internal/cmd/template/deploy/deploy.go
Added vars map[string]string field to Options. Added --var (StringToStringVar) flag. In non-interactive mode, validate all raw.Spec.Variables supplied via --var. When processing variables, consume supplied values, perform DOMAIN-type validation (skip for sha1 region), call domain availability API and error if unavailable, and skip prompts for provided keys. Retains interactive prompts for unsupplied variables.

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant DeployCmd as "deploy.go"
  participant Prompt as "Interactive Prompt"
  participant DomainAPI as "Domain Availability API"

  CLI->>DeployCmd: parse flags (--var => opts.vars)
  DeployCmd->>DeployCmd: load template raw.Spec.Variables
  alt non-interactive
    DeployCmd->>DeployCmd: check all variables present in opts.vars
    DeployCmd-->>CLI: error if missing variables
  else interactive or partial
    loop for each variable
      DeployCmd->>DeployCmd: if var in opts.vars use value
      alt var type == DOMAIN and region != "sha1"
        DeployCmd->>DomainAPI: check domain availability
        DomainAPI-->>DeployCmd: available / unavailable
        alt unavailable
          DeployCmd-->>CLI: error (domain unavailable)
        end
      else if not provided
        DeployCmd->>Prompt: prompt user for value
        Prompt-->>DeployCmd: user input
      end
    end
  end
  DeployCmd->>CLI: proceed with deployment using resolved vars
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a --var flag for non-interactive template deployment, which matches the core functionality added in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch can/zea-8506-enable-fully-automated-template-deployment-via-var-flag

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5b80e85df

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +125 to +129
if !f.Interactive {
var missingVars []string
for _, v := range raw.Spec.Variables {
if _, ok := opts.vars[v.Key]; !ok {
missingVars = append(missingVars, fmt.Sprintf(" --var %s=<value> (%s)", v.Key, v.Description))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Skip DOMAIN vars for sha1 in non-interactive precheck

In non-interactive mode this loop treats every template variable as required, but later in the same function DOMAIN variables are explicitly skipped when project.Region.ID == "sha1" (they’re not supported and the deploy proceeds without them). That means zeabur template deploy -i=false against a sha1 project will always fail with “missing required variables” if the template includes a DOMAIN variable, even though it would have been accepted interactively. Consider exempting DOMAIN vars for sha1 (or mirroring the later conditional) when building missingVars so CI deployments in that region don’t get blocked unnecessarily.

Useful? React with 👍 / 👎.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for supplying template variables via a --var KEY=value flag to enable non-interactive (CI/CD) deployments, with upfront validation of required variables when running without prompts.

Changes:

  • Add --var (StringToStringVar) flag and store parsed values in Options.vars.
  • In non-interactive mode, validate missing template variables upfront and return a consolidated error.
  • Prefer --var-provided values over interactive prompts when building the variables map for deployment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +124 to +127
// In non-interactive mode, check all required variables upfront
if !f.Interactive {
var missingVars []string
for _, v := range raw.Spec.Variables {
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upfront missing-variable check in non-interactive mode currently treats all template variables as required. This can break existing behavior for DOMAIN variables in region "sha1": later in the loop DOMAIN variables are explicitly skipped for sha1, but the pre-check will still fail unless the user provides --var for them. Align the pre-check with the actual per-variable handling (e.g., skip DOMAIN variables when project.Region.ID == "sha1", and generally only require vars that will actually be consumed).

Suggested change
// In non-interactive mode, check all required variables upfront
if !f.Interactive {
var missingVars []string
for _, v := range raw.Spec.Variables {
// In non-interactive mode, check all required variables upfront,
// but only for variables that will actually be consumed later.
if !f.Interactive {
var missingVars []string
for _, v := range raw.Spec.Variables {
// DOMAIN variables are skipped for region "sha1" later in the loop,
// so they should not be treated as required here either.
if project.Region != nil && project.Region.ID == "sha1" && v.Type == "DOMAIN" {
continue
}

Copilot uses AI. Check for mistakes.
Comment on lines 138 to 142
// Check if variable is provided via --var flag
if val, ok := opts.vars[v.Key]; ok {
vars[v.Key] = val
continue
}
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--var values are applied before the type-specific logic and continue, which means DOMAIN variables provided via --var bypass the sha1-region skip + warning and the availability check (CheckDomainAvailable). Consider handling DOMAIN keys specially even when provided via --var (e.g., in sha1 ignore with the existing warning, otherwise validate availability and return a clear error if unavailable) so --var doesn’t change DOMAIN semantics.

Copilot uses AI. Check for mistakes.
@canyugs canyugs self-assigned this Jan 27, 2026
Previously, DOMAIN type variables provided via --var flag were not
validated for availability, allowing deployment with taken domains.
Now the CLI checks domain availability before deploying.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@canyugs canyugs merged commit 5f6479c into main Jan 28, 2026
5 checks passed
@canyugs canyugs deleted the can/zea-8506-enable-fully-automated-template-deployment-via-var-flag branch January 28, 2026 12:22
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