Skip to content

Commit 5f6479c

Browse files
canyugsclaude
andcommitted
fix(template): validate domain availability when using --var flag
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>
1 parent 3f76006 commit 5f6479c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

internal/cmd/template/deploy/deploy.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,34 @@ func runDeploy(f *cmdutil.Factory, opts *Options) error {
137137
for _, v := range raw.Spec.Variables {
138138
// Check if variable is provided via --var flag
139139
if val, ok := opts.vars[v.Key]; ok {
140+
// Validate DOMAIN type variables
141+
if v.Type == "DOMAIN" {
142+
// Skip domain validation for sha1 region
143+
if project.Region.ID == "sha1" {
144+
f.Log.Warnf("Selected region does not support generated domain, please bind a custom domain after template deployed.\n")
145+
continue
146+
}
147+
148+
s := spinner.New(cmdutil.SpinnerCharSet, cmdutil.SpinnerInterval,
149+
spinner.WithColor(cmdutil.SpinnerColor),
150+
spinner.WithSuffix(" Checking if domain "+val+".zeabur.app is available ..."),
151+
)
152+
153+
s.Start()
154+
available, _, err := f.ApiClient.CheckDomainAvailable(context.Background(), val, true, project.Region.ID)
155+
s.Stop()
156+
157+
if err != nil {
158+
return fmt.Errorf("check domain availability failed: %w", err)
159+
}
160+
161+
if !available {
162+
return fmt.Errorf("domain %s.zeabur.app is not available, please choose another one", val)
163+
}
164+
165+
f.Log.Infof("Domain %s.zeabur.app is available!\n", val)
166+
}
167+
140168
vars[v.Key] = val
141169
continue
142170
}

0 commit comments

Comments
 (0)