Skip to content

Commit 60ad881

Browse files
committed
Merge branch 'refactorsite' into apps
2 parents 80b5600 + 8b81c35 commit 60ad881

File tree

150 files changed

+4594
-1459
lines changed

Some content is hidden

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

150 files changed

+4594
-1459
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: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ 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
1116
Coder creates remote development machines so you can develop your code from anywhere. #coder
1217

1318
> **Note**:
@@ -56,47 +61,25 @@ You can use any Web IDE ([code-server](https://github.com/coder/code-server), [p
5661

5762
## Installing Coder
5863

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:
62-
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`
65-
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):
64+
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).
7665

77-
```bash
78-
coder server --dev
79-
```
66+
If you use the install script, you can preview what occurs during the install process:
8067

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-
```
68+
```sh
69+
curl -fsSL https://coder.com/install.sh | sh -s -- --dry-run
70+
```
8771

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

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

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

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

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

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/cliui/provisionerjob.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cliui
22

33
import (
4+
"bytes"
45
"context"
56
"fmt"
67
"io"
@@ -35,6 +36,9 @@ type ProvisionerJobOptions struct {
3536
FetchInterval time.Duration
3637
// Verbose determines whether debug and trace logs will be shown.
3738
Verbose bool
39+
// Silent determines whether log output will be shown unless there is an
40+
// error.
41+
Silent bool
3842
}
3943

4044
// ProvisionerJob renders a provisioner job with interactive cancellation.
@@ -133,12 +137,30 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp
133137
return xerrors.Errorf("logs: %w", err)
134138
}
135139

140+
var (
141+
// logOutput is where log output is written
142+
logOutput = writer
143+
// logBuffer is where logs are buffered if opts.Silent is true
144+
logBuffer = &bytes.Buffer{}
145+
)
146+
if opts.Silent {
147+
logOutput = logBuffer
148+
}
149+
flushLogBuffer := func() {
150+
if opts.Silent {
151+
_, _ = io.Copy(writer, logBuffer)
152+
}
153+
}
154+
136155
ticker := time.NewTicker(opts.FetchInterval)
156+
defer ticker.Stop()
137157
for {
138158
select {
139159
case err = <-errChan:
160+
flushLogBuffer()
140161
return err
141162
case <-ctx.Done():
163+
flushLogBuffer()
142164
return ctx.Err()
143165
case <-ticker.C:
144166
updateJob()
@@ -160,8 +182,10 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp
160182
}
161183
err = xerrors.New(job.Error)
162184
jobMutex.Unlock()
185+
flushLogBuffer()
163186
return err
164187
}
188+
165189
output := ""
166190
switch log.Level {
167191
case codersdk.LogLevelTrace, codersdk.LogLevelDebug:
@@ -176,14 +200,17 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp
176200
case codersdk.LogLevelInfo:
177201
output = log.Output
178202
}
203+
179204
jobMutex.Lock()
180205
if log.Stage != currentStage && log.Stage != "" {
181206
updateStage(log.Stage, log.CreatedAt)
182207
jobMutex.Unlock()
183208
continue
184209
}
185-
_, _ = fmt.Fprintf(writer, "%s %s\n", Styles.Placeholder.Render(" "), output)
186-
didLogBetweenStage = true
210+
_, _ = fmt.Fprintf(logOutput, "%s %s\n", Styles.Placeholder.Render(" "), output)
211+
if !opts.Silent {
212+
didLogBetweenStage = true
213+
}
187214
jobMutex.Unlock()
188215
}
189216
}

cli/create.go

Lines changed: 35 additions & 5 deletions
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

@@ -170,10 +171,40 @@ func create() *cobra.Command {
170171
}
171172
_, _ = fmt.Fprintln(cmd.OutOrStdout())
172173

173-
resources, err := client.TemplateVersionResources(cmd.Context(), templateVersion.ID)
174+
// Run a dry-run with the given parameters to check correctness
175+
after := time.Now()
176+
dryRun, err := client.CreateTemplateVersionDryRun(cmd.Context(), templateVersion.ID, codersdk.CreateTemplateVersionDryRunRequest{
177+
WorkspaceName: workspaceName,
178+
ParameterValues: parameters,
179+
})
174180
if err != nil {
175-
return err
181+
return xerrors.Errorf("begin workspace dry-run: %w", err)
182+
}
183+
_, _ = fmt.Fprintln(cmd.OutOrStdout(), "Planning workspace...")
184+
err = cliui.ProvisionerJob(cmd.Context(), cmd.OutOrStdout(), cliui.ProvisionerJobOptions{
185+
Fetch: func() (codersdk.ProvisionerJob, error) {
186+
return client.TemplateVersionDryRun(cmd.Context(), templateVersion.ID, dryRun.ID)
187+
},
188+
Cancel: func() error {
189+
return client.CancelTemplateVersionDryRun(cmd.Context(), templateVersion.ID, dryRun.ID)
190+
},
191+
Logs: func() (<-chan codersdk.ProvisionerJobLog, error) {
192+
return client.TemplateVersionDryRunLogsAfter(cmd.Context(), templateVersion.ID, dryRun.ID, after)
193+
},
194+
// Don't show log output for the dry-run unless there's an error.
195+
Silent: true,
196+
})
197+
if err != nil {
198+
// TODO (Dean): reprompt for parameter values if we deem it to
199+
// be a validation error
200+
return xerrors.Errorf("dry-run workspace: %w", err)
176201
}
202+
203+
resources, err := client.TemplateVersionDryRunResources(cmd.Context(), templateVersion.ID, dryRun.ID)
204+
if err != nil {
205+
return xerrors.Errorf("get workspace dry-run resources: %w", err)
206+
}
207+
177208
err = cliui.WorkspaceResources(cmd.OutOrStdout(), resources, cliui.WorkspaceResourcesOptions{
178209
WorkspaceName: workspaceName,
179210
// Since agent's haven't connected yet, hiding this makes more sense.
@@ -192,19 +223,18 @@ func create() *cobra.Command {
192223
return err
193224
}
194225

195-
before := time.Now()
196226
workspace, err := client.CreateWorkspace(cmd.Context(), organization.ID, codersdk.CreateWorkspaceRequest{
197227
TemplateID: template.ID,
198228
Name: workspaceName,
199229
AutostartSchedule: &schedSpec,
200-
TTL: &ttl,
230+
TTLMillis: ptr.Ref(ttl.Milliseconds()),
201231
ParameterValues: parameters,
202232
})
203233
if err != nil {
204234
return err
205235
}
206236

207-
err = cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, workspace.LatestBuild.ID, before)
237+
err = cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, workspace.LatestBuild.ID, after)
208238
if err != nil {
209239
return err
210240
}

0 commit comments

Comments
 (0)