Skip to content

Commit bc39570

Browse files
committed
Merge branch 'main' into dean/schedule-max-ttl
2 parents 96fd840 + 0bf6229 commit bc39570

File tree

183 files changed

+4647
-3988
lines changed

Some content is hidden

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

183 files changed

+4647
-3988
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ jobs:
506506
507507
- uses: actions/setup-node@v3
508508
with:
509-
node-version: "14"
509+
node-version: "16.16.0"
510510

511511
- name: Install node_modules
512512
run: ./scripts/yarn_install.sh
@@ -555,7 +555,7 @@ jobs:
555555

556556
- uses: actions/setup-node@v3
557557
with:
558-
node-version: "14"
558+
node-version: "16.16.0"
559559

560560
- name: Echo Go Cache Paths
561561
id: go-cache-paths
@@ -609,6 +609,10 @@ jobs:
609609
# only get 1 commit on shallow checkout.
610610
fetch-depth: 0
611611

612+
- uses: actions/setup-node@v3
613+
with:
614+
node-version: "16.16.0"
615+
612616
- name: Install dependencies
613617
run: cd site && yarn
614618

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"stretchr",
114114
"STTY",
115115
"stuntest",
116+
"tanstack",
116117
"tailbroker",
117118
"tailcfg",
118119
"tailexchange",

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,10 @@ docs/admin/prometheus.md: scripts/metricsdocgen/main.go scripts/metricsdocgen/me
501501
yarn run format:write:only ../docs/admin/prometheus.md
502502

