From fa3b28f015b3f5f36552e3a7c9b82b7a1c9b1ec2 Mon Sep 17 00:00:00 2001 From: defelmnq Date: Thu, 10 Oct 2024 00:19:11 +0200 Subject: [PATCH 01/14] chore: rename build options to ephemeral parameters in cli --- cli/create.go | 8 ++++---- cli/parameter.go | 30 ++++++++++++++++++++++++------ cli/parameterresolver.go | 32 ++++++++++++++++---------------- cli/restart_test.go | 8 ++++---- cli/start.go | 14 +++++++------- cli/start_test.go | 10 +++++----- cli/update.go | 2 +- cli/update_test.go | 12 ++++++------ 8 files changed, 67 insertions(+), 49 deletions(-) diff --git a/cli/create.go b/cli/create.go index 5384ec094fd73..644bc76f803ff 100644 --- a/cli/create.go +++ b/cli/create.go @@ -355,8 +355,8 @@ type prepWorkspaceBuildArgs struct { LastBuildParameters []codersdk.WorkspaceBuildParameter SourceWorkspaceParameters []codersdk.WorkspaceBuildParameter - PromptBuildOptions bool - BuildOptions []codersdk.WorkspaceBuildParameter + PromptEphemeralParameters bool + EphemeralParameters []codersdk.WorkspaceBuildParameter PromptRichParameters bool RichParameters []codersdk.WorkspaceBuildParameter @@ -390,8 +390,8 @@ func prepWorkspaceBuild(inv *serpent.Invocation, client *codersdk.Client, args p resolver := new(ParameterResolver). WithLastBuildParameters(args.LastBuildParameters). WithSourceWorkspaceParameters(args.SourceWorkspaceParameters). - WithPromptBuildOptions(args.PromptBuildOptions). - WithBuildOptions(args.BuildOptions). + WithPromptEphemeralParameters(args.PromptEphemeralParameters). + WithEphemeralParameters(args.EphemeralParameters). WithPromptRichParameters(args.PromptRichParameters). WithRichParameters(args.RichParameters). WithRichParametersFile(parameterFile). diff --git a/cli/parameter.go b/cli/parameter.go index e674348fa1e06..6b49e4cc850f1 100644 --- a/cli/parameter.go +++ b/cli/parameter.go @@ -15,8 +15,9 @@ import ( // workspaceParameterFlags are used by commands processing rich parameters and/or build options. type workspaceParameterFlags struct { - promptBuildOptions bool - buildOptions []string + promptEphemeralParameters bool + + ephemeralParameters []string richParameterFile string richParameters []string @@ -26,23 +27,40 @@ type workspaceParameterFlags struct { } func (wpf *workspaceParameterFlags) allOptions() []serpent.Option { - options := append(wpf.cliBuildOptions(), wpf.cliParameters()...) + options := append(wpf.cliEphemeralParameters(), wpf.cliParameters()...) options = append(options, wpf.cliParameterDefaults()...) return append(options, wpf.alwaysPrompt()) } -func (wpf *workspaceParameterFlags) cliBuildOptions() []serpent.Option { +func (wpf *workspaceParameterFlags) cliEphemeralParameters() []serpent.Option { return serpent.OptionSet{ + // Deprecated - replaced with ephemeral-parameter { Flag: "build-option", Env: "CODER_BUILD_OPTION", Description: `Build option value in the format "name=value".`, - Value: serpent.StringArrayOf(&wpf.buildOptions), + UseInstead: []serpent.Option{{Flag: "ephemeral-parameter"}}, + Hidden: true, + Value: serpent.StringArrayOf(&wpf.ephemeralParameters), }, + // Deprecated - replaced with prompt-ephemeral-parameters { Flag: "build-options", Description: "Prompt for one-time build options defined with ephemeral parameters.", - Value: serpent.BoolOf(&wpf.promptBuildOptions), + UseInstead: []serpent.Option{{Flag: "prompt-ephemeral-parameters"}}, + Value: serpent.BoolOf(&wpf.promptEphemeralParameters), + }, + { + Flag: "ephemeral-parameter", + Env: "CODER_EPHEMERAL_PARAMETER", + Description: `Define ephemeral parameters in the format "name=value".`, + Value: serpent.StringArrayOf(&wpf.ephemeralParameters), + }, + { + Flag: "prompt-ephemeral-parameters", + Env: "CODER_PROMPT_EPHEMERAL_PARAMETERS", + Description: "Prompt for values of ephemeral parameters described in the template.", + Value: serpent.BoolOf(&wpf.promptEphemeralParameters), }, } } diff --git a/cli/parameterresolver.go b/cli/parameterresolver.go index 437b4bd407d75..41c61d5315a77 100644 --- a/cli/parameterresolver.go +++ b/cli/parameterresolver.go @@ -29,10 +29,10 @@ type ParameterResolver struct { richParameters []codersdk.WorkspaceBuildParameter richParametersDefaults map[string]string richParametersFile map[string]string - buildOptions []codersdk.WorkspaceBuildParameter + ephemeralParameters []codersdk.WorkspaceBuildParameter - promptRichParameters bool - promptBuildOptions bool + promptRichParameters bool + promptEphemeralParameters bool } func (pr *ParameterResolver) WithLastBuildParameters(params []codersdk.WorkspaceBuildParameter) *ParameterResolver { @@ -50,8 +50,8 @@ func (pr *ParameterResolver) WithRichParameters(params []codersdk.WorkspaceBuild return pr } -func (pr *ParameterResolver) WithBuildOptions(params []codersdk.WorkspaceBuildParameter) *ParameterResolver { - pr.buildOptions = params +func (pr *ParameterResolver) WithEphemeralParameters(params []codersdk.WorkspaceBuildParameter) *ParameterResolver { + pr.ephemeralParameters = params return pr } @@ -75,8 +75,8 @@ func (pr *ParameterResolver) WithPromptRichParameters(promptRichParameters bool) return pr } -func (pr *ParameterResolver) WithPromptBuildOptions(promptBuildOptions bool) *ParameterResolver { - pr.promptBuildOptions = promptBuildOptions +func (pr *ParameterResolver) WithPromptEphemeralParameters(promptEphemeralParameters bool) *ParameterResolver { + pr.promptEphemeralParameters = promptEphemeralParameters return pr } @@ -128,16 +128,16 @@ nextRichParameter: resolved = append(resolved, richParameter) } -nextBuildOption: - for _, buildOption := range pr.buildOptions { +nextEphemeralParameter: + for _, ephemeralParameter := range pr.ephemeralParameters { for i, r := range resolved { - if r.Name == buildOption.Name { - resolved[i].Value = buildOption.Value - continue nextBuildOption + if r.Name == ephemeralParameter.Name { + resolved[i].Value = ephemeralParameter.Value + continue nextEphemeralParameter } } - resolved = append(resolved, buildOption) + resolved = append(resolved, ephemeralParameter) } return resolved } @@ -209,8 +209,8 @@ func (pr *ParameterResolver) verifyConstraints(resolved []codersdk.WorkspaceBuil return templateVersionParametersNotFound(r.Name, templateVersionParameters) } - if tvp.Ephemeral && !pr.promptBuildOptions && findWorkspaceBuildParameter(tvp.Name, pr.buildOptions) == nil { - return xerrors.Errorf("ephemeral parameter %q can be used only with --build-options or --build-option flag", r.Name) + if tvp.Ephemeral && !pr.promptEphemeralParameters && findWorkspaceBuildParameter(tvp.Name, pr.ephemeralParameters) == nil { + return xerrors.Errorf("ephemeral parameter %q can be used only with --prompt-ephemeral-parameters or --ephemeral-parameter flag", r.Name) } if !tvp.Mutable && action != WorkspaceCreate { @@ -231,7 +231,7 @@ func (pr *ParameterResolver) resolveWithInput(resolved []codersdk.WorkspaceBuild firstTimeUse := pr.isFirstTimeUse(tvp.Name) promptParameterOption := pr.isLastBuildParameterInvalidOption(tvp) - if (tvp.Ephemeral && pr.promptBuildOptions) || + if (tvp.Ephemeral && pr.promptEphemeralParameters) || (action == WorkspaceCreate && tvp.Required) || (action == WorkspaceCreate && !tvp.Ephemeral) || (action == WorkspaceUpdate && promptParameterOption) || diff --git a/cli/restart_test.go b/cli/restart_test.go index d81169b8c4aba..b5ddace19fc9c 100644 --- a/cli/restart_test.go +++ b/cli/restart_test.go @@ -60,7 +60,7 @@ func TestRestart(t *testing.T) { require.NoError(t, err, "execute failed") }) - t.Run("BuildOptions", func(t *testing.T) { + t.Run("PromptEphemeralParameters", func(t *testing.T) { t.Parallel() client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) @@ -72,7 +72,7 @@ func TestRestart(t *testing.T) { workspace := coderdtest.CreateWorkspace(t, member, template.ID) coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) - inv, root := clitest.New(t, "restart", workspace.Name, "--build-options") + inv, root := clitest.New(t, "restart", workspace.Name, "--prompt-ephemeral-parameters") clitest.SetupConfig(t, member, root) doneChan := make(chan struct{}) pty := ptytest.New(t).Attach(inv) @@ -114,7 +114,7 @@ func TestRestart(t *testing.T) { }) }) - t.Run("BuildOptionFlags", func(t *testing.T) { + t.Run("EphemeralParameterFlags", func(t *testing.T) { t.Parallel() client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) @@ -127,7 +127,7 @@ func TestRestart(t *testing.T) { coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) inv, root := clitest.New(t, "restart", workspace.Name, - "--build-option", fmt.Sprintf("%s=%s", ephemeralParameterName, ephemeralParameterValue)) + "--ephemeral-parameter", fmt.Sprintf("%s=%s", ephemeralParameterName, ephemeralParameterValue)) clitest.SetupConfig(t, member, root) doneChan := make(chan struct{}) pty := ptytest.New(t).Attach(inv) diff --git a/cli/start.go b/cli/start.go index da2d394d12846..bca800471f28b 100644 --- a/cli/start.go +++ b/cli/start.go @@ -96,7 +96,7 @@ func buildWorkspaceStartRequest(inv *serpent.Invocation, client *codersdk.Client return codersdk.CreateWorkspaceBuildRequest{}, err } - buildOptions, err := asWorkspaceBuildParameters(parameterFlags.buildOptions) + ephemeralParameters, err := asWorkspaceBuildParameters(parameterFlags.ephemeralParameters) if err != nil { return codersdk.CreateWorkspaceBuildRequest{}, xerrors.Errorf("unable to parse build options: %w", err) } @@ -117,12 +117,12 @@ func buildWorkspaceStartRequest(inv *serpent.Invocation, client *codersdk.Client NewWorkspaceName: workspace.Name, LastBuildParameters: lastBuildParameters, - PromptBuildOptions: parameterFlags.promptBuildOptions, - BuildOptions: buildOptions, - PromptRichParameters: parameterFlags.promptRichParameters, - RichParameters: cliRichParameters, - RichParameterFile: parameterFlags.richParameterFile, - RichParameterDefaults: cliRichParameterDefaults, + PromptEphemeralParameters: parameterFlags.promptEphemeralParameters, + EphemeralParameters: ephemeralParameters, + PromptRichParameters: parameterFlags.promptRichParameters, + RichParameters: cliRichParameters, + RichParameterFile: parameterFlags.richParameterFile, + RichParameterDefaults: cliRichParameterDefaults, }) if err != nil { return codersdk.CreateWorkspaceBuildRequest{}, err diff --git a/cli/start_test.go b/cli/start_test.go index 404052745f00b..e9809ff4bc4ff 100644 --- a/cli/start_test.go +++ b/cli/start_test.go @@ -115,7 +115,7 @@ func TestStart(t *testing.T) { workspaceBuild := coderdtest.CreateWorkspaceBuild(t, client, workspace, database.WorkspaceTransitionStop) coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspaceBuild.ID) - inv, root := clitest.New(t, "start", workspace.Name, "--build-options") + inv, root := clitest.New(t, "start", workspace.Name, "--prompt-ephemeral-parameters") clitest.SetupConfig(t, member, root) doneChan := make(chan struct{}) pty := ptytest.New(t).Attach(inv) @@ -140,7 +140,7 @@ func TestStart(t *testing.T) { } <-doneChan - // Verify if build option is set + // Verify if ephemeral parameter is set ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) defer cancel() @@ -154,7 +154,7 @@ func TestStart(t *testing.T) { }) }) - t.Run("BuildOptionFlags", func(t *testing.T) { + t.Run("EphemeralParameterFlags", func(t *testing.T) { t.Parallel() client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) @@ -170,7 +170,7 @@ func TestStart(t *testing.T) { coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspaceBuild.ID) inv, root := clitest.New(t, "start", workspace.Name, - "--build-option", fmt.Sprintf("%s=%s", ephemeralParameterName, ephemeralParameterValue)) + "--ephemeral-parameter", fmt.Sprintf("%s=%s", ephemeralParameterName, ephemeralParameterValue)) clitest.SetupConfig(t, member, root) doneChan := make(chan struct{}) pty := ptytest.New(t).Attach(inv) @@ -183,7 +183,7 @@ func TestStart(t *testing.T) { pty.ExpectMatch("workspace has been started") <-doneChan - // Verify if build option is set + // Verify if ephemeral parameter is set ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) defer cancel() diff --git a/cli/update.go b/cli/update.go index cf4ec5e1b6c39..25ab8c5b0b49c 100644 --- a/cli/update.go +++ b/cli/update.go @@ -29,7 +29,7 @@ func (r *RootCmd) update() *serpent.Command { if err != nil { return err } - if !workspace.Outdated && !parameterFlags.promptRichParameters && !parameterFlags.promptBuildOptions && len(parameterFlags.buildOptions) == 0 { + if !workspace.Outdated && !parameterFlags.promptRichParameters && !parameterFlags.promptEphemeralParameters && len(parameterFlags.ephemeralParameters) == 0 { _, _ = fmt.Fprintf(inv.Stdout, "Workspace isn't outdated!\n") return nil } diff --git a/cli/update_test.go b/cli/update_test.go index 887a787b1d36e..5344a35920653 100644 --- a/cli/update_test.go +++ b/cli/update_test.go @@ -160,7 +160,7 @@ func TestUpdateWithRichParameters(t *testing.T) { <-doneChan }) - t.Run("BuildOptions", func(t *testing.T) { + t.Run("PromptEphemeralParameters", func(t *testing.T) { t.Parallel() client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) @@ -186,7 +186,7 @@ func TestUpdateWithRichParameters(t *testing.T) { err := inv.Run() assert.NoError(t, err) - inv, root = clitest.New(t, "update", workspaceName, "--build-options") + inv, root = clitest.New(t, "update", workspaceName, "--prompt-ephemeral-parameters") clitest.SetupConfig(t, member, root) doneChan := make(chan struct{}) @@ -211,7 +211,7 @@ func TestUpdateWithRichParameters(t *testing.T) { } <-doneChan - // Verify if build option is set + // Verify if ephemeral parameter is set ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) defer cancel() @@ -225,7 +225,7 @@ func TestUpdateWithRichParameters(t *testing.T) { }) }) - t.Run("BuildOptionFlags", func(t *testing.T) { + t.Run("EphemeralParameterFlags", func(t *testing.T) { t.Parallel() client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) @@ -247,7 +247,7 @@ func TestUpdateWithRichParameters(t *testing.T) { assert.NoError(t, err) inv, root = clitest.New(t, "update", workspaceName, - "--build-option", fmt.Sprintf("%s=%s", ephemeralParameterName, ephemeralParameterValue)) + "--ephemeral-parameter", fmt.Sprintf("%s=%s", ephemeralParameterName, ephemeralParameterValue)) clitest.SetupConfig(t, member, root) doneChan := make(chan struct{}) @@ -261,7 +261,7 @@ func TestUpdateWithRichParameters(t *testing.T) { pty.ExpectMatch("Planning workspace") <-doneChan - // Verify if build option is set + // Verify if ephemeral parameter is set ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) defer cancel() From fbf1c50e68740dac0c2abee9d70cf00a3afe8d57 Mon Sep 17 00:00:00 2001 From: defelmnq Date: Wed, 9 Oct 2024 23:01:14 +0000 Subject: [PATCH 02/14] fix: generate golden files --- cli/testdata/coder_restart_--help.golden | 10 +++++++--- cli/testdata/coder_start_--help.golden | 10 +++++++--- cli/testdata/coder_update_--help.golden | 10 +++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/cli/testdata/coder_restart_--help.golden b/cli/testdata/coder_restart_--help.golden index 84d3e0f14996b..88223dd3ac7a8 100644 --- a/cli/testdata/coder_restart_--help.golden +++ b/cli/testdata/coder_restart_--help.golden @@ -10,11 +10,12 @@ OPTIONS: Always prompt all parameters. Does not pull parameter values from existing workspace. - --build-option string-array, $CODER_BUILD_OPTION - Build option value in the format "name=value". - --build-options bool Prompt for one-time build options defined with ephemeral parameters. + DEPRECATED: Use --prompt-ephemeral-parameters instead. + + --ephemeral-parameter string-array, $CODER_EPHEMERAL_PARAMETER + Define ephemeral parameters in the format "name=value". --parameter string-array, $CODER_RICH_PARAMETER Rich parameter value in the format "name=value". @@ -22,6 +23,9 @@ OPTIONS: --parameter-default string-array, $CODER_RICH_PARAMETER_DEFAULT Rich parameter default values in the format "name=value". + --prompt-ephemeral-parameters bool, $CODER_PROMPT_EPHEMERAL_PARAMETERS + Prompt for values of ephemeral parameters described in the template. + --rich-parameter-file string, $CODER_RICH_PARAMETER_FILE Specify a file path with values for rich parameters defined in the template. The file should be in YAML format, containing key-value diff --git a/cli/testdata/coder_start_--help.golden b/cli/testdata/coder_start_--help.golden index a4c77e4fa9698..83943ba93e08e 100644 --- a/cli/testdata/coder_start_--help.golden +++ b/cli/testdata/coder_start_--help.golden @@ -10,11 +10,12 @@ OPTIONS: Always prompt all parameters. Does not pull parameter values from existing workspace. - --build-option string-array, $CODER_BUILD_OPTION - Build option value in the format "name=value". - --build-options bool Prompt for one-time build options defined with ephemeral parameters. + DEPRECATED: Use --prompt-ephemeral-parameters instead. + + --ephemeral-parameter string-array, $CODER_EPHEMERAL_PARAMETER + Define ephemeral parameters in the format "name=value". --parameter string-array, $CODER_RICH_PARAMETER Rich parameter value in the format "name=value". @@ -22,6 +23,9 @@ OPTIONS: --parameter-default string-array, $CODER_RICH_PARAMETER_DEFAULT Rich parameter default values in the format "name=value". + --prompt-ephemeral-parameters bool, $CODER_PROMPT_EPHEMERAL_PARAMETERS + Prompt for values of ephemeral parameters described in the template. + --rich-parameter-file string, $CODER_RICH_PARAMETER_FILE Specify a file path with values for rich parameters defined in the template. The file should be in YAML format, containing key-value diff --git a/cli/testdata/coder_update_--help.golden b/cli/testdata/coder_update_--help.golden index 98537fade95f4..23f548a045a3f 100644 --- a/cli/testdata/coder_update_--help.golden +++ b/cli/testdata/coder_update_--help.golden @@ -12,11 +12,12 @@ OPTIONS: Always prompt all parameters. Does not pull parameter values from existing workspace. - --build-option string-array, $CODER_BUILD_OPTION - Build option value in the format "name=value". - --build-options bool Prompt for one-time build options defined with ephemeral parameters. + DEPRECATED: Use --prompt-ephemeral-parameters instead. + + --ephemeral-parameter string-array, $CODER_EPHEMERAL_PARAMETER + Define ephemeral parameters in the format "name=value". --parameter string-array, $CODER_RICH_PARAMETER Rich parameter value in the format "name=value". @@ -24,6 +25,9 @@ OPTIONS: --parameter-default string-array, $CODER_RICH_PARAMETER_DEFAULT Rich parameter default values in the format "name=value". + --prompt-ephemeral-parameters bool, $CODER_PROMPT_EPHEMERAL_PARAMETERS + Prompt for values of ephemeral parameters described in the template. + --rich-parameter-file string, $CODER_RICH_PARAMETER_FILE Specify a file path with values for rich parameters defined in the template. The file should be in YAML format, containing key-value From ab0fe51e4687403ef27e1c37c59197b245f8c2dc Mon Sep 17 00:00:00 2001 From: defelmnq Date: Wed, 9 Oct 2024 23:11:20 +0000 Subject: [PATCH 03/14] gen: cli docs --- docs/reference/cli/restart.md | 27 ++++++++++++++++++--------- docs/reference/cli/start.md | 27 ++++++++++++++++++--------- docs/reference/cli/update.md | 27 ++++++++++++++++++--------- 3 files changed, 54 insertions(+), 27 deletions(-) diff --git a/docs/reference/cli/restart.md b/docs/reference/cli/restart.md index 33c8f94f27909..ef9b83427a216 100644 --- a/docs/reference/cli/restart.md +++ b/docs/reference/cli/restart.md @@ -20,15 +20,6 @@ coder restart [flags] Bypass prompts. -### --build-option - -| | | -| ----------- | -------------------------------- | -| Type | string-array | -| Environment | $CODER_BUILD_OPTION | - -Build option value in the format "name=value". - ### --build-options | | | @@ -37,6 +28,24 @@ Build option value in the format "name=value". Prompt for one-time build options defined with ephemeral parameters. +### --ephemeral-parameter + +| | | +| ----------- | --------------------------------------- | +| Type | string-array | +| Environment | $CODER_EPHEMERAL_PARAMETER | + +Define ephemeral parameters in the format "name=value". + +### --prompt-ephemeral-parameters + +| | | +| ----------- | ----------------------------------------------- | +| Type | bool | +| Environment | $CODER_PROMPT_EPHEMERAL_PARAMETERS | + +Prompt for values of ephemeral parameters described in the template. + ### --parameter | | | diff --git a/docs/reference/cli/start.md b/docs/reference/cli/start.md index 7fa2f246846e7..95c441dfeb6b9 100644 --- a/docs/reference/cli/start.md +++ b/docs/reference/cli/start.md @@ -20,15 +20,6 @@ coder start [flags] Bypass prompts. -### --build-option - -| | | -| ----------- | -------------------------------- | -| Type | string-array | -| Environment | $CODER_BUILD_OPTION | - -Build option value in the format "name=value". - ### --build-options | | | @@ -37,6 +28,24 @@ Build option value in the format "name=value". Prompt for one-time build options defined with ephemeral parameters. +### --ephemeral-parameter + +| | | +| ----------- | --------------------------------------- | +| Type | string-array | +| Environment | $CODER_EPHEMERAL_PARAMETER | + +Define ephemeral parameters in the format "name=value". + +### --prompt-ephemeral-parameters + +| | | +| ----------- | ----------------------------------------------- | +| Type | bool | +| Environment | $CODER_PROMPT_EPHEMERAL_PARAMETERS | + +Prompt for values of ephemeral parameters described in the template. + ### --parameter | | | diff --git a/docs/reference/cli/update.md b/docs/reference/cli/update.md index 87665c79cd361..20dc089ad53b9 100644 --- a/docs/reference/cli/update.md +++ b/docs/reference/cli/update.md @@ -18,15 +18,6 @@ Use --always-prompt to change the parameter values of the workspace. ## Options -### --build-option - -| | | -| ----------- | -------------------------------- | -| Type | string-array | -| Environment | $CODER_BUILD_OPTION | - -Build option value in the format "name=value". - ### --build-options | | | @@ -35,6 +26,24 @@ Build option value in the format "name=value". Prompt for one-time build options defined with ephemeral parameters. +### --ephemeral-parameter + +| | | +| ----------- | --------------------------------------- | +| Type | string-array | +| Environment | $CODER_EPHEMERAL_PARAMETER | + +Define ephemeral parameters in the format "name=value". + +### --prompt-ephemeral-parameters + +| | | +| ----------- | ----------------------------------------------- | +| Type | bool | +| Environment | $CODER_PROMPT_EPHEMERAL_PARAMETERS | + +Prompt for values of ephemeral parameters described in the template. + ### --parameter | | | From 6986958979b430c1a33cfa20eb07b4f960b70765 Mon Sep 17 00:00:00 2001 From: defelmnq Date: Wed, 9 Oct 2024 23:21:31 +0000 Subject: [PATCH 04/14] fix: remove hidden tag to build-option --- cli/parameter.go | 1 - docs/reference/cli/restart.md | 9 +++++++++ docs/reference/cli/start.md | 9 +++++++++ docs/reference/cli/update.md | 9 +++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/cli/parameter.go b/cli/parameter.go index 6b49e4cc850f1..38c82d1d3e1cb 100644 --- a/cli/parameter.go +++ b/cli/parameter.go @@ -40,7 +40,6 @@ func (wpf *workspaceParameterFlags) cliEphemeralParameters() []serpent.Option { Env: "CODER_BUILD_OPTION", Description: `Build option value in the format "name=value".`, UseInstead: []serpent.Option{{Flag: "ephemeral-parameter"}}, - Hidden: true, Value: serpent.StringArrayOf(&wpf.ephemeralParameters), }, // Deprecated - replaced with prompt-ephemeral-parameters diff --git a/docs/reference/cli/restart.md b/docs/reference/cli/restart.md index ef9b83427a216..c12cbde43ebcc 100644 --- a/docs/reference/cli/restart.md +++ b/docs/reference/cli/restart.md @@ -20,6 +20,15 @@ coder restart [flags] Bypass prompts. +### --build-option + +| | | +| ----------- | -------------------------------- | +| Type | string-array | +| Environment | $CODER_BUILD_OPTION | + +Build option value in the format "name=value". + ### --build-options | | | diff --git a/docs/reference/cli/start.md b/docs/reference/cli/start.md index 95c441dfeb6b9..ead65808fa4a6 100644 --- a/docs/reference/cli/start.md +++ b/docs/reference/cli/start.md @@ -20,6 +20,15 @@ coder start [flags] Bypass prompts. +### --build-option + +| | | +| ----------- | -------------------------------- | +| Type | string-array | +| Environment | $CODER_BUILD_OPTION | + +Build option value in the format "name=value". + ### --build-options | | | diff --git a/docs/reference/cli/update.md b/docs/reference/cli/update.md index 20dc089ad53b9..ddba535a7e10f 100644 --- a/docs/reference/cli/update.md +++ b/docs/reference/cli/update.md @@ -18,6 +18,15 @@ Use --always-prompt to change the parameter values of the workspace. ## Options +### --build-option + +| | | +| ----------- | -------------------------------- | +| Type | string-array | +| Environment | $CODER_BUILD_OPTION | + +Build option value in the format "name=value". + ### --build-options | | | From 7b1b9af164e41a21e2551069536c16a383bfea86 Mon Sep 17 00:00:00 2001 From: defelmnq Date: Wed, 9 Oct 2024 23:29:29 +0000 Subject: [PATCH 05/14] fix: remove hidden tag to build-option --- cli/testdata/coder_restart_--help.golden | 4 ++++ cli/testdata/coder_start_--help.golden | 4 ++++ cli/testdata/coder_update_--help.golden | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/cli/testdata/coder_restart_--help.golden b/cli/testdata/coder_restart_--help.golden index 88223dd3ac7a8..c6355c4d2a292 100644 --- a/cli/testdata/coder_restart_--help.golden +++ b/cli/testdata/coder_restart_--help.golden @@ -10,6 +10,10 @@ OPTIONS: Always prompt all parameters. Does not pull parameter values from existing workspace. + --build-option string-array, $CODER_BUILD_OPTION + Build option value in the format "name=value". + DEPRECATED: Use --ephemeral-parameter instead. + --build-options bool Prompt for one-time build options defined with ephemeral parameters. DEPRECATED: Use --prompt-ephemeral-parameters instead. diff --git a/cli/testdata/coder_start_--help.golden b/cli/testdata/coder_start_--help.golden index 83943ba93e08e..3eafc7694e0da 100644 --- a/cli/testdata/coder_start_--help.golden +++ b/cli/testdata/coder_start_--help.golden @@ -10,6 +10,10 @@ OPTIONS: Always prompt all parameters. Does not pull parameter values from existing workspace. + --build-option string-array, $CODER_BUILD_OPTION + Build option value in the format "name=value". + DEPRECATED: Use --ephemeral-parameter instead. + --build-options bool Prompt for one-time build options defined with ephemeral parameters. DEPRECATED: Use --prompt-ephemeral-parameters instead. diff --git a/cli/testdata/coder_update_--help.golden b/cli/testdata/coder_update_--help.golden index 23f548a045a3f..646a1f6c0dd07 100644 --- a/cli/testdata/coder_update_--help.golden +++ b/cli/testdata/coder_update_--help.golden @@ -12,6 +12,10 @@ OPTIONS: Always prompt all parameters. Does not pull parameter values from existing workspace. + --build-option string-array, $CODER_BUILD_OPTION + Build option value in the format "name=value". + DEPRECATED: Use --ephemeral-parameter instead. + --build-options bool Prompt for one-time build options defined with ephemeral parameters. DEPRECATED: Use --prompt-ephemeral-parameters instead. From 06b6c090b9b004bf0102249a9307b98620240509 Mon Sep 17 00:00:00 2001 From: defelmnq Date: Thu, 10 Oct 2024 14:55:33 +0200 Subject: [PATCH 06/14] doc(build-parameters): work on wording around ephemeral parameters --- docs/admin/templates/extending-templates/parameters.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/admin/templates/extending-templates/parameters.md b/docs/admin/templates/extending-templates/parameters.md index 0ce8f06f6a06e..27b6c7781bb76 100644 --- a/docs/admin/templates/extending-templates/parameters.md +++ b/docs/admin/templates/extending-templates/parameters.md @@ -204,10 +204,11 @@ operational issue, but it is not advised to overuse this opportunity. ## Ephemeral parameters -Ephemeral parameters are introduced to users in the form of "build options." Use -ephemeral parameters to model specific behaviors in a Coder workspace, such as -reverting to a previous image, restoring from a volume snapshot, or building a -project without using cache. +Ephemeral parameters are introduced to users in order to model specific behaviors +in a Coder workspace, such as reverting to a previous image, restoring from a +volume snapshot, or building a project without using cache. These parameters are +only settable when starting, updating, or restarting a workspace and do not persist +after the workspace is stopped. Since these parameters are ephemeral in nature, subsequent builds proceed in the standard manner: From 4313b7e5254c00116644e723773e11fbc725b2d0 Mon Sep 17 00:00:00 2001 From: Vincent Vielle Date: Sun, 13 Oct 2024 22:44:57 +0200 Subject: [PATCH 07/14] Update cli/parameter.go Co-authored-by: Mathias Fredriksson --- cli/parameter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/parameter.go b/cli/parameter.go index 38c82d1d3e1cb..4cf4825c9fbce 100644 --- a/cli/parameter.go +++ b/cli/parameter.go @@ -58,7 +58,7 @@ func (wpf *workspaceParameterFlags) cliEphemeralParameters() []serpent.Option { { Flag: "prompt-ephemeral-parameters", Env: "CODER_PROMPT_EPHEMERAL_PARAMETERS", - Description: "Prompt for values of ephemeral parameters described in the template.", + Description: "Prompt to set values of ephemeral parameters defined in the template. If a value has been set via --ephemeral-parameter, it will not be prompted for.", Value: serpent.BoolOf(&wpf.promptEphemeralParameters), }, } From b2aea6c3f43bc6a0dd801d8eecef32549ed46c97 Mon Sep 17 00:00:00 2001 From: Vincent Vielle Date: Sun, 13 Oct 2024 22:45:18 +0200 Subject: [PATCH 08/14] Update cli/parameter.go Co-authored-by: Mathias Fredriksson --- cli/parameter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/parameter.go b/cli/parameter.go index 4cf4825c9fbce..02ff4e11f63e4 100644 --- a/cli/parameter.go +++ b/cli/parameter.go @@ -52,7 +52,7 @@ func (wpf *workspaceParameterFlags) cliEphemeralParameters() []serpent.Option { { Flag: "ephemeral-parameter", Env: "CODER_EPHEMERAL_PARAMETER", - Description: `Define ephemeral parameters in the format "name=value".`, + Description: `Set the value of ephemeral parameters defined in the template. The format is "name=value".`, Value: serpent.StringArrayOf(&wpf.ephemeralParameters), }, { From 19f0baeeb5be43935aa5a685ca5116f44d4f25b0 Mon Sep 17 00:00:00 2001 From: EdwardAngert <17991901+EdwardAngert@users.noreply.github.com> Date: Mon, 14 Oct 2024 18:32:13 +0000 Subject: [PATCH 09/14] make fmt --- docs/admin/templates/extending-templates/parameters.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/admin/templates/extending-templates/parameters.md b/docs/admin/templates/extending-templates/parameters.md index 27b6c7781bb76..ee72f4bbe2dc4 100644 --- a/docs/admin/templates/extending-templates/parameters.md +++ b/docs/admin/templates/extending-templates/parameters.md @@ -204,11 +204,11 @@ operational issue, but it is not advised to overuse this opportunity. ## Ephemeral parameters -Ephemeral parameters are introduced to users in order to model specific behaviors -in a Coder workspace, such as reverting to a previous image, restoring from a -volume snapshot, or building a project without using cache. These parameters are -only settable when starting, updating, or restarting a workspace and do not persist -after the workspace is stopped. +Ephemeral parameters are introduced to users in order to model specific +behaviors in a Coder workspace, such as reverting to a previous image, restoring +from a volume snapshot, or building a project without using cache. These +parameters are only settable when starting, updating, or restarting a workspace +and do not persist after the workspace is stopped. Since these parameters are ephemeral in nature, subsequent builds proceed in the standard manner: From 4d069b7b3b0a6987e3f997457f4e6b498bd60656 Mon Sep 17 00:00:00 2001 From: EdwardAngert <17991901+EdwardAngert@users.noreply.github.com> Date: Mon, 14 Oct 2024 19:38:11 +0000 Subject: [PATCH 10/14] fix links --- docs/admin/monitoring/notifications/index.md | 3 ++- docs/admin/provisioners.md | 2 +- docs/admin/templates/creating-templates.md | 6 +++--- docs/admin/templates/extending-templates/icons.md | 2 +- .../templates/managing-templates/devcontainers.md | 6 +++--- docs/admin/templates/troubleshooting.md | 13 +++++++------ docs/admin/users/sessions-tokens.md | 7 +++---- docs/tutorials/example-guide.md | 13 ++++++------- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/admin/monitoring/notifications/index.md b/docs/admin/monitoring/notifications/index.md index 00bf65d601600..e7f29bc19e892 100644 --- a/docs/admin/monitoring/notifications/index.md +++ b/docs/admin/monitoring/notifications/index.md @@ -77,7 +77,8 @@ can only be delivered to one method, and this method is configured globally with (default: `smtp`). Enterprise customers can configure which method to use for each of the supported -[Events](#events); see the [Preferences](#preferences) section below for more +[Events](#event-types); see the +[Preferences](#delivery-preferences-enterprise-premium) section below for more details. ## SMTP (Email) diff --git a/docs/admin/provisioners.md b/docs/admin/provisioners.md index 49e3968039049..5b66fdeb08a8e 100644 --- a/docs/admin/provisioners.md +++ b/docs/admin/provisioners.md @@ -94,7 +94,7 @@ coder provisioner start \ --tag environment=kubernetes ``` -Note: Any user can start [user-scoped provisioners](#User-scoped-Provisioners), +Note: Any user can start [user-scoped provisioners](#user-scoped-provisioners), but this will also require a template on your deployment with the corresponding tags. diff --git a/docs/admin/templates/creating-templates.md b/docs/admin/templates/creating-templates.md index f79a4d3c97d27..73a817c0d6d20 100644 --- a/docs/admin/templates/creating-templates.md +++ b/docs/admin/templates/creating-templates.md @@ -27,13 +27,13 @@ Give your template a name, description, and icon and press `Create template`. > **⚠️ Note**: If template creation fails, Coder is likely not authorized to > deploy infrastructure in the given location. Learn how to configure -> [provisioner authentication](#TODO). +> [provisioner authentication](../../admin/external-auth.md). ### CLI You can the [Coder CLI](../../install/cli.md) to manage templates for Coder. -After [logging in](#TODO) to your deployment, create a folder to store your -templates: +After [logging in](../../reference/cli/login.md) to your deployment, create a +folder to store your templates: ```sh # This snippet applies to macOS and Linux only diff --git a/docs/admin/templates/extending-templates/icons.md b/docs/admin/templates/extending-templates/icons.md index 7ae54d29164ee..c4abce0408e28 100644 --- a/docs/admin/templates/extending-templates/icons.md +++ b/docs/admin/templates/extending-templates/icons.md @@ -57,7 +57,7 @@ repository on [GitHub](https://github.com/coder/coder/tree/main/site/static/icon). You can also view the entire list, with search and previews, by navigating to -/icons on your Coder deployment. E.g. [https://coder.example.com/icons](#). This +`/icons` on your Coder deployment. E.g. `https://coder.example.com/icons`. This can be particularly useful in airgapped deployments. ![The icon gallery](../../../images/icons-gallery.png) diff --git a/docs/admin/templates/managing-templates/devcontainers.md b/docs/admin/templates/managing-templates/devcontainers.md index 1d23d926eb574..de10582c24c90 100644 --- a/docs/admin/templates/managing-templates/devcontainers.md +++ b/docs/admin/templates/managing-templates/devcontainers.md @@ -25,9 +25,9 @@ Then developers enter their repository URL as a workspace. [Envbuilder](https://github.com/coder/envbuilder) clones the repo and builds a container from the `devcontainer.json` specified in the repo. -When using the [Envbuilder Terraform provider](#provider), a previously built -and cached image can be re-used directly, allowing instantaneous dev container -starts. +When using the [Envbuilder Terraform provider](#envbuilder-terraform-provider), +a previously built and cached image can be re-used directly, allowing +instantaneous dev container starts. Developers can edit the `devcontainer.json` in their workspace to rebuild to iterate on their development environments. diff --git a/docs/admin/templates/troubleshooting.md b/docs/admin/templates/troubleshooting.md index 4f5dea02b2470..7c61dfaa8be65 100644 --- a/docs/admin/templates/troubleshooting.md +++ b/docs/admin/templates/troubleshooting.md @@ -58,9 +58,10 @@ terminating processes started by it or terminating the startup script itself (on Linux, `ps` and `kill` are useful tools). For tips on how to write a startup script that doesn't run forever, see the -[`startup_script`](#startup_script) section. For more ways to override the -startup script behavior, see the -[`startup_script_behavior`](#startup_script_behavior) section. +[`startup_script`](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#startup_script) +section. For more ways to override the startup script behavior, see the +[`startup_script_behavior`](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#startup_script_behavior) +section. Template authors can also set the [startup script behavior](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#startup_script_behavior) @@ -75,9 +76,9 @@ be aware that programs, files, or settings may be missing from your workspace. This can happen if the [startup script](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#startup_script) is still running or has exited with a non-zero status (see -[startup script error](#startup-script-error)). No action is necessary, but you -may want to -[start a new shell session](#session-was-started-before-the-startup-script-finished-web-terminal) +[startup script error](#startup-script-exited-with-an-error)). No action is +necessary, but you may want to +[start a new shell session](#session-was-started-before-the-startup-script-finished) after it has completed or check the [startup script logs](#debugging-the-startup-script) to see if there are any issues. diff --git a/docs/admin/users/sessions-tokens.md b/docs/admin/users/sessions-tokens.md index de9aa8b7526d0..1002a32c7bf73 100644 --- a/docs/admin/users/sessions-tokens.md +++ b/docs/admin/users/sessions-tokens.md @@ -4,10 +4,9 @@ Users can generate tokens to make API requests on behalf of themselves. ## Short-Lived Tokens (Sessions) -The [Coder CLI](../../install/cli.md) and [Backstage Plugin](#TODO) use -short-lived token to authenticate. To generate a short-lived session token on -behalf of your account, visit the following URL: -`https://coder.example.com/cli-auth` +The [Coder CLI](../../install/cli.md) and Backstage plugin use short-lived token +to authenticate. To generate a short-lived session token on behalf of your +account, visit the following URL: `https://coder.example.com/cli-auth` ### Session Durations diff --git a/docs/tutorials/example-guide.md b/docs/tutorials/example-guide.md index 0a16b5d830a03..b0a9de5e8dafd 100644 --- a/docs/tutorials/example-guide.md +++ b/docs/tutorials/example-guide.md @@ -1,9 +1,9 @@ # Guide Title (Only Visible in Github) December 13, 2023 @@ -11,15 +11,14 @@ December 13, 2023 --- This is a guide on how to make Coder guides, it is not listed on our -[official guides page](https://coder.com/docs/guides) in the docs. Intended for -those who don't frequently contribute documentation changes to the `coder/coder` +[official tutorials page](../tutorials/index.md) in the docs. Intended for those +who don't frequently contribute documentation changes to the `coder/coder` repository. ## Content -Defer to our -[Contributing/Documentation](https://coder.com/docs/contributing/documentation) -page for rules on technical writing. +Defer to our [Contributing/Documentation](../contributing/documentation.md) page +for rules on technical writing. ### Adding Photos From 33b0313b9e2d26da568bf2f8af5a0ffa17b91fa5 Mon Sep 17 00:00:00 2001 From: EdwardAngert <17991901+EdwardAngert@users.noreply.github.com> Date: Mon, 14 Oct 2024 20:03:16 +0000 Subject: [PATCH 11/14] fix link --- docs/user-guides/workspace-access/vscode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user-guides/workspace-access/vscode.md b/docs/user-guides/workspace-access/vscode.md index 17a08d8cb7d6d..cac2d722e0dcc 100644 --- a/docs/user-guides/workspace-access/vscode.md +++ b/docs/user-guides/workspace-access/vscode.md @@ -2,7 +2,7 @@ You can develop in your Coder workspace remotely with [VSCode](https://code.visualstudio.com/download). We support connecting with the -desktop client and VSCode in the browser with [code-server](#code-server). +desktop client and VSCode in the browser with [code-server](https://coder.com/docs/code-server/latest). ## VSCode Desktop From 905a683e5660a8841512b7cb95070c5d8bf52950 Mon Sep 17 00:00:00 2001 From: defelmnq Date: Wed, 16 Oct 2024 15:56:34 +0000 Subject: [PATCH 12/14] fix(doc): generate docs with new parameters --- docs/reference/cli/restart.md | 4 ++-- docs/reference/cli/start.md | 4 ++-- docs/reference/cli/update.md | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/reference/cli/restart.md b/docs/reference/cli/restart.md index c12cbde43ebcc..3b06efb6e4855 100644 --- a/docs/reference/cli/restart.md +++ b/docs/reference/cli/restart.md @@ -44,7 +44,7 @@ Prompt for one-time build options defined with ephemeral parameters. | Type | string-array | | Environment | $CODER_EPHEMERAL_PARAMETER | -Define ephemeral parameters in the format "name=value". +Set the value of ephemeral parameters defined in the template. The format is "name=value". ### --prompt-ephemeral-parameters @@ -53,7 +53,7 @@ Define ephemeral parameters in the format "name=value". | Type | bool | | Environment | $CODER_PROMPT_EPHEMERAL_PARAMETERS | -Prompt for values of ephemeral parameters described in the template. +Prompt to set values of ephemeral parameters defined in the template. If a value has been set via --ephemeral-parameter, it will not be prompted for. ### --parameter diff --git a/docs/reference/cli/start.md b/docs/reference/cli/start.md index ead65808fa4a6..9be64d5a83d85 100644 --- a/docs/reference/cli/start.md +++ b/docs/reference/cli/start.md @@ -44,7 +44,7 @@ Prompt for one-time build options defined with ephemeral parameters. | Type | string-array | | Environment | $CODER_EPHEMERAL_PARAMETER | -Define ephemeral parameters in the format "name=value". +Set the value of ephemeral parameters defined in the template. The format is "name=value". ### --prompt-ephemeral-parameters @@ -53,7 +53,7 @@ Define ephemeral parameters in the format "name=value". | Type | bool | | Environment | $CODER_PROMPT_EPHEMERAL_PARAMETERS | -Prompt for values of ephemeral parameters described in the template. +Prompt to set values of ephemeral parameters defined in the template. If a value has been set via --ephemeral-parameter, it will not be prompted for. ### --parameter diff --git a/docs/reference/cli/update.md b/docs/reference/cli/update.md index ddba535a7e10f..920fee20058b1 100644 --- a/docs/reference/cli/update.md +++ b/docs/reference/cli/update.md @@ -42,7 +42,7 @@ Prompt for one-time build options defined with ephemeral parameters. | Type | string-array | | Environment | $CODER_EPHEMERAL_PARAMETER | -Define ephemeral parameters in the format "name=value". +Set the value of ephemeral parameters defined in the template. The format is "name=value". ### --prompt-ephemeral-parameters @@ -51,7 +51,7 @@ Define ephemeral parameters in the format "name=value". | Type | bool | | Environment | $CODER_PROMPT_EPHEMERAL_PARAMETERS | -Prompt for values of ephemeral parameters described in the template. +Prompt to set values of ephemeral parameters defined in the template. If a value has been set via --ephemeral-parameter, it will not be prompted for. ### --parameter From 6b138a63a2e61d0d63210142633489e9b9dd0d7a Mon Sep 17 00:00:00 2001 From: defelmnq Date: Wed, 16 Oct 2024 16:34:53 +0000 Subject: [PATCH 13/14] fix(doc): generate docs with new parameters --- cli/testdata/coder_restart_--help.golden | 7 +++++-- cli/testdata/coder_start_--help.golden | 7 +++++-- cli/testdata/coder_update_--help.golden | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cli/testdata/coder_restart_--help.golden b/cli/testdata/coder_restart_--help.golden index c6355c4d2a292..6208b733457ab 100644 --- a/cli/testdata/coder_restart_--help.golden +++ b/cli/testdata/coder_restart_--help.golden @@ -19,7 +19,8 @@ OPTIONS: DEPRECATED: Use --prompt-ephemeral-parameters instead. --ephemeral-parameter string-array, $CODER_EPHEMERAL_PARAMETER - Define ephemeral parameters in the format "name=value". + Set the value of ephemeral parameters defined in the template. The + format is "name=value". --parameter string-array, $CODER_RICH_PARAMETER Rich parameter value in the format "name=value". @@ -28,7 +29,9 @@ OPTIONS: Rich parameter default values in the format "name=value". --prompt-ephemeral-parameters bool, $CODER_PROMPT_EPHEMERAL_PARAMETERS - Prompt for values of ephemeral parameters described in the template. + Prompt to set values of ephemeral parameters defined in the template. + If a value has been set via --ephemeral-parameter, it will not be + prompted for. --rich-parameter-file string, $CODER_RICH_PARAMETER_FILE Specify a file path with values for rich parameters defined in the diff --git a/cli/testdata/coder_start_--help.golden b/cli/testdata/coder_start_--help.golden index 3eafc7694e0da..be40782eb5ebf 100644 --- a/cli/testdata/coder_start_--help.golden +++ b/cli/testdata/coder_start_--help.golden @@ -19,7 +19,8 @@ OPTIONS: DEPRECATED: Use --prompt-ephemeral-parameters instead. --ephemeral-parameter string-array, $CODER_EPHEMERAL_PARAMETER - Define ephemeral parameters in the format "name=value". + Set the value of ephemeral parameters defined in the template. The + format is "name=value". --parameter string-array, $CODER_RICH_PARAMETER Rich parameter value in the format "name=value". @@ -28,7 +29,9 @@ OPTIONS: Rich parameter default values in the format "name=value". --prompt-ephemeral-parameters bool, $CODER_PROMPT_EPHEMERAL_PARAMETERS - Prompt for values of ephemeral parameters described in the template. + Prompt to set values of ephemeral parameters defined in the template. + If a value has been set via --ephemeral-parameter, it will not be + prompted for. --rich-parameter-file string, $CODER_RICH_PARAMETER_FILE Specify a file path with values for rich parameters defined in the diff --git a/cli/testdata/coder_update_--help.golden b/cli/testdata/coder_update_--help.golden index 646a1f6c0dd07..501447add29a7 100644 --- a/cli/testdata/coder_update_--help.golden +++ b/cli/testdata/coder_update_--help.golden @@ -21,7 +21,8 @@ OPTIONS: DEPRECATED: Use --prompt-ephemeral-parameters instead. --ephemeral-parameter string-array, $CODER_EPHEMERAL_PARAMETER - Define ephemeral parameters in the format "name=value". + Set the value of ephemeral parameters defined in the template. The + format is "name=value". --parameter string-array, $CODER_RICH_PARAMETER Rich parameter value in the format "name=value". @@ -30,7 +31,9 @@ OPTIONS: Rich parameter default values in the format "name=value". --prompt-ephemeral-parameters bool, $CODER_PROMPT_EPHEMERAL_PARAMETERS - Prompt for values of ephemeral parameters described in the template. + Prompt to set values of ephemeral parameters defined in the template. + If a value has been set via --ephemeral-parameter, it will not be + prompted for. --rich-parameter-file string, $CODER_RICH_PARAMETER_FILE Specify a file path with values for rich parameters defined in the From 5e11687bf23369a318405862b382cb2537e93e50 Mon Sep 17 00:00:00 2001 From: defelmnq Date: Wed, 16 Oct 2024 23:40:34 +0200 Subject: [PATCH 14/14] feat(cli): add back test on deprecated flags build-option and build-options --- cli/restart_test.go | 108 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/cli/restart_test.go b/cli/restart_test.go index b5ddace19fc9c..a17a9ba2a25cb 100644 --- a/cli/restart_test.go +++ b/cli/restart_test.go @@ -167,6 +167,114 @@ func TestRestart(t *testing.T) { Value: ephemeralParameterValue, }) }) + + t.Run("with deprecated build-options flag", func(t *testing.T) { + t.Parallel() + + client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) + owner := coderdtest.CreateFirstUser(t, client) + member, memberUser := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID) + version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, echoResponses) + coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) + template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID) + workspace := coderdtest.CreateWorkspace(t, member, template.ID) + coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) + + inv, root := clitest.New(t, "restart", workspace.Name, "--build-options") + clitest.SetupConfig(t, member, root) + doneChan := make(chan struct{}) + pty := ptytest.New(t).Attach(inv) + go func() { + defer close(doneChan) + err := inv.Run() + assert.NoError(t, err) + }() + + matches := []string{ + ephemeralParameterDescription, ephemeralParameterValue, + "Restart workspace?", "yes", + "Stopping workspace", "", + "Starting workspace", "", + "workspace has been restarted", "", + } + for i := 0; i < len(matches); i += 2 { + match := matches[i] + value := matches[i+1] + pty.ExpectMatch(match) + + if value != "" { + pty.WriteLine(value) + } + } + <-doneChan + + // Verify if build option is set + ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) + defer cancel() + + workspace, err := client.WorkspaceByOwnerAndName(ctx, memberUser.ID.String(), workspace.Name, codersdk.WorkspaceOptions{}) + require.NoError(t, err) + actualParameters, err := client.WorkspaceBuildParameters(ctx, workspace.LatestBuild.ID) + require.NoError(t, err) + require.Contains(t, actualParameters, codersdk.WorkspaceBuildParameter{ + Name: ephemeralParameterName, + Value: ephemeralParameterValue, + }) + }) + + t.Run("with deprecated build-option flag", func(t *testing.T) { + t.Parallel() + + client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) + owner := coderdtest.CreateFirstUser(t, client) + member, memberUser := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID) + version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, echoResponses) + coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) + template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID) + workspace := coderdtest.CreateWorkspace(t, member, template.ID) + coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) + + inv, root := clitest.New(t, "restart", workspace.Name, + "--build-option", fmt.Sprintf("%s=%s", ephemeralParameterName, ephemeralParameterValue)) + clitest.SetupConfig(t, member, root) + doneChan := make(chan struct{}) + pty := ptytest.New(t).Attach(inv) + go func() { + defer close(doneChan) + err := inv.Run() + assert.NoError(t, err) + }() + + matches := []string{ + "Restart workspace?", "yes", + "Stopping workspace", "", + "Starting workspace", "", + "workspace has been restarted", "", + } + for i := 0; i < len(matches); i += 2 { + match := matches[i] + value := matches[i+1] + pty.ExpectMatch(match) + + if value != "" { + pty.WriteLine(value) + } + } + <-doneChan + + // Verify if build option is set + ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) + defer cancel() + + workspace, err := client.WorkspaceByOwnerAndName(ctx, memberUser.ID.String(), workspace.Name, codersdk.WorkspaceOptions{}) + require.NoError(t, err) + actualParameters, err := client.WorkspaceBuildParameters(ctx, workspace.LatestBuild.ID) + require.NoError(t, err) + require.Contains(t, actualParameters, codersdk.WorkspaceBuildParameter{ + Name: ephemeralParameterName, + Value: ephemeralParameterValue, + }) + }) } func TestRestartWithParameters(t *testing.T) {