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

Commit f33052b

Browse files
authored
Revert "Revert "feat(cli): AutoStart education notice [ch7441] (#236)" (#249)" (#281)
This reverts commit 26b2794.
1 parent 94a596d commit f33052b

File tree

4 files changed

+62
-32
lines changed

4 files changed

+62
-32
lines changed

coder-sdk/env.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,18 @@ const (
7575

7676
// CreateEnvironmentRequest is used to configure a new environment.
7777
type CreateEnvironmentRequest struct {
78-
Name string `json:"name"`
79-
ImageID string `json:"image_id"`
80-
OrgID string `json:"org_id"`
81-
ImageTag string `json:"image_tag"`
82-
CPUCores float32 `json:"cpu_cores"`
83-
MemoryGB float32 `json:"memory_gb"`
84-
DiskGB int `json:"disk_gb"`
85-
GPUs int `json:"gpus"`
86-
UseContainerVM bool `json:"use_container_vm"`
87-
ResourcePoolID string `json:"resource_pool_id"`
88-
Namespace string `json:"namespace"`
78+
Name string `json:"name"`
79+
ImageID string `json:"image_id"`
80+
OrgID string `json:"org_id"`
81+
ImageTag string `json:"image_tag"`
82+
CPUCores float32 `json:"cpu_cores"`
83+
MemoryGB float32 `json:"memory_gb"`
84+
DiskGB int `json:"disk_gb"`
85+
GPUs int `json:"gpus"`
86+
UseContainerVM bool `json:"use_container_vm"`
87+
ResourcePoolID string `json:"resource_pool_id"`
88+
Namespace string `json:"namespace"`
89+
EnableAutoStart bool `json:"autostart_enabled"`
8990

9091
// Template comes from the parse template route on cemanager.
9192
// This field should never be manually populated

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: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"cdr.dev/coder-cli/coder-sdk"
1313
"cdr.dev/coder-cli/internal/coderutil"
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"
@@ -151,16 +152,17 @@ coder envs --user [email protected] ls -o json \
151152

152153
func createEnvCmd() *cobra.Command {
153154
var (
154-
org string
155-
cpu float32
156-
memory float32
157-
disk int
158-
gpus int
159-
img string
160-
tag string
161-
follow bool
162-
useCVM bool
163-
providerName string
155+
org string
156+
cpu float32
157+
memory float32
158+
disk int
159+
gpus int
160+
img string
161+
tag string
162+
follow bool
163+
useCVM bool
164+
providerName string
165+
enableAutostart bool
164166
)
165167

166168
cmd := &cobra.Command{
@@ -171,6 +173,9 @@ func createEnvCmd() *cobra.Command {
171173
Example: `# create a new environment using default resource amounts
172174
coder envs create my-new-env --image ubuntu
173175
coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ubuntu`,
176+
PreRun: func(cmd *cobra.Command, args []string) {
177+
autoStartInfo()
178+
},
174179
RunE: func(cmd *cobra.Command, args []string) error {
175180
ctx := cmd.Context()
176181
if img == "" {
@@ -214,17 +219,18 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
214219

215220
// ExactArgs(1) ensures our name value can't panic on an out of bounds.
216221
createReq := &coder.CreateEnvironmentRequest{
217-
Name: args[0],
218-
ImageID: importedImg.ID,
219-
OrgID: importedImg.OrganizationID,
220-
ImageTag: tag,
221-
CPUCores: cpu,
222-
MemoryGB: memory,
223-
DiskGB: disk,
224-
GPUs: gpus,
225-
UseContainerVM: useCVM,
226-
ResourcePoolID: provider.ID,
227-
Namespace: provider.DefaultNamespace,
222+
Name: args[0],
223+
ImageID: importedImg.ID,
224+
OrgID: importedImg.OrganizationID,
225+
ImageTag: tag,
226+
CPUCores: cpu,
227+
MemoryGB: memory,
228+
DiskGB: disk,
229+
GPUs: gpus,
230+
UseContainerVM: useCVM,
231+
ResourcePoolID: provider.ID,
232+
Namespace: provider.DefaultNamespace,
233+
EnableAutoStart: enableAutostart,
228234
}
229235

230236
// if any of these defaulted to their zero value we provision
@@ -269,6 +275,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
269275
cmd.Flags().StringVar(&providerName, "provider", "", "name of Workspace Provider with which to create the environment")
270276
cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild")
271277
cmd.Flags().BoolVar(&useCVM, "container-based-vm", false, "deploy the environment as a Container-based VM")
278+
cmd.Flags().BoolVar(&enableAutostart, "enable-autostart", false, "automatically start this environment at your preferred time.")
272279
_ = cmd.MarkFlagRequired("image")
273280
return cmd
274281
}
@@ -417,6 +424,9 @@ func editEnvCmd() *cobra.Command {
417424
Example: `coder envs edit back-end-env --cpu 4
418425
419426
coder envs edit back-end-env --disk 20`,
427+
PreRun: func(cmd *cobra.Command, args []string) {
428+
autoStartInfo()
429+
},
420430
RunE: func(cmd *cobra.Command, args []string) error {
421431
ctx := cmd.Context()
422432
client, err := newClient(ctx)
@@ -644,3 +654,18 @@ func buildUpdateReq(ctx context.Context, client coder.Client, conf updateConf) (
644654
}
645655
return &updateReq, nil
646656
}
657+
658+
// TODO (Grey): Remove education in a future non-patch release.
659+
func autoStartInfo() {
660+
var preferencesURI string
661+
662+
accessURI, err := config.URL.Read()
663+
if err != nil {
664+
// Error is fairly benign in this case, fallback to relative URI
665+
preferencesURI = "/preferences"
666+
} else {
667+
preferencesURI = fmt.Sprintf("%s%s", accessURI, "/preferences?tab=autostart")
668+
}
669+
670+
clog.LogInfo("⚡NEW: Automate daily environment startup", "Visit "+preferencesURI+" to configure your preferred time")
671+
}

internal/cmd/rebuild.go

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

0 commit comments

Comments
 (0)