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

feat(cli): AutoStart education notice [ch7441] #236

Merged
merged 4 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions coder-sdk/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions docs/coder_envs_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 43 additions & 18 deletions internal/cmd/envs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -151,15 +152,16 @@ coder envs --user [email protected] 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{
Expand All @@ -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 == "" {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
3 changes: 3 additions & 0 deletions internal/cmd/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down