Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
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
26 changes: 8 additions & 18 deletions coder-sdk/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package coder

import (
"context"
"encoding/json"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -84,6 +85,10 @@ type CreateEnvironmentRequest struct {
GPUs int `json:"gpus"`
Services []string `json:"services"`
UseContainerVM bool `json:"use_container_vm"`

// Template comes from the parse template route on cemanager.
// This field should never be manually populated
Template Template `json:"template,omitempty"`
}

// CreateEnvironment sends a request to create an environment.
Expand All @@ -104,24 +109,9 @@ type ParseTemplateRequest struct {
}

// Template is a Workspaces As Code (WAC) template.
type Template struct {
Workspace Workspace `json:"workspace"`
}

// Workspace defines values on the workspace that can be configured.
type Workspace struct {
Name string `json:"name"`
Image string `json:"image"`
ContainerBasedVM bool `json:"container-based-vm"`
Resources Resources `json:"resources"`
}

// Resources defines compute values that can be configured for a workspace.
type Resources struct {
CPU float32 `json:"cpu" `
Memory float32 `json:"memory"`
Disk int `json:"disk"`
}
// For now, let's not interpret it on the CLI level. We just need
// to forward this as part of the create env request.
type Template = json.RawMessage

// ParseTemplate parses a template config. It support both remote repositories and local files.
// If a local file is specified then all other values in the request are ignored.
Expand Down
18 changes: 1 addition & 17 deletions internal/cmd/envs.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,24 +317,8 @@ coder envs create-from-repo -f coder.yaml`,
return xerrors.Errorf("parse environment template config: %w", err)
}

importedImg, err := findImg(ctx, client, findImgConf{
email: coder.Me,
imgName: tpl.Workspace.Image,
orgName: org,
})
if err != nil {
return err
}

env, err := client.CreateEnvironment(ctx, coder.CreateEnvironmentRequest{
Name: tpl.Workspace.Name,
ImageID: importedImg.ID,
OrgID: importedImg.OrganizationID,
ImageTag: importedImg.DefaultTag.Tag,
CPUCores: tpl.Workspace.Resources.CPU,
MemoryGB: tpl.Workspace.Resources.Memory,
DiskGB: tpl.Workspace.Resources.Disk,
UseContainerVM: tpl.Workspace.ContainerBasedVM,
Template: tpl,
})
if err != nil {
return xerrors.Errorf("create environment: %w", err)
Expand Down