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

Commit 08f1935

Browse files
authored
Stevenmasley/wac api (#253)
* envs-from-config to use wac template values * Add comment
1 parent 5bdd9fe commit 08f1935

File tree

2 files changed

+9
-35
lines changed

2 files changed

+9
-35
lines changed

coder-sdk/env.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package coder
22

33
import (
44
"context"
5+
"encoding/json"
56
"io"
67
"net/http"
78
"net/url"
@@ -84,6 +85,10 @@ type CreateEnvironmentRequest struct {
8485
GPUs int `json:"gpus"`
8586
Services []string `json:"services"`
8687
UseContainerVM bool `json:"use_container_vm"`
88+
89+
// Template comes from the parse template route on cemanager.
90+
// This field should never be manually populated
91+
Template Template `json:"template,omitempty"`
8792
}
8893

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

106111
// Template is a Workspaces As Code (WAC) template.
107-
type Template struct {
108-
Workspace Workspace `json:"workspace"`
109-
}
110-
111-
// Workspace defines values on the workspace that can be configured.
112-
type Workspace struct {
113-
Name string `json:"name"`
114-
Image string `json:"image"`
115-
ContainerBasedVM bool `json:"container-based-vm"`
116-
Resources Resources `json:"resources"`
117-
}
118-
119-
// Resources defines compute values that can be configured for a workspace.
120-
type Resources struct {
121-
CPU float32 `json:"cpu" `
122-
Memory float32 `json:"memory"`
123-
Disk int `json:"disk"`
124-
}
112+
// For now, let's not interpret it on the CLI level. We just need
113+
// to forward this as part of the create env request.
114+
type Template = json.RawMessage
125115

126116
// ParseTemplate parses a template config. It support both remote repositories and local files.
127117
// If a local file is specified then all other values in the request are ignored.

internal/cmd/envs.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -317,24 +317,8 @@ coder envs create-from-repo -f coder.yaml`,
317317
return xerrors.Errorf("parse environment template config: %w", err)
318318
}
319319

320-
importedImg, err := findImg(ctx, client, findImgConf{
321-
email: coder.Me,
322-
imgName: tpl.Workspace.Image,
323-
orgName: org,
324-
})
325-
if err != nil {
326-
return err
327-
}
328-
329320
env, err := client.CreateEnvironment(ctx, coder.CreateEnvironmentRequest{
330-
Name: tpl.Workspace.Name,
331-
ImageID: importedImg.ID,
332-
OrgID: importedImg.OrganizationID,
333-
ImageTag: importedImg.DefaultTag.Tag,
334-
CPUCores: tpl.Workspace.Resources.CPU,
335-
MemoryGB: tpl.Workspace.Resources.Memory,
336-
DiskGB: tpl.Workspace.Resources.Disk,
337-
UseContainerVM: tpl.Workspace.ContainerBasedVM,
321+
Template: tpl,
338322
})
339323
if err != nil {
340324
return xerrors.Errorf("create environment: %w", err)

0 commit comments

Comments
 (0)