Skip to content

Commit 8c38a74

Browse files
committed
Merge remote-tracking branch 'origin/main' into cj/1783/updating-workspace-ttl-updates-deadline
2 parents 85da57b + 567e4af commit 8c38a74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2594
-867
lines changed

.gitattributes

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ coderd/database/dump.sql linguist-generated=true
33
peerbroker/proto/*.go linguist-generated=true
44
provisionerd/proto/*.go linguist-generated=true
55
provisionersdk/proto/*.go linguist-generated=true
6+
*.tfplan.json linguist-generated=true
7+
*.tfstate.json linguist-generated=true
8+
*.tfstate.dot linguist-generated=true
9+
*.tfplan.dot linguist-generated=true

.vscode/settings.json

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"kirsle",
3939
"ldflags",
4040
"manifoldco",
41+
"mapstructure",
4142
"mattn",
4243
"mitchellh",
4344
"moby",
@@ -67,9 +68,11 @@
6768
"tcpip",
6869
"TCSETS",
6970
"templateversions",
71+
"testdata",
7072
"testid",
7173
"tfexec",
7274
"tfjson",
75+
"tfplan",
7376
"tfstate",
7477
"trimprefix",
7578
"turnconn",
@@ -83,6 +86,7 @@
8386
"workspaceapp",
8487
"workspaceapps",
8588
"workspacebuilds",
89+
"workspacename",
8690
"wsconncache",
8791
"xerrors",
8892
"xstate",

README.md

+18-95
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,30 @@ Discord"](https://img.shields.io/badge/join-us%20on%20Discord-gray.svg?longCache
88
Follow](https://img.shields.io/twitter/follow/CoderHQ?label=%40CoderHQ&style=social)](https://twitter.com/coderhq)
99
[![codecov](https://codecov.io/gh/coder/coder/branch/main/graph/badge.svg?token=TNLW3OAP6G)](https://codecov.io/gh/coder/coder)
1010

11-
## Run Coder *now*
12-
13-
```curl -L https://coder.com/install.sh | sh```
14-
15-
## What Coder does
16-
Coder creates remote development machines so you can develop your code from anywhere. #coder
17-
18-
> **Note**:
19-
> Coder is in an alpha state, but any serious bugs are P1 for us so [please report them](https://github.com/coder/coder/issues/new/choose).
11+
Coder creates remote development machines so your team can develop from anywhere.
2012

2113
<p align="center">
2214
<img src="./docs/images/hero-image.png">
2315
</p>
2416

25-
**Code more**
26-
27-
- Build and test faster
28-
- Leveraging cloud CPUs, RAM, network speeds, etc.
29-
- Access your environment from any place on any client (even an iPad)
30-
- Onboard instantly then stay up to date continuously
31-
3217
**Manage less**
3318

3419
- Ensure your entire team is using the same tools and resources
3520
- Rollout critical updates to your developers with one command
3621
- Automatically shut down expensive cloud resources
3722
- Keep your source code and data behind your firewall
3823

39-
## How it works
40-
41-
Coder workspaces are represented with Terraform. But, no Terraform knowledge is
42-
required to get started. We have a database of pre-made templates built into the
43-
product.
44-
45-
<p align="center">
46-
<img src="./docs/images/providers-compute.png">
47-
</p>
48-
49-
Coder workspaces don't stop at compute. You can add storage buckets, secrets, sidecars
50-
and whatever else Terraform lets you dream up.
51-
52-
[Learn more about managing infrastructure.](./docs/templates.md)
53-
54-
## IDE Support
24+
**Code more**
5525

56-
You can use any Web IDE ([code-server](https://github.com/coder/code-server), [projector](https://github.com/JetBrains/projector-server), [Jupyter](https://jupyter.org/), etc.), [JetBrains Gateway](https://www.jetbrains.com/remote-development/gateway/), [VS Code Remote](https://code.visualstudio.com/docs/remote/ssh-tutorial) or even a file sync such as [mutagen](https://mutagen.io/).
26+
- Build and test faster
27+
- Leveraging cloud CPUs, RAM, network speeds, etc.
28+
- Access your environment from any place on any client (even an iPad)
29+
- Onboard instantly then stay up to date continuously
5730

58-
<p align="center">
59-
<img src="./docs/images/ide-icons.svg" height=72>
60-
</p>
31+
## Getting Started
6132

62-
## Installing Coder
33+
> **Note**:
34+
> Coder is in an alpha state. [Report issues here](https://github.com/coder/coder/issues/new).
6335
6436
There are a few ways to install Coder: [install script](./docs/install.md#installsh) (macOS, Linux), [docker-compose](./docs/install.md#docker-compose), or [manually](./docs/install.md#manual) via the latest release (macOS, Windows, and Linux).
6537

@@ -81,66 +53,11 @@ Once installed, you can run a temporary deployment in dev mode (all data is in-m
8153
coder server --dev
8254
```
8355

84-
Use `coder --help` to get a complete list of flags and environment variables.
85-
86-
## Creating your first template and workspace
87-
88-
In a new terminal window, run the following to copy a sample template:
89-
90-
```bash
91-
coder templates init
92-
```
93-
94-
Follow the CLI instructions to modify and create the template specific for your
95-
usage (e.g., a template to **Develop in Linux on Google Cloud**).
96-
97-
Create a workspace using your template:
98-
99-
```bash
100-
coder create --template="yourTemplate" <workspaceName>
101-
```
102-
103-
Connect to your workspace via SSH:
104-
105-
```bash
106-
coder ssh <workspaceName>
107-
```
108-
109-
## Modifying templates
110-
111-
You can edit the Terraform template using a sample template:
112-
113-
```sh
114-
coder templates init
115-
cd gcp-linux/
116-
vim main.tf
117-
coder templates update gcp-linux
118-
```
56+
Use `coder --help` to get a complete list of flags and environment variables. Use our [quickstart guide](./docs/quickstart.md) for a full walkthrough.
11957

12058
## Documentation
12159

122-
- [About Coder](./docs/about.md#about-coder)
123-
- [Why remote development](./docs/about.md#why-remote-development)
124-
- [Why Coder](./docs/about.md#why-coder)
125-
- [What Coder is not](./docs/about.md#what-coder-is-not)
126-
- [Comparison: Coder vs. [product]](./docs/about.md#comparison)
127-
- [Templates](./docs/templates.md)
128-
- [Manage templates](./docs/templates.md#manage-templates)
129-
- [Persistent and ephemeral
130-
resources](./docs/templates.md#persistent-and-ephemeral-resources)
131-
- [Parameters](./docs/templates.md#parameters)
132-
- [Workspaces](./docs/workspaces.md)
133-
- [Create workspaces](./docs/workspaces.md#create-workspaces)
134-
- [Connect with SSH](./docs/workspaces.md#connect-with-ssh)
135-
- [Editors and IDEs](./docs/workspaces.md#editors-and-ides)
136-
- [Workspace lifecycle](./docs/workspaces.md#workspace-lifecycle)
137-
- [Updating workspaces](./docs/workspaces.md#updating-workspaces)
138-
139-
## Community
140-
141-
Join the community on [Discord](https://discord.gg/coder) and [Twitter](https://twitter.com/coderhq) #coder!
142-
143-
[Suggest improvements and report problems](https://github.com/coder/coder/issues/new/choose)
60+
Visit our docs [here](./docs/index.md).
14461

14562
## Comparison
14663

@@ -155,7 +72,13 @@ Please file [an issue](https://github.com/coder/coder/issues/new) if any informa
15572

15673
---
15774

158-
_As of 5/27/22_
75+
_Last updated: 5/27/22_
76+
77+
## Community and Support
78+
79+
Join our community on [Discord](https://discord.gg/coder) and [Twitter](https://twitter.com/coderhq)!
80+
81+
[Suggest improvements and report problems](https://github.com/coder/coder/issues/new/choose)
15982

16083
## Contributing
16184

cli/create.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func create() *cobra.Command {
4949
workspaceName, err = cliui.Prompt(cmd, cliui.PromptOptions{
5050
Text: "Specify a name for your workspace:",
5151
Validate: func(workspaceName string) error {
52-
_, err = client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, workspaceName)
52+
_, err = client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, workspaceName, codersdk.WorkspaceByOwnerAndNameParams{})
5353
if err == nil {
5454
return xerrors.Errorf("A workspace already exists named %q!", workspaceName)
5555
}
@@ -61,7 +61,7 @@ func create() *cobra.Command {
6161
}
6262
}
6363

64-
_, err = client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, workspaceName)
64+
_, err = client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, workspaceName, codersdk.WorkspaceByOwnerAndNameParams{})
6565
if err == nil {
6666
return xerrors.Errorf("A workspace already exists named %q!", workspaceName)
6767
}
@@ -242,19 +242,7 @@ func create() *cobra.Command {
242242
return err
243243
}
244244

245-
resources, err = client.WorkspaceResourcesByBuild(cmd.Context(), workspace.LatestBuild.ID)
246-
if err != nil {
247-
return err
248-
}
249-
250-
err = cliui.WorkspaceResources(cmd.OutOrStdout(), resources, cliui.WorkspaceResourcesOptions{
251-
WorkspaceName: workspaceName,
252-
})
253-
if err != nil {
254-
return err
255-
}
256-
257-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "The %s workspace has been created!\n", cliui.Styles.Keyword.Render(workspace.Name))
245+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nThe %s workspace has been created!\n", cliui.Styles.Keyword.Render(workspace.Name))
258246
return nil
259247
},
260248
}

cli/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func namedWorkspace(cmd *cobra.Command, client *codersdk.Client, identifier stri
214214
return codersdk.Workspace{}, xerrors.Errorf("invalid workspace name: %q", identifier)
215215
}
216216

217-
return client.WorkspaceByOwnerAndName(cmd.Context(), owner, name)
217+
return client.WorkspaceByOwnerAndName(cmd.Context(), owner, name, codersdk.WorkspaceByOwnerAndNameParams{})
218218
}
219219

220220
// createConfig consumes the global configuration flag to produce a config root.

cli/templateedit.go

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/spf13/cobra"
8+
"golang.org/x/xerrors"
9+
10+
"github.com/coder/coder/cli/cliui"
11+
"github.com/coder/coder/codersdk"
12+
)
13+
14+
func templateEdit() *cobra.Command {
15+
var (
16+
description string
17+
maxTTL time.Duration
18+
minAutostartInterval time.Duration
19+
)
20+
21+
cmd := &cobra.Command{
22+
Use: "edit <template> [flags]",
23+
Args: cobra.ExactArgs(1),
24+
Short: "Edit the metadata of a template by name.",
25+
RunE: func(cmd *cobra.Command, args []string) error {
26+
client, err := createClient(cmd)
27+
if err != nil {
28+
return xerrors.Errorf("create client: %w", err)
29+
}
30+
organization, err := currentOrganization(cmd, client)
31+
if err != nil {
32+
return xerrors.Errorf("get current organization: %w", err)
33+
}
34+
template, err := client.TemplateByName(cmd.Context(), organization.ID, args[0])
35+
if err != nil {
36+
return xerrors.Errorf("get workspace template: %w", err)
37+
}
38+
39+
// NOTE: coderd will ignore empty fields.
40+
req := codersdk.UpdateTemplateMeta{
41+
Description: description,
42+
MaxTTLMillis: maxTTL.Milliseconds(),
43+
MinAutostartIntervalMillis: minAutostartInterval.Milliseconds(),
44+
}
45+
46+
_, err = client.UpdateTemplateMeta(cmd.Context(), template.ID, req)
47+
if err != nil {
48+
return xerrors.Errorf("update template metadata: %w", err)
49+
}
50+
_, _ = fmt.Printf("Updated template metadata!\n")
51+
return nil
52+
},
53+
}
54+
55+
cmd.Flags().StringVarP(&description, "description", "", "", "Edit the template description")
56+
cmd.Flags().DurationVarP(&maxTTL, "max_ttl", "", 0, "Edit the template maximum time before shutdown")
57+
cmd.Flags().DurationVarP(&minAutostartInterval, "min_autostart_interval", "", 0, "Edit the template minimum autostart interval")
58+
cliui.AllowSkipPrompt(cmd)
59+
60+
return cmd
61+
}

cli/templateedit_test.go

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package cli_test
2+
3+
import (
4+
"context"
5+
"testing"
6+
"time"
7+
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
11+
"github.com/coder/coder/cli/clitest"
12+
"github.com/coder/coder/coderd/coderdtest"
13+
"github.com/coder/coder/coderd/util/ptr"
14+
"github.com/coder/coder/codersdk"
15+
)
16+
17+
func TestTemplateEdit(t *testing.T) {
18+
t.Parallel()
19+
20+
t.Run("Modified", func(t *testing.T) {
21+
t.Parallel()
22+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
23+
user := coderdtest.CreateFirstUser(t, client)
24+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
25+
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
26+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
27+
ctr.Description = "original description"
28+
ctr.MaxTTLMillis = ptr.Ref(24 * time.Hour.Milliseconds())
29+
ctr.MinAutostartIntervalMillis = ptr.Ref(time.Hour.Milliseconds())
30+
})
31+
32+
// Test the cli command.
33+
desc := "lorem ipsum dolor sit amet et cetera"
34+
maxTTL := 12 * time.Hour
35+
minAutostartInterval := time.Minute
36+
cmdArgs := []string{
37+
"templates",
38+
"edit",
39+
template.Name,
40+
"--description", desc,
41+
"--max_ttl", maxTTL.String(),
42+
"--min_autostart_interval", minAutostartInterval.String(),
43+
}
44+
cmd, root := clitest.New(t, cmdArgs...)
45+
clitest.SetupConfig(t, client, root)
46+
47+
err := cmd.Execute()
48+
49+
require.NoError(t, err)
50+
51+
// Assert that the template metadata changed.
52+
updated, err := client.Template(context.Background(), template.ID)
53+
require.NoError(t, err)
54+
assert.Equal(t, desc, updated.Description)
55+
assert.Equal(t, maxTTL.Milliseconds(), updated.MaxTTLMillis)
56+
assert.Equal(t, minAutostartInterval.Milliseconds(), updated.MinAutostartIntervalMillis)
57+
})
58+
59+
t.Run("NotModified", func(t *testing.T) {
60+
t.Parallel()
61+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
62+
user := coderdtest.CreateFirstUser(t, client)
63+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
64+
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
65+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
66+
ctr.Description = "original description"
67+
ctr.MaxTTLMillis = ptr.Ref(24 * time.Hour.Milliseconds())
68+
ctr.MinAutostartIntervalMillis = ptr.Ref(time.Hour.Milliseconds())
69+
})
70+
71+
// Test the cli command.
72+
cmdArgs := []string{
73+
"templates",
74+
"edit",
75+
template.Name,
76+
"--description", template.Description,
77+
"--max_ttl", (time.Duration(template.MaxTTLMillis) * time.Millisecond).String(),
78+
"--min_autostart_interval", (time.Duration(template.MinAutostartIntervalMillis) * time.Millisecond).String(),
79+
}
80+
cmd, root := clitest.New(t, cmdArgs...)
81+
clitest.SetupConfig(t, client, root)
82+
83+
err := cmd.Execute()
84+
85+
require.ErrorContains(t, err, "not modified")
86+
87+
// Assert that the template metadata did not change.
88+
updated, err := client.Template(context.Background(), template.ID)
89+
require.NoError(t, err)
90+
assert.Equal(t, template.Description, updated.Description)
91+
assert.Equal(t, template.MaxTTLMillis, updated.MaxTTLMillis)
92+
assert.Equal(t, template.MinAutostartIntervalMillis, updated.MinAutostartIntervalMillis)
93+
})
94+
}

0 commit comments

Comments
 (0)