Skip to content

Commit 1c6f546

Browse files
committed
Merge remote-tracking branch 'origin/main' into stevenmasley/pagination_after_id
2 parents be23937 + dcf03d8 commit 1c6f546

File tree

65 files changed

+1357
-374
lines changed

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

+1357
-374
lines changed

.github/workflows/coder.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ jobs:
5252
- uses: actions/checkout@v3
5353
- name: Run ShellCheck
5454
uses: ludeeus/action-shellcheck@1.1.0
55+
env:
56+
SHELLCHECK_OPTS: --external-sources
5557
with:
5658
ignore: node_modules
5759

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ lint/go:
7171
# Use shfmt to determine the shell files, takes editorconfig into consideration.
7272
lint/shellcheck: $(shell shfmt -f .)
7373
@echo "--- shellcheck"
74-
shellcheck $(shell shfmt -f .)
74+
shellcheck --external-sources $(shell shfmt -f .)
7575

7676
peerbroker/proto/peerbroker.pb.go: peerbroker/proto/peerbroker.proto
7777
protoc \

README.md

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -56,47 +56,25 @@ You can use any Web IDE ([code-server](https://github.com/coder/code-server), [p
5656

5757
## Installing Coder
5858

59-
We recommend installing [the latest
60-
release](https://github.com/coder/coder/releases) on a system with at least 1
61-
CPU core and 2 GB RAM:
59+
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).
6260

63-
1. Download the [release asset](https://github.com/coder/coder/releases) appropriate for your operating system
64-
1. Unzip the folder you just downloaded, and move the `coder` executable to a location that's on your `PATH`
61+
If you use the install script, you can preview what occurs during the install process:
6562

66-
```sh
67-
# ex. MacOS and Linux
68-
mv coder /usr/local/bin
69-
```
70-
71-
Windows: see [this guide](https://answers.microsoft.com/en-us/windows/forum/all/adding-path-variable/97300613-20cb-4d85-8d0e-cc9d3549ba23) on adding a folder to `PATH`
72-
73-
There are a few ways to run Coder:
74-
75-
- To run a **temporary deployment**, start with dev mode (all data is in-memory and destroyed on exit):
76-
77-
```bash
78-
coder server --dev
79-
```
80-
81-
- To run a **production deployment** with PostgreSQL:
82-
83-
```bash
84-
CODER_PG_CONNECTION_URL="postgres://<username>@<host>/<database>?password=<password>" \
85-
coder server
86-
```
63+
```sh
64+
curl -fsSL https://coder.com/install.sh | sh -s -- --dry-run
65+
```
8766

88-
- To run as a **system service**, install with `.deb` (Debian, Ubuntu) or `.rpm` (Fedora, CentOS, RHEL, SUSE):
67+
To install, run:
8968

90-
```bash
91-
# Edit the configuration!
92-
sudo vim /etc/coder.d/coder.env
93-
sudo service coder restart
94-
```
69+
```sh
70+
curl -fsSL https://coder.com/install.sh | sh
71+
```
9572

96-
> macOS and Windows users: You'll need to write your own
97-
> configuration to run Coder as a system service.
73+
Once installed, you can run a temporary deployment in dev mode (all data is in-memory and destroyed on exit):
9874

99-
- See the [installation guide](./docs/install.md) for additional ways to run Coder (e.g., docker-compose)
75+
```sh
76+
coder server --dev
77+
```
10078

10179
Use `coder --help` to get a complete list of flags and environment variables.
10280

cli/autostart.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ func autostartShow() *cobra.Command {
5151
return err
5252
}
5353

54-
if workspace.AutostartSchedule == "" {
54+
if workspace.AutostartSchedule == nil || *workspace.AutostartSchedule == "" {
5555
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "not enabled\n")
5656
return nil
5757
}
5858

59-
validSchedule, err := schedule.Weekly(workspace.AutostartSchedule)
59+
validSchedule, err := schedule.Weekly(*workspace.AutostartSchedule)
6060
if err != nil {
6161
// This should never happen.
62-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "invalid autostart schedule %q for workspace %s: %s\n", workspace.AutostartSchedule, workspace.Name, err.Error())
62+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "invalid autostart schedule %q for workspace %s: %s\n", *workspace.AutostartSchedule, workspace.Name, err.Error())
6363
return nil
6464
}
6565

@@ -110,7 +110,7 @@ func autostartEnable() *cobra.Command {
110110
}
111111

112112
err = client.UpdateWorkspaceAutostart(cmd.Context(), workspace.ID, codersdk.UpdateWorkspaceAutostartRequest{
113-
Schedule: validSchedule.String(),
113+
Schedule: &spec,
114114
})
115115
if err != nil {
116116
return err
@@ -153,7 +153,7 @@ func autostartDisable() *cobra.Command {
153153
}
154154

155155
err = client.UpdateWorkspaceAutostart(cmd.Context(), workspace.ID, codersdk.UpdateWorkspaceAutostartRequest{
156-
Schedule: "",
156+
Schedule: nil,
157157
})
158158
if err != nil {
159159
return err

cli/autostart_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/coder/coder/cli/clitest"
1313
"github.com/coder/coder/coderd/coderdtest"
14+
"github.com/coder/coder/coderd/util/ptr"
1415
"github.com/coder/coder/codersdk"
1516
)
1617

@@ -34,7 +35,7 @@ func TestAutostart(t *testing.T) {
3435
)
3536

3637
err := client.UpdateWorkspaceAutostart(ctx, workspace.ID, codersdk.UpdateWorkspaceAutostartRequest{
37-
Schedule: sched,
38+
Schedule: ptr.Ref(sched),
3839
})
3940
require.NoError(t, err)
4041

@@ -76,7 +77,7 @@ func TestAutostart(t *testing.T) {
7677
// Ensure autostart schedule updated
7778
updated, err := client.Workspace(ctx, workspace.ID)
7879
require.NoError(t, err, "fetch updated workspace")
79-
require.Equal(t, sched, updated.AutostartSchedule, "expected autostart schedule to be set")
80+
require.Equal(t, sched, *updated.AutostartSchedule, "expected autostart schedule to be set")
8081

8182
// Disable schedule
8283
cmd, root = clitest.New(t, "autostart", "disable", workspace.Name)
@@ -90,7 +91,7 @@ func TestAutostart(t *testing.T) {
9091
// Ensure autostart schedule updated
9192
updated, err = client.Workspace(ctx, workspace.ID)
9293
require.NoError(t, err, "fetch updated workspace")
93-
require.Empty(t, updated.AutostartSchedule, "expected autostart schedule to not be set")
94+
require.Nil(t, updated.AutostartSchedule, "expected autostart schedule to not be set")
9495
})
9596

9697
t.Run("Enable_NotFound", func(t *testing.T) {
@@ -155,6 +156,6 @@ func TestAutostart(t *testing.T) {
155156
// Ensure nothing happened
156157
updated, err := client.Workspace(ctx, workspace.ID)
157158
require.NoError(t, err, "fetch updated workspace")
158-
require.Equal(t, expectedSchedule, updated.AutostartSchedule, "expected default autostart schedule")
159+
require.Equal(t, expectedSchedule, *updated.AutostartSchedule, "expected default autostart schedule")
159160
})
160161
}

cli/bump_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func TestBump(t *testing.T) {
4040
expectedDeadline := workspace.LatestBuild.Deadline.Add(90 * time.Minute)
4141

4242
// Assert test invariant: workspace build has a deadline set equal to now plus ttl
43-
require.WithinDuration(t, workspace.LatestBuild.Deadline, time.Now().Add(*workspace.TTL), time.Minute)
44-
require.NoError(t, err)
43+
initDeadline := time.Now().Add(time.Duration(*workspace.TTLMillis) * time.Millisecond)
44+
require.WithinDuration(t, initDeadline, workspace.LatestBuild.Deadline, time.Minute)
4545

4646
cmd, root := clitest.New(t, cmdArgs...)
4747
clitest.SetupConfig(t, client, root)
@@ -81,8 +81,8 @@ func TestBump(t *testing.T) {
8181
expectedDeadline := workspace.LatestBuild.Deadline.Add(30 * time.Minute)
8282

8383
// Assert test invariant: workspace build has a deadline set equal to now plus ttl
84-
require.WithinDuration(t, workspace.LatestBuild.Deadline, time.Now().Add(*workspace.TTL), time.Minute)
85-
require.NoError(t, err)
84+
initDeadline := time.Now().Add(time.Duration(*workspace.TTLMillis) * time.Millisecond)
85+
require.WithinDuration(t, initDeadline, workspace.LatestBuild.Deadline, time.Minute)
8686

8787
cmd, root := clitest.New(t, cmdArgs...)
8888
clitest.SetupConfig(t, client, root)
@@ -121,8 +121,8 @@ func TestBump(t *testing.T) {
121121
require.NoError(t, err)
122122

123123
// Assert test invariant: workspace build has a deadline set equal to now plus ttl
124-
require.WithinDuration(t, workspace.LatestBuild.Deadline, time.Now().Add(*workspace.TTL), time.Minute)
125-
require.NoError(t, err)
124+
initDeadline := time.Now().Add(time.Duration(*workspace.TTLMillis) * time.Millisecond)
125+
require.WithinDuration(t, initDeadline, workspace.LatestBuild.Deadline, time.Minute)
126126

127127
cmd, root := clitest.New(t, cmdArgs...)
128128
clitest.SetupConfig(t, client, root)
@@ -147,7 +147,7 @@ func TestBump(t *testing.T) {
147147
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
148148
project = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
149149
workspace = coderdtest.CreateWorkspace(t, client, user.OrganizationID, project.ID, func(cwr *codersdk.CreateWorkspaceRequest) {
150-
cwr.TTL = nil
150+
cwr.TTLMillis = nil
151151
})
152152
cmdArgs = []string{"bump", workspace.Name}
153153
stdoutBuf = &bytes.Buffer{}
@@ -199,8 +199,8 @@ func TestBump(t *testing.T) {
199199
require.NoError(t, err)
200200

201201
// Assert test invariant: workspace build has a deadline set equal to now plus ttl
202-
require.WithinDuration(t, workspace.LatestBuild.Deadline, time.Now().Add(*workspace.TTL), time.Minute)
203-
require.NoError(t, err)
202+
initDeadline := time.Now().Add(time.Duration(*workspace.TTLMillis) * time.Millisecond)
203+
require.WithinDuration(t, initDeadline, workspace.LatestBuild.Deadline, time.Minute)
204204

205205
cmd, root := clitest.New(t, cmdArgs...)
206206
clitest.SetupConfig(t, client, root)

cli/create.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/coder/coder/cli/cliflag"
1212
"github.com/coder/coder/cli/cliui"
1313
"github.com/coder/coder/coderd/autobuild/schedule"
14+
"github.com/coder/coder/coderd/util/ptr"
1415
"github.com/coder/coder/codersdk"
1516
)
1617

@@ -226,7 +227,7 @@ func create() *cobra.Command {
226227
TemplateID: template.ID,
227228
Name: workspaceName,
228229
AutostartSchedule: &schedSpec,
229-
TTL: &ttl,
230+
TTLMillis: ptr.Ref(ttl.Milliseconds()),
230231
ParameterValues: parameters,
231232
})
232233
if err != nil {

cli/list.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/coder/coder/cli/cliui"
1313
"github.com/coder/coder/coderd/autobuild/schedule"
14+
"github.com/coder/coder/coderd/util/ptr"
1415
"github.com/coder/coder/codersdk"
1516
)
1617

@@ -87,15 +88,16 @@ func list() *cobra.Command {
8788

8889
duration := time.Now().UTC().Sub(workspace.LatestBuild.Job.CreatedAt).Truncate(time.Second)
8990
autostartDisplay := "-"
90-
if workspace.AutostartSchedule != "" {
91-
if sched, err := schedule.Weekly(workspace.AutostartSchedule); err == nil {
91+
if !ptr.NilOrEmpty(workspace.AutostartSchedule) {
92+
if sched, err := schedule.Weekly(*workspace.AutostartSchedule); err == nil {
9293
autostartDisplay = sched.Cron()
9394
}
9495
}
9596

9697
autostopDisplay := "-"
97-
if workspace.TTL != nil {
98-
autostopDisplay = durationDisplay(*workspace.TTL)
98+
if !ptr.NilOrZero(workspace.TTLMillis) {
99+
dur := time.Duration(*workspace.TTLMillis) * time.Millisecond
100+
autostopDisplay = durationDisplay(dur)
99101
if has, ext := hasExtension(workspace); has {
100102
autostopDisplay += fmt.Sprintf(" (+%s)", durationDisplay(ext.Round(time.Minute)))
101103
}
@@ -128,10 +130,11 @@ func hasExtension(ws codersdk.Workspace) (bool, time.Duration) {
128130
if ws.LatestBuild.Deadline.IsZero() {
129131
return false, 0
130132
}
131-
if ws.TTL == nil {
133+
if ws.TTLMillis == nil {
132134
return false, 0
133135
}
134-
delta := ws.LatestBuild.Deadline.Add(-*ws.TTL).Sub(ws.LatestBuild.CreatedAt)
136+
ttl := time.Duration(*ws.TTLMillis) * time.Millisecond
137+
delta := ws.LatestBuild.Deadline.Add(-ttl).Sub(ws.LatestBuild.CreatedAt)
135138
if delta < time.Minute {
136139
return false, 0
137140
}

cli/ssh.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/coder/coder/cli/cliflag"
2323
"github.com/coder/coder/cli/cliui"
2424
"github.com/coder/coder/coderd/autobuild/notify"
25+
"github.com/coder/coder/coderd/util/ptr"
2526
"github.com/coder/coder/codersdk"
2627
"github.com/coder/coder/cryptorand"
2728
)
@@ -34,6 +35,7 @@ func ssh() *cobra.Command {
3435
stdio bool
3536
shuffle bool
3637
forwardAgent bool
38+
identityAgent string
3739
wsPollInterval time.Duration
3840
)
3941
cmd := &cobra.Command{
@@ -110,8 +112,11 @@ func ssh() *cobra.Command {
110112
return err
111113
}
112114

113-
if forwardAgent && os.Getenv("SSH_AUTH_SOCK") != "" {
114-
err = gosshagent.ForwardToRemote(sshClient, os.Getenv("SSH_AUTH_SOCK"))
115+
if identityAgent == "" {
116+
identityAgent = os.Getenv("SSH_AUTH_SOCK")
117+
}
118+
if forwardAgent && identityAgent != "" {
119+
err = gosshagent.ForwardToRemote(sshClient, identityAgent)
115120
if err != nil {
116121
return xerrors.Errorf("forward agent failed: %w", err)
117122
}
@@ -171,6 +176,7 @@ func ssh() *cobra.Command {
171176
cliflag.BoolVarP(cmd.Flags(), &shuffle, "shuffle", "", "CODER_SSH_SHUFFLE", false, "Specifies whether to choose a random workspace")
172177
_ = cmd.Flags().MarkHidden("shuffle")
173178
cliflag.BoolVarP(cmd.Flags(), &forwardAgent, "forward-agent", "A", "CODER_SSH_FORWARD_AGENT", false, "Specifies whether to forward the SSH agent specified in $SSH_AUTH_SOCK")
179+
cliflag.StringVarP(cmd.Flags(), &identityAgent, "identity-agent", "", "CODER_SSH_IDENTITY_AGENT", "", "Specifies which identity agent to use (overrides $SSH_AUTH_SOCK), forward agent must also be enabled")
174180
cliflag.DurationVarP(cmd.Flags(), &wsPollInterval, "workspace-poll-interval", "", "CODER_WORKSPACE_POLL_INTERVAL", workspacePollInterval, "Specifies how often to poll for workspace automated shutdown.")
175181

176182
return cmd
@@ -285,7 +291,7 @@ func notifyCondition(ctx context.Context, client *codersdk.Client, workspaceID u
285291
return time.Time{}, nil
286292
}
287293

288-
if ws.TTL == nil || *ws.TTL == 0 {
294+
if ptr.NilOrZero(ws.TTLMillis) {
289295
return time.Time{}, nil
290296
}
291297

cli/ssh_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@ func TestSSH(t *testing.T) {
146146

147147
<-cmdDone
148148
})
149-
//nolint:paralleltest // Disabled due to use of t.Setenv.
150149
t.Run("ForwardAgent", func(t *testing.T) {
151150
if runtime.GOOS == "windows" {
152151
t.Skip("Test not supported on windows")
153152
}
154153

154+
t.Parallel()
155+
155156
client, workspace, agentToken := setupWorkspaceForSSH(t)
156157

157158
_, _ = tGoContext(t, func(ctx context.Context) {
@@ -198,11 +199,11 @@ func TestSSH(t *testing.T) {
198199
}
199200
})
200201

201-
t.Setenv("SSH_AUTH_SOCK", agentSock)
202202
cmd, root := clitest.New(t,
203203
"ssh",
204204
workspace.Name,
205205
"--forward-agent",
206+
"--identity-agent", agentSock, // Overrides $SSH_AUTH_SOCK.
206207
)
207208
clitest.SetupConfig(t, client, root)
208209
pty := ptytest.New(t)

cli/ttl.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ func ttlShow() *cobra.Command {
4949
return xerrors.Errorf("get workspace: %w", err)
5050
}
5151

52-
if workspace.TTL == nil {
52+
if workspace.TTLMillis == nil || *workspace.TTLMillis == 0 {
5353
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "not set\n")
5454
return nil
5555
}
5656

57-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%s\n", workspace.TTL)
57+
dur := time.Duration(*workspace.TTLMillis) * time.Millisecond
58+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%s\n", dur)
5859

5960
return nil
6061
},
@@ -96,10 +97,10 @@ func ttlset() *cobra.Command {
9697
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "warning: ttl rounded down to %s\n", truncated)
9798
}
9899

99-
err = client.UpdateWorkspaceTTL(cmd.Context(), workspace.ID, codersdk.UpdateWorkspaceTTLRequest{
100-
TTL: &truncated,
101-
})
102-
if err != nil {
100+
millis := truncated.Milliseconds()
101+
if err = client.UpdateWorkspaceTTL(cmd.Context(), workspace.ID, codersdk.UpdateWorkspaceTTLRequest{
102+
TTLMillis: &millis,
103+
}); err != nil {
103104
return xerrors.Errorf("update workspace ttl: %w", err)
104105
}
105106

@@ -130,7 +131,7 @@ func ttlunset() *cobra.Command {
130131
}
131132

132133
err = client.UpdateWorkspaceTTL(cmd.Context(), workspace.ID, codersdk.UpdateWorkspaceTTLRequest{
133-
TTL: nil,
134+
TTLMillis: nil,
134135
})
135136
if err != nil {
136137
return xerrors.Errorf("update workspace ttl: %w", err)

0 commit comments

Comments
 (0)