503503
docs/cli/coder.md: scripts/clidocgen/main.go $(GO_SRC_FILES) docs/manifest.json
504-
BASE_PATH="." go run scripts/clidocgen/main.go
504+
rm -rf ./docs/cli/*.md
505+
BASE_PATH="." go run ./scripts/clidocgen
505506
cd site
506-
yarn run format:write:only ../docs/cli/*.md ../docs/manifest.json
507+
yarn run format:write:only ../docs/cli.md ../docs/cli/*.md ../docs/manifest.json
507508

508509
docs/admin/audit-logs.md: scripts/auditdocgen/main.go enterprise/audit/table.go
509510
go run scripts/auditdocgen/main.go

cli/speedtest.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import (
1919

2020
func speedtest() *cobra.Command {
2121
var (
22-
direct bool
23-
duration time.Duration
24-
reverse bool
22+
direct bool
23+
duration time.Duration
24+
direction string
2525
)
2626
cmd := &cobra.Command{
2727
Annotations: workspaceCommand,
@@ -48,7 +48,7 @@ func speedtest() *cobra.Command {
4848
return client.WorkspaceAgent(ctx, workspaceAgent.ID)
4949
},
5050
})
51-
if err != nil {
51+
if err != nil && !xerrors.Is(err, cliui.AgentStartError) {
5252
return xerrors.Errorf("await agent: %w", err)
5353
}
5454
logger := slog.Make(sloghuman.Sink(cmd.ErrOrStderr()))
@@ -94,25 +94,29 @@ func speedtest() *cobra.Command {
9494
} else {
9595
conn.AwaitReachable(ctx)
9696
}
97-
dir := tsspeedtest.Download
98-
if reverse {
99-
dir = tsspeedtest.Upload
97+
var tsDir tsspeedtest.Direction
98+
switch direction {
99+
case "up":
100+
tsDir = tsspeedtest.Upload
101+
case "down":
102+
tsDir = tsspeedtest.Download
103+
default:
104+
return xerrors.Errorf("invalid direction: %q", direction)
100105
}
101-
cmd.Printf("Starting a %ds %s test...\n", int(duration.Seconds()), dir)
102-
results, err := conn.Speedtest(ctx, dir, duration)
106+
cmd.Printf("Starting a %ds %s test...\n", int(duration.Seconds()), tsDir)
107+
results, err := conn.Speedtest(ctx, tsDir, duration)
103108
if err != nil {
104109
return err
105110
}
106111
tableWriter := cliui.Table()
107-
tableWriter.AppendHeader(table.Row{"Interval", "Transfer", "Bandwidth"})
112+
tableWriter.AppendHeader(table.Row{"Interval", "Throughput"})
108113
startTime := results[0].IntervalStart
109114
for _, r := range results {
110115
if r.Total {
111116
tableWriter.AppendSeparator()
112117
}
113118
tableWriter.AppendRow(table.Row{
114119
fmt.Sprintf("%.2f-%.2f sec", r.IntervalStart.Sub(startTime).Seconds(), r.IntervalEnd.Sub(startTime).Seconds()),
115-
fmt.Sprintf("%.4f MBits", r.MegaBits()),
116120
fmt.Sprintf("%.4f Mbits/sec", r.MBitsPerSecond()),
117121
})
118122
}
@@ -122,8 +126,9 @@ func speedtest() *cobra.Command {
122126
}
123127
cliflag.BoolVarP(cmd.Flags(), &direct, "direct", "d", "", false,
124128
"Specifies whether to wait for a direct connection before testing speed.")
125-
cliflag.BoolVarP(cmd.Flags(), &reverse, "reverse", "r", "", false,
126-
"Specifies whether to run in reverse mode where the client receives and the server sends.")
129+
cliflag.StringVarP(cmd.Flags(), &direction, "direction", "", "", "down",
130+
"Specifies whether to run in reverse mode where the client receives and the server sends. (up|down)",
131+
)
127132
cmd.Flags().DurationVarP(&duration, "time", "t", tsspeedtest.DefaultDuration,
128133
"Specifies the duration to monitor traffic.")
129134
return cmd

cli/speedtest_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
func TestSpeedtest(t *testing.T) {
2121
t.Parallel()
22+
t.Skip("Flaky test - see https://github.com/coder/coder/issues/6321")
2223
if testing.Short() {
2324
t.Skip("This test takes a minimum of 5ms per a hardcoded value in Tailscale!")
2425
}

cli/state.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ func state() *cobra.Command {
2727
func statePull() *cobra.Command {
2828
var buildNumber int
2929
cmd := &cobra.Command{
30-
Use: "pull <workspace> [file]",
31-
Args: cobra.MinimumNArgs(1),
30+
Use: "pull <workspace> [file]",
31+
Short: "Pull a Terraform state file from a workspace.",
32+
Args: cobra.MinimumNArgs(1),
3233
RunE: func(cmd *cobra.Command, args []string) error {
3334
client, err := CreateClient(cmd)
3435
if err != nil {
@@ -68,8 +69,9 @@ func statePull() *cobra.Command {
6869
func statePush() *cobra.Command {
6970
var buildNumber int
7071
cmd := &cobra.Command{
71-
Use: "push <workspace> <file>",
72-
Args: cobra.ExactArgs(2),
72+
Use: "push <workspace> <file>",
73+
Args: cobra.ExactArgs(2),
74+
Short: "Push a Terraform state file to a workspace.",
7375
RunE: func(cmd *cobra.Command, args []string) error {
7476
client, err := CreateClient(cmd)
7577
if err != nil {

cli/templatepull.go

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package cli
22

33
import (
4+
"bytes"
45
"fmt"
5-
"io/fs"
66
"os"
77
"sort"
88

9+
"github.com/codeclysm/extract"
910
"github.com/spf13/cobra"
1011
"golang.org/x/xerrors"
1112

@@ -14,6 +15,7 @@ import (
1415
)
1516

1617
func templatePull() *cobra.Command {
18+
var tarMode bool
1719
cmd := &cobra.Command{
1820
Use: "pull <name> [destination]",
1921
Short: "Download the latest version of a template to a path.",
@@ -75,48 +77,44 @@ func templatePull() *cobra.Command {
7577
return xerrors.Errorf("unexpected Content-Type %q, expecting %q", ctype, codersdk.ContentTypeTar)
7678
}
7779

78-
// If the destination is empty then we write to stdout
79-
// and bail early.
80-
if dest == "" {
80+
if tarMode {
8181
_, err = cmd.OutOrStdout().Write(raw)
82-
if err != nil {
83-
return xerrors.Errorf("write stdout: %w", err)
84-
}
85-
return nil
82+
return err
8683
}
8784

88-
// Stat the destination to ensure nothing exists already.
89-
fi, err := os.Stat(dest)
90-
if err != nil && !xerrors.Is(err, fs.ErrNotExist) {
91-
return xerrors.Errorf("stat destination: %w", err)
85+
if dest == "" {
86+
dest = templateName + "/"
9287
}
9388

94-
if fi != nil && fi.IsDir() {
95-
// If the destination is a directory we just bail.
96-
return xerrors.Errorf("%q already exists.", dest)
89+
err = os.MkdirAll(dest, 0o750)
90+
if err != nil {
91+
return xerrors.Errorf("mkdirall %q: %w", dest, err)
9792
}
9893

99-
// If a file exists at the destination prompt the user
100-
// to ensure we don't overwrite something valuable.
101-
if fi != nil {
94+
ents, err := os.ReadDir(dest)
95+
if err != nil {
96+
return xerrors.Errorf("read dir %q: %w", dest, err)
97+
}
98+
99+
if len(ents) > 0 {
102100
_, err = cliui.Prompt(cmd, cliui.PromptOptions{
103-
Text: fmt.Sprintf("%q already exists, do you want to overwrite it?", dest),
101+
Text: fmt.Sprintf("Directory %q is not empty, existing files may be overwritten.\nContinue extracting?", dest),
102+
Default: "No",
103+
Secret: false,
104104
IsConfirm: true,
105105
})
106106
if err != nil {
107-
return xerrors.Errorf("parse prompt: %w", err)
107+
return err
108108
}
109109
}
110110

111-
err = os.WriteFile(dest, raw, 0o600)
112-
if err != nil {
113-
return xerrors.Errorf("write to path: %w", err)
114-
}
115-
116-
return nil
111+
_, _ = fmt.Fprintf(cmd.OutOrStderr(), "Extracting template to %q\n", dest)
112+
err = extract.Tar(ctx, bytes.NewReader(raw), dest, nil)
113+
return err
117114
},
118115
}
119116

117+
cmd.Flags().BoolVar(&tarMode, "tar", false, "output the template as a tar archive to stdout")
120118
cliui.AllowSkipPrompt(cmd)
121119

122120
return cmd

0 commit comments

Comments
 (0)