Skip to content

feat(template): support deploy by template code with -c/--code flag#195

Merged
yuaanlin merged 3 commits intomainfrom
feat/template-deploy-by-code
Mar 25, 2026
Merged

feat(template): support deploy by template code with -c/--code flag#195
yuaanlin merged 3 commits intomainfrom
feat/template-deploy-by-code

Conversation

@yuaanlin
Copy link
Member

@yuaanlin yuaanlin commented Mar 24, 2026

Summary

  • Add -c/--code flag to template deploy command
  • Fetches template YAML from https://zeabur.com/templates/<code>.yaml and deploys it directly
  • Mutually exclusive with -f/--file — only one can be specified

Before

# Two-step process
zeabur template get -c KXL04P --raw > /tmp/mongodb.yaml
zeabur template deploy -f /tmp/mongodb.yaml --project-id <id>

After

# One command
zeabur template deploy -c KXL04P --project-id <id>

Test plan

  • go build ./... passes
  • go test ./... passes
  • template deploy --help shows new -c/--code flag
  • template deploy -c KXL04P --project-id <id> deploys MongoDB successfully

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a --code / -c option to deploy, letting you specify templates by code instead of a local file.
    • If a code is provided, the CLI fetches the template from a remote template URL with a 30s timeout and reports clear HTTP errors (including not found).
    • Improved parameter validation to require either a file or code and prevent providing both simultaneously; interactive prompts guide the choice.

Add `-c/--code` flag to `template deploy` so users can deploy
marketplace templates directly by code without manually fetching
the YAML first.

Before:
  zeabur template get -c KXL04P --raw > /tmp/mongodb.yaml
  zeabur template deploy -f /tmp/mongodb.yaml --project-id <id>

After:
  zeabur template deploy -c KXL04P --project-id <id>

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d6bc0a5e-1295-4fae-a89f-b2a2b43b6533

📥 Commits

Reviewing files that changed from the base of the PR and between 7552e84 and 28370f6.

📒 Files selected for processing (1)
  • internal/cmd/template/deploy/deploy.go

Walkthrough

Adds a --code/-c option and Options.code; deploy now fetches templates from https://zeabur.com/templates/<code>.yaml (30s timeout) when --code is used. Validation now requires exactly one source (--file xor --code) and handles 404 and other non-200 HTTP responses explicitly.

Changes

Cohort / File(s) Summary
CLI Flag & Options
internal/cmd/template/deploy/deploy.go
Added code string to Options and bound --code/-c CLI flag in NewCmdDeploy.
Template Fetching & Validation
internal/cmd/template/deploy/deploy.go
runDeploy now loads template from https://zeabur.com/templates/<escaped code>.yaml when opts.code set (HTTP GET with 30s context). Handles 404 as "template not found" and other non-200 statuses. paramCheck signature updated to paramCheck(f *cmdutil.Factory, opts *Options) error; rejects both --file and --code, requires at least one, and prompts in interactive mode to choose source.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI as Deploy Command
    participant Validator as Validation Logic
    participant HTTP as HTTP Client
    participant Zeabur as Zeabur Server

    User->>CLI: run deploy --code=abc123
    CLI->>Validator: validate flags (--file / --code)
    alt invalid: both or neither provided
        Validator-->>CLI: return validation error
        CLI-->>User: show error
    else valid (--code)
        Validator-->>CLI: validation passed
        CLI->>HTTP: GET https://zeabur.com/templates/abc123.yaml (30s timeout)
        HTTP->>Zeabur: request
        alt 200 OK
            Zeabur-->>HTTP: 200 + body
            HTTP-->>CLI: template content
            CLI-->>User: proceed with deploy
        else 404
            Zeabur-->>HTTP: 404 Not Found
            HTTP-->>CLI: "template not found" error
            CLI-->>User: show error
        else other non-200
            Zeabur-->>HTTP: non-200 status
            HTTP-->>CLI: unexpected status error
            CLI-->>User: show error
        end
    end
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 clearly and specifically summarizes the main change: adding a -c/--code flag to the template deploy command.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/template-deploy-by-code

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

yuaanlin added a commit to zeabur/zeabur-claude-plugin that referenced this pull request Mar 24, 2026
Update instructions to use `template deploy -c <code>` instead of
the two-step `template get --raw > file && template deploy -f file`
workflow. Depends on zeabur/cli#195.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/cmd/template/deploy/deploy.go`:
- Around line 63-81: The current fetch uses http.Get without timeout and reports
any non-200 as "not found"; replace it with a context.WithTimeout (import
context and time) and perform the request with http.NewRequestWithContext or an
http.Client with Timeout to enforce a deadline when fetching templateURL (the
block handling opts.code and spinner s). After s.Start(), create ctx, do the
request with the timeout, stop s on error, defer resp.Body.Close(), and then
distinguish resp.StatusCode==http.StatusNotFound to return "template not found
(code: %s)" while returning a different error for other non-200 codes like
"failed fetching template (code: %s, HTTP %d)". Ensure spinner s is stopped in
all early-return paths.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fcfec7dc-9e7c-4d61-8c9c-679385b1d939

📥 Commits

Reviewing files that changed from the base of the PR and between 4f1eb83 and 07fdefc.

📒 Files selected for processing (1)
  • internal/cmd/template/deploy/deploy.go

Use context.WithTimeout (30s) consistent with get.go pattern.
Distinguish 404 "template not found" from other HTTP errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/cmd/template/deploy/deploy.go`:
- Around line 338-340: The code currently unconditionally errors when both
opts.file and opts.code are empty; change it to only return the "one required"
error in non-interactive runs and keep the mutual-exclusion behavior for
both-set. Concretely: retain the existing mutual-exclusion check for opts.file
&& opts.code and return an error there, but for the "neither provided" case,
branch on the runtime interactive flag (use the existing interactive indicator
in your CLI context, e.g., opts.interactive or the command IO helper such as
o.IO.IsInteractive()) — if non-interactive return the fmt.Errorf, otherwise
allow execution to continue so the command can prompt the user for a source
selection.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bab2ee6c-534b-4ae9-92c3-716f5fa53324

📥 Commits

Reviewing files that changed from the base of the PR and between 07fdefc and 7552e84.

📒 Files selected for processing (1)
  • internal/cmd/template/deploy/deploy.go

…ags provided

In interactive mode, prompt user to choose between file and code source
instead of hard-failing. Non-interactive mode still requires explicit flags.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@yuaanlin yuaanlin merged commit 67b399c into main Mar 25, 2026
4 of 5 checks passed
@yuaanlin yuaanlin deleted the feat/template-deploy-by-code branch March 25, 2026 07:56
yuaanlin added a commit to zeabur/zeabur-claude-plugin that referenced this pull request Mar 25, 2026
#23)

* fix: prevent duplicate services on redeploy and add marketplace deploy

- zeabur-deploy: split into "First Deploy" and "Redeploy" sections,
  emphasize that --service-id is REQUIRED for redeployment to avoid
  creating duplicate services, and mandate saving service-id after
  first deploy
- zeabur-template-deploy: add Marketplace Prebuilt Services section
  with --marketplace-code flag for common services (MongoDB, PostgreSQL,
  MySQL, Redis, MinIO) so AI doesn't write custom template YAML files
  for services that already exist in the marketplace

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: add marketplace prebuilt services section to template-deploy skill

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: replace deprecated marketplace-code with template search + get workflow

Use `template search` → `template get -c <code> --raw` → `template deploy -f`
instead of the deprecated `--marketplace-code` flag.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: use new -c/--code flag for marketplace template deploy

Update instructions to use `template deploy -c <code>` instead of
the two-step `template get --raw > file && template deploy -f file`
workflow. Depends on zeabur/cli#195.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: add advanced section for fetch-and-customize workflow

Keep `template get --raw` + edit + `deploy -f` as an advanced use case
for users who need to customize the template YAML before deploying.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant