Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 51f8a81

Browse files
committed
Reset
1 parent ca68fdb commit 51f8a81

File tree

4 files changed

+48
-19
lines changed

4 files changed

+48
-19
lines changed

coder-sdk/env.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,17 @@ const (
7474

7575
// CreateEnvironmentRequest is used to configure a new environment.
7676
type CreateEnvironmentRequest struct {
77-
Name string `json:"name"`
78-
ImageID string `json:"image_id"`
79-
OrgID string `json:"org_id"`
80-
ImageTag string `json:"image_tag"`
81-
CPUCores float32 `json:"cpu_cores"`
82-
MemoryGB float32 `json:"memory_gb"`
83-
DiskGB int `json:"disk_gb"`
84-
GPUs int `json:"gpus"`
85-
Services []string `json:"services"`
86-
UseContainerVM bool `json:"use_container_vm"`
77+
Name string `json:"name"`
78+
ImageID string `json:"image_id"`
79+
OrgID string `json:"org_id"`
80+
ImageTag string `json:"image_tag"`
81+
CPUCores float32 `json:"cpu_cores"`
82+
MemoryGB float32 `json:"memory_gb"`
83+
DiskGB int `json:"disk_gb"`
84+
GPUs int `json:"gpus"`
85+
Services []string `json:"services"`
86+
UseContainerVM bool `json:"use_container_vm"`
87+
EnableAutoStart bool `json:"autostart_enabled"`
8788
}
8889

8990
// CreateEnvironment sends a request to create an environment.

docs/coder_envs_create.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
2424
--container-based-vm deploy the environment as a Container-based VM
2525
-c, --cpu float32 number of cpu cores the environment should be provisioned with.
2626
-d, --disk int GB of disk storage an environment should be provisioned with.
27+
--enable-autostart automatically start this environment at your preferred time.
2728
--follow follow buildlog after initiating rebuild
2829
-g, --gpus int number GPUs an environment should be provisioned with.
2930
-h, --help help for create

internal/cmd/envs.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212

1313
"cdr.dev/coder-cli/coder-sdk"
14+
"cdr.dev/coder-cli/internal/config"
1415
"cdr.dev/coder-cli/internal/x/xcobra"
1516
"cdr.dev/coder-cli/pkg/clog"
1617
"cdr.dev/coder-cli/pkg/tablewriter"
@@ -160,6 +161,7 @@ func createEnvCmd() *cobra.Command {
160161
tag string
161162
follow bool
162163
useCVM bool
164+
useAS bool
163165
)
164166

165167
cmd := &cobra.Command{
@@ -170,6 +172,9 @@ func createEnvCmd() *cobra.Command {
170172
Example: `# create a new environment using default resource amounts
171173
coder envs create my-new-env --image ubuntu
172174
coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ubuntu`,
175+
PreRun: func(cmd *cobra.Command, args []string) {
176+
autoStartInfo()
177+
},
173178
RunE: func(cmd *cobra.Command, args []string) error {
174179
ctx := cmd.Context()
175180
if img == "" {
@@ -200,15 +205,16 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
200205

201206
// ExactArgs(1) ensures our name value can't panic on an out of bounds.
202207
createReq := &coder.CreateEnvironmentRequest{
203-
Name: args[0],
204-
ImageID: importedImg.ID,
205-
OrgID: importedImg.OrganizationID,
206-
ImageTag: tag,
207-
CPUCores: cpu,
208-
MemoryGB: memory,
209-
DiskGB: disk,
210-
GPUs: gpus,
211-
UseContainerVM: useCVM,
208+
Name: args[0],
209+
ImageID: importedImg.ID,
210+
OrgID: importedImg.OrganizationID,
211+
ImageTag: tag,
212+
CPUCores: cpu,
213+
MemoryGB: memory,
214+
DiskGB: disk,
215+
GPUs: gpus,
216+
UseContainerVM: useCVM,
217+
EnableAutoStart: useAS,
212218
}
213219

214220
// 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
252258
cmd.Flags().StringVarP(&img, "image", "i", "", "name of the image to base the environment off of.")
253259
cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild")
254260
cmd.Flags().BoolVar(&useCVM, "container-based-vm", false, "deploy the environment as a Container-based VM")
261+
cmd.Flags().BoolVar(&useAS, "enable-autostart", false, "automatically start this environment at your preferred time.")
255262
_ = cmd.MarkFlagRequired("image")
256263
return cmd
257264
}
@@ -384,6 +391,9 @@ func editEnvCmd() *cobra.Command {
384391
Example: `coder envs edit back-end-env --cpu 4
385392
386393
coder envs edit back-end-env --disk 20`,
394+
PreRun: func(cmd *cobra.Command, args []string) {
395+
autoStartInfo()
396+
},
387397
RunE: func(cmd *cobra.Command, args []string) error {
388398
ctx := cmd.Context()
389399
client, err := newClient(ctx)
@@ -611,3 +621,17 @@ func buildUpdateReq(ctx context.Context, client *coder.Client, conf updateConf)
611621
}
612622
return &updateReq, nil
613623
}
624+
625+
func autoStartInfo() {
626+
var preferencesURI string
627+
628+
accessURI, err := config.URL.Read()
629+
if err != nil {
630+
// Error is fairly benign in this case, fallback to relative URI
631+
preferencesURI = "/preferences"
632+
} else {
633+
preferencesURI = fmt.Sprintf("%s%s", accessURI, "/preferences?tab=autostart")
634+
}
635+
636+
clog.LogInfo("⚡NEW: Automate daily environment startup", "Visit "+preferencesURI+" to configure your preferred time")
637+
}

internal/cmd/rebuild.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ func rebuildEnvCommand() *cobra.Command {
2929
Args: xcobra.ExactArgs(1),
3030
Example: `coder envs rebuild front-end-env --follow
3131
coder envs rebuild backend-env --force`,
32+
PreRun: func(cmd *cobra.Command, args []string) {
33+
autoStartInfo()
34+
},
3235
RunE: func(cmd *cobra.Command, args []string) error {
3336
ctx := cmd.Context()
3437
client, err := newClient(ctx)

0 commit comments

Comments
 (0)