Skip to content

Commit

Permalink
Revert "Revert "feat(cli): AutoStart education notice [ch7441] (#236)" (
Browse files Browse the repository at this point in the history
#249)" (#281)

This reverts commit 26b2794.
  • Loading branch information
greyscaled committed Mar 11, 2021
1 parent 94a596d commit f33052b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 32 deletions.
23 changes: 12 additions & 11 deletions coder-sdk/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,18 @@ 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"`
UseContainerVM bool `json:"use_container_vm"`
ResourcePoolID string `json:"resource_pool_id"`
Namespace string `json:"namespace"`
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"`
UseContainerVM bool `json:"use_container_vm"`
ResourcePoolID string `json:"resource_pool_id"`
Namespace string `json:"namespace"`
EnableAutoStart bool `json:"autostart_enabled"`

// Template comes from the parse template route on cemanager.
// This field should never be manually populated
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
67 changes: 46 additions & 21 deletions internal/cmd/envs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"cdr.dev/coder-cli/coder-sdk"
"cdr.dev/coder-cli/internal/coderutil"
"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,16 +152,17 @@ 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
providerName string
org string
cpu float32
memory float32
disk int
gpus int
img string
tag string
follow bool
useCVM bool
providerName string
enableAutostart bool
)

cmd := &cobra.Command{
Expand All @@ -171,6 +173,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 @@ -214,17 +219,18 @@ 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,
ResourcePoolID: provider.ID,
Namespace: provider.DefaultNamespace,
Name: args[0],
ImageID: importedImg.ID,
OrgID: importedImg.OrganizationID,
ImageTag: tag,
CPUCores: cpu,
MemoryGB: memory,
DiskGB: disk,
GPUs: gpus,
UseContainerVM: useCVM,
ResourcePoolID: provider.ID,
Namespace: provider.DefaultNamespace,
EnableAutoStart: enableAutostart,
}

// if any of these defaulted to their zero value we provision
Expand Down Expand Up @@ -269,6 +275,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
cmd.Flags().StringVar(&providerName, "provider", "", "name of Workspace Provider with which to create the environment")
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 @@ -417,6 +424,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 @@ -644,3 +654,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 @@ -27,6 +27,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

0 comments on commit f33052b

Please sign in to comment.