From 51f8a817c40847b90f122d6fb08e6a3f772d648e Mon Sep 17 00:00:00 2001 From: G r e y Date: Tue, 16 Feb 2021 20:17:57 +0000 Subject: [PATCH 1/4] Reset --- coder-sdk/env.go | 21 ++++++++++---------- docs/coder_envs_create.md | 1 + internal/cmd/envs.go | 42 ++++++++++++++++++++++++++++++--------- internal/cmd/rebuild.go | 3 +++ 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/coder-sdk/env.go b/coder-sdk/env.go index d28e6fb7..9ef54f11 100644 --- a/coder-sdk/env.go +++ b/coder-sdk/env.go @@ -74,16 +74,17 @@ const ( // CreateEnvironmentRequest is used to configure a new environment. type CreateEnvironmentRequest struct { - Name string `json:"name"` - ImageID string `json:"image_id"` - OrgID string `json:"org_id"` - ImageTag string `json:"image_tag"` - CPUCores float32 `json:"cpu_cores"` - MemoryGB float32 `json:"memory_gb"` - DiskGB int `json:"disk_gb"` - GPUs int `json:"gpus"` - Services []string `json:"services"` - UseContainerVM bool `json:"use_container_vm"` + Name string `json:"name"` + ImageID string `json:"image_id"` + OrgID string `json:"org_id"` + ImageTag string `json:"image_tag"` + CPUCores float32 `json:"cpu_cores"` + MemoryGB float32 `json:"memory_gb"` + DiskGB int `json:"disk_gb"` + GPUs int `json:"gpus"` + Services []string `json:"services"` + UseContainerVM bool `json:"use_container_vm"` + EnableAutoStart bool `json:"autostart_enabled"` } // CreateEnvironment sends a request to create an environment. diff --git a/docs/coder_envs_create.md b/docs/coder_envs_create.md index d728e34b..ea23ff94 100644 --- a/docs/coder_envs_create.md +++ b/docs/coder_envs_create.md @@ -24,6 +24,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub --container-based-vm deploy the environment as a Container-based VM -c, --cpu float32 number of cpu cores the environment should be provisioned with. -d, --disk int GB of disk storage an environment should be provisioned with. + --enable-autostart automatically start this environment at your preferred time. --follow follow buildlog after initiating rebuild -g, --gpus int number GPUs an environment should be provisioned with. -h, --help help for create diff --git a/internal/cmd/envs.go b/internal/cmd/envs.go index ae14b528..13376403 100644 --- a/internal/cmd/envs.go +++ b/internal/cmd/envs.go @@ -11,6 +11,7 @@ import ( "os" "cdr.dev/coder-cli/coder-sdk" + "cdr.dev/coder-cli/internal/config" "cdr.dev/coder-cli/internal/x/xcobra" "cdr.dev/coder-cli/pkg/clog" "cdr.dev/coder-cli/pkg/tablewriter" @@ -160,6 +161,7 @@ func createEnvCmd() *cobra.Command { tag string follow bool useCVM bool + useAS bool ) cmd := &cobra.Command{ @@ -170,6 +172,9 @@ func createEnvCmd() *cobra.Command { Example: `# create a new environment using default resource amounts coder envs create my-new-env --image ubuntu coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ubuntu`, + PreRun: func(cmd *cobra.Command, args []string) { + autoStartInfo() + }, RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() if img == "" { @@ -200,15 +205,16 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub // ExactArgs(1) ensures our name value can't panic on an out of bounds. createReq := &coder.CreateEnvironmentRequest{ - Name: args[0], - ImageID: importedImg.ID, - OrgID: importedImg.OrganizationID, - ImageTag: tag, - CPUCores: cpu, - MemoryGB: memory, - DiskGB: disk, - GPUs: gpus, - UseContainerVM: useCVM, + Name: args[0], + ImageID: importedImg.ID, + OrgID: importedImg.OrganizationID, + ImageTag: tag, + CPUCores: cpu, + MemoryGB: memory, + DiskGB: disk, + GPUs: gpus, + UseContainerVM: useCVM, + EnableAutoStart: useAS, } // if any of these defaulted to their zero value we provision @@ -252,6 +258,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub cmd.Flags().StringVarP(&img, "image", "i", "", "name of the image to base the environment off of.") cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild") cmd.Flags().BoolVar(&useCVM, "container-based-vm", false, "deploy the environment as a Container-based VM") + cmd.Flags().BoolVar(&useAS, "enable-autostart", false, "automatically start this environment at your preferred time.") _ = cmd.MarkFlagRequired("image") return cmd } @@ -384,6 +391,9 @@ func editEnvCmd() *cobra.Command { Example: `coder envs edit back-end-env --cpu 4 coder envs edit back-end-env --disk 20`, + PreRun: func(cmd *cobra.Command, args []string) { + autoStartInfo() + }, RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() client, err := newClient(ctx) @@ -611,3 +621,17 @@ func buildUpdateReq(ctx context.Context, client *coder.Client, conf updateConf) } return &updateReq, nil } + +func autoStartInfo() { + var preferencesURI string + + accessURI, err := config.URL.Read() + if err != nil { + // Error is fairly benign in this case, fallback to relative URI + preferencesURI = "/preferences" + } else { + preferencesURI = fmt.Sprintf("%s%s", accessURI, "/preferences?tab=autostart") + } + + clog.LogInfo("⚡NEW: Automate daily environment startup", "Visit "+preferencesURI+" to configure your preferred time") +} diff --git a/internal/cmd/rebuild.go b/internal/cmd/rebuild.go index 1eff6e08..7b39d39d 100644 --- a/internal/cmd/rebuild.go +++ b/internal/cmd/rebuild.go @@ -29,6 +29,9 @@ func rebuildEnvCommand() *cobra.Command { Args: xcobra.ExactArgs(1), Example: `coder envs rebuild front-end-env --follow coder envs rebuild backend-env --force`, + PreRun: func(cmd *cobra.Command, args []string) { + autoStartInfo() + }, RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() client, err := newClient(ctx) From f6304209012749e4af2aa29cd7d915176ca48d82 Mon Sep 17 00:00:00 2001 From: G r e y Date: Tue, 16 Feb 2021 20:38:53 +0000 Subject: [PATCH 2/4] Clarify variable --- internal/cmd/envs.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/cmd/envs.go b/internal/cmd/envs.go index 13376403..fbefae76 100644 --- a/internal/cmd/envs.go +++ b/internal/cmd/envs.go @@ -152,16 +152,16 @@ coder envs --user charlie@coder.com ls -o json \ func createEnvCmd() *cobra.Command { var ( - org string - cpu float32 - memory float32 - disk int - gpus int - img string - tag string - follow bool - useCVM bool - useAS bool + org string + cpu float32 + memory float32 + disk int + gpus int + img string + tag string + follow bool + useCVM bool + enableAutostart bool ) cmd := &cobra.Command{ @@ -214,7 +214,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub DiskGB: disk, GPUs: gpus, UseContainerVM: useCVM, - EnableAutoStart: useAS, + EnableAutoStart: enableAutostart, } // if any of these defaulted to their zero value we provision @@ -258,7 +258,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub cmd.Flags().StringVarP(&img, "image", "i", "", "name of the image to base the environment off of.") cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild") cmd.Flags().BoolVar(&useCVM, "container-based-vm", false, "deploy the environment as a Container-based VM") - cmd.Flags().BoolVar(&useAS, "enable-autostart", false, "automatically start this environment at your preferred time.") + cmd.Flags().BoolVar(&enableAutostart, "enable-autostart", false, "automatically start this environment at your preferred time.") _ = cmd.MarkFlagRequired("image") return cmd } From 773f456e9784686a2461f2297600bf6bf68a9ec3 Mon Sep 17 00:00:00 2001 From: G r e y Date: Tue, 16 Feb 2021 20:41:23 +0000 Subject: [PATCH 3/4] Add TODO --- internal/cmd/envs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/cmd/envs.go b/internal/cmd/envs.go index fbefae76..623df8df 100644 --- a/internal/cmd/envs.go +++ b/internal/cmd/envs.go @@ -622,6 +622,7 @@ func buildUpdateReq(ctx context.Context, client *coder.Client, conf updateConf) return &updateReq, nil } +// TODO (Grey): Remove education in a future non-patch release func autoStartInfo() { var preferencesURI string From 515e6c06b6670221bb6972aecfbc7acd1f769d3c Mon Sep 17 00:00:00 2001 From: G r e y Date: Tue, 16 Feb 2021 20:42:49 +0000 Subject: [PATCH 4/4] End comment in period --- internal/cmd/envs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cmd/envs.go b/internal/cmd/envs.go index 623df8df..db755509 100644 --- a/internal/cmd/envs.go +++ b/internal/cmd/envs.go @@ -622,7 +622,7 @@ func buildUpdateReq(ctx context.Context, client *coder.Client, conf updateConf) return &updateReq, nil } -// TODO (Grey): Remove education in a future non-patch release +// TODO (Grey): Remove education in a future non-patch release. func autoStartInfo() { var preferencesURI string