-
Notifications
You must be signed in to change notification settings - Fork 13
feat(template): add --var flag for non-interactive deploy #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ type Options struct { | |
| file string | ||
| projectID string | ||
| skipValidation bool | ||
| vars map[string]string | ||
| } | ||
|
|
||
| func NewCmdDeploy(f *cmdutil.Factory) *cobra.Command { | ||
|
|
@@ -40,6 +41,7 @@ func NewCmdDeploy(f *cmdutil.Factory) *cobra.Command { | |
| cmd.Flags().StringVarP(&opts.file, "file", "f", "", "Template file") | ||
| cmd.Flags().StringVar(&opts.projectID, "project-id", "", "Project ID to deploy on") | ||
| cmd.Flags().BoolVar(&opts.skipValidation, "skip-validation", false, "Skip template validation") | ||
| cmd.Flags().StringToStringVar(&opts.vars, "var", nil, "Template variables (e.g. --var KEY=value)") | ||
|
|
||
| return cmd | ||
| } | ||
|
|
@@ -118,7 +120,55 @@ func runDeploy(f *cmdutil.Factory, opts *Options) error { | |
| } | ||
|
|
||
| vars := model.Map{} | ||
|
|
||
| // In non-interactive mode, check all required variables upfront | ||
| 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)) | ||
|
Comment on lines
+125
to
+129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In non-interactive mode this loop treats every template variable as required, but later in the same function Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
| if len(missingVars) > 0 { | ||
| return fmt.Errorf("missing required variables in non-interactive mode:\n%s", strings.Join(missingVars, "\n")) | ||
| } | ||
| } | ||
|
|
||
| for _, v := range raw.Spec.Variables { | ||
| // Check if variable is provided via --var flag | ||
| if val, ok := opts.vars[v.Key]; ok { | ||
| // Validate DOMAIN type variables | ||
| if v.Type == "DOMAIN" { | ||
| // Skip domain validation for sha1 region | ||
| if project.Region.ID == "sha1" { | ||
| f.Log.Warnf("Selected region does not support generated domain, please bind a custom domain after template deployed.\n") | ||
| continue | ||
| } | ||
|
|
||
| s := spinner.New(cmdutil.SpinnerCharSet, cmdutil.SpinnerInterval, | ||
| spinner.WithColor(cmdutil.SpinnerColor), | ||
| spinner.WithSuffix(" Checking if domain "+val+".zeabur.app is available ..."), | ||
| ) | ||
|
|
||
| s.Start() | ||
| available, _, err := f.ApiClient.CheckDomainAvailable(context.Background(), val, true, project.Region.ID) | ||
| s.Stop() | ||
|
|
||
| if err != nil { | ||
| return fmt.Errorf("check domain availability failed: %w", err) | ||
| } | ||
|
|
||
| if !available { | ||
| return fmt.Errorf("domain %s.zeabur.app is not available, please choose another one", val) | ||
| } | ||
|
|
||
| f.Log.Infof("Domain %s.zeabur.app is available!\n", val) | ||
| } | ||
|
|
||
| vars[v.Key] = val | ||
| continue | ||
| } | ||
|
|
||
| switch v.Type { | ||
| case "DOMAIN": | ||
| // Notice: flex shared cluster in China mainland (sha1) does not support generated domain | ||
|
|
||
There was a problem hiding this comment.
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
--varfor them. Align the pre-check with the actual per-variable handling (e.g., skip DOMAIN variables whenproject.Region.ID == "sha1", and generally only require vars that will actually be consumed).