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..db755509 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" @@ -151,15 +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 + org string + cpu float32 + memory float32 + disk int + gpus int + img string + tag string + follow bool + useCVM bool + enableAutostart 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: enableAutostart, } // 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(&enableAutostart, "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,18 @@ 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 + + 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)