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

Commit 2c14487

Browse files
committed
Add envs create command
1 parent 8917fb8 commit 2c14487

26 files changed

+179
-12
lines changed

ci/integration/envs_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package integration
2+
3+
import (
4+
"context"
5+
"regexp"
6+
"testing"
7+
8+
"cdr.dev/coder-cli/ci/tcli"
9+
)
10+
11+
// From Coder organization images
12+
const ubuntuImgID = "5f443b16-30652892427b955601330fa5"
13+
14+
func TestEnvsCLI(t *testing.T) {
15+
t.Parallel()
16+
17+
run(t, "coder-cli-env-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
18+
headlessLogin(ctx, t, c)
19+
20+
// Ensure binary is present.
21+
c.Run(ctx, "which coder").Assert(t,
22+
tcli.Success(),
23+
tcli.StdoutMatches("/usr/sbin/coder"),
24+
tcli.StderrEmpty(),
25+
)
26+
27+
// Minimum args not received.
28+
c.Run(ctx, "coder envs create").Assert(t,
29+
tcli.StderrMatches(regexp.QuoteMeta("accepts 1 arg(s), received 0")),
30+
tcli.Error(),
31+
)
32+
33+
// Successfully output help.
34+
c.Run(ctx, "coder envs create --help").Assert(t,
35+
tcli.Success(),
36+
tcli.StdoutMatches(regexp.QuoteMeta("Create a new environment under the active user.")),
37+
tcli.StderrEmpty(),
38+
)
39+
40+
// TODO(Faris) : uncomment this when we can safely purge the environments
41+
// the integrations tests would create in the sidecar
42+
// Successfully create environment.
43+
// c.Run(ctx, "coder envs create --image "+ubuntuImgID+" test-ubuntu").Assert(t,
44+
// tcli.Success(),
45+
// // why does flog.Success write to stderr?
46+
// tcli.StderrMatches(regexp.QuoteMeta("Successfully created environment \"test-ubuntu\"")),
47+
// )
48+
49+
// Invalid environment name should fail.
50+
c.Run(ctx, "coder envs create --image "+ubuntuImgID+" this-IS-an-invalid-EnvironmentName").Assert(t,
51+
tcli.Error(),
52+
tcli.StderrMatches(regexp.QuoteMeta("environment name must conform to regex ^[a-z0-9]([a-z0-9-]+)?")),
53+
)
54+
55+
// TODO(Faris) : uncomment this when we can safely purge the environments
56+
// the integrations tests would create in the sidecar
57+
// Successfully provision environment with fractional resource amounts
58+
// c.Run(ctx, fmt.Sprintf(`coder envs create -i %s -c 1.2 -m 1.4 non-whole-resource-amounts`, ubuntuImgID)).Assert(t,
59+
// tcli.Success(),
60+
// tcli.StderrMatches(regexp.QuoteMeta("Successfully created environment \"non-whole-resource-amounts\"")),
61+
// )
62+
63+
// Image does not exist should fail.
64+
c.Run(ctx, "coder envs create --image does-not-exist env-will-not-be-created").Assert(t,
65+
tcli.Error(),
66+
tcli.StderrMatches(regexp.QuoteMeta("does not exist")),
67+
)
68+
})
69+
}

ci/steps/gendocs.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ rm -rf ./docs
1111
mkdir ./docs
1212
go run ./cmd/coder gen-docs ./docs
1313

14-
# remove cobra footer from each file
15-
for filename in ./docs/*.md; do
16-
trimmed=$(head -n -1 "$filename")
17-
echo "$trimmed" >$filename
18-
done
19-
2014
if [[ ${CI-} && $(git ls-files --other --modified --exclude-standard) ]]; then
2115
echo "Documentation needs generation:"
2216
git -c color.ui=always status | grep --color=no '\e\[31m'

coder-sdk/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ type CreateEnvironmentRequest struct {
7878
ImageID string `json:"image_id"`
7979
ImageTag string `json:"image_tag"`
8080
CPUCores float32 `json:"cpu_cores"`
81-
MemoryGB int `json:"memory_gb"`
81+
MemoryGB float32 `json:"memory_gb"`
8282
DiskGB int `json:"disk_gb"`
8383
GPUs int `json:"gpus"`
8484
Services []string `json:"services"`

docs/coder.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ coder provides a CLI for working with an existing Coder Enterprise installation
2525
* [coder sync](coder_sync.md) - Establish a one way directory sync to a Coder environment
2626
* [coder urls](coder_urls.md) - Interact with environment DevURLs
2727
* [coder users](coder_users.md) - Interact with Coder user accounts
28+

docs/coder_completion.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ MacOS:
6767
### SEE ALSO
6868

6969
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
70+

docs/coder_config-ssh.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ coder config-ssh [flags]
2727
### SEE ALSO
2828

2929
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
30+

docs/coder_envs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ Perform operations on the Coder environments owned by the active user.
2424
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
2525
* [coder envs ls](coder_envs_ls.md) - list all environments owned by the active user
2626
* [coder envs stop](coder_envs_stop.md) - stop Coder environments by name
27+

docs/coder_envs_ls.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ coder envs ls [flags]
2727
### SEE ALSO
2828

2929
* [coder envs](coder_envs.md) - Interact with Coder environments
30+

docs/coder_envs_stop.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ coder envs --user charlie@coder.com ls -o json \
4141
### SEE ALSO
4242

4343
* [coder envs](coder_envs.md) - Interact with Coder environments
44+

docs/coder_login.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ coder login [Coder Enterprise URL eg. https://my.coder.domain/] [flags]
2525
### SEE ALSO
2626

2727
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
28+

0 commit comments

Comments
 (0)