Skip to content

Commit 24b436f

Browse files
committed
Merge remote-tracking branch 'origin/main' into cj/scaletest-script
2 parents 105dbca + a77b48a commit 24b436f

File tree

181 files changed

+4491
-3907
lines changed

Some content is hidden

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

181 files changed

+4491
-3907
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/actions/setup-go/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ runs:
77
- uses: buildjet/setup-go@v4
88
with:
99
cache: true
10-
go-version: "~1.20"
10+
go-version: "1.20.5"
1111
- name: Install gotestsum
1212
uses: jaxxstorm/action-install-gh-release@v1.10.0
1313
with:

.github/actions/upload-datadog/action.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ runs:
99
steps:
1010
- shell: bash
1111
run: |
12-
if [[ ${{ github.event.pull_request.head.repo.full_name != 'coder/coder' }} ]]; then
12+
owner=${{ github.repository_owner }}
13+
echo "owner: $owner"
14+
if [[ $owner != "coder" ]]; then
1315
echo "Not a pull request from the main repo, skipping..."
1416
exit 0
1517
fi
18+
if [[ -z "${{ inputs.api-key }}" ]]; then
19+
# This can happen for dependabot.
20+
echo "No API key provided, skipping..."
21+
exit 0
22+
fi
1623
npm install -g @datadog/datadog-ci
1724
datadog-ci junit upload --service coder ./gotests.xml \
1825
--tags os:${{runner.os}} --tags runner_name:${{runner.name}}

.github/dependabot.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ updates:
4747
interval: "weekly"
4848
time: "06:00"
4949
timezone: "America/Chicago"
50+
commit-message:
51+
prefix: "chore"
52+
labels: []
5053
ignore:
5154
# We need to coordinate terraform updates with the version hardcoded in
5255
# our Go code.
@@ -86,3 +89,26 @@ updates:
8689
ignore:
8790
# We likely want to update this ourselves.
8891
- dependency-name: "coder/coder"
92+
93+
# Update dogfood.
94+
- package-ecosystem: "docker"
95+
directory: "/dogfood/"
96+
schedule:
97+
interval: "weekly"
98+
time: "06:00"
99+
timezone: "America/Chicago"
100+
commit-message:
101+
prefix: "chore"
102+
labels: []
103+
104+
- package-ecosystem: "terraform"
105+
directory: "/dogfood/"
106+
schedule:
107+
interval: "weekly"
108+
time: "06:00"
109+
timezone: "America/Chicago"
110+
commit-message:
111+
prefix: "chore"
112+
labels: []
113+
ignore:
114+
- dependency-name: "coder/coder"

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737

3838
# Check for any typos!
3939
- name: Check for typos
40-
uses: crate-ci/typos@v1.14.11
40+
uses: crate-ci/typos@v1.14.12
4141
with:
4242
config: .github/workflows/typos.toml
4343
- name: Fix the typos
@@ -49,7 +49,7 @@ jobs:
4949
5050
# Check for Go linting errors!
5151
- name: Lint Go
52-
uses: golangci/golangci-lint-action@v3.3.1
52+
uses: golangci/golangci-lint-action@v3.5.0
5353
with:
5454
version: v1.52.2
5555

.github/workflows/dogfood.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ on:
66
- main
77
paths:
88
- "dogfood/**"
9+
- ".github/workflows/dogfood.yaml"
910
# Uncomment these lines when testing with CI.
1011
# pull_request:
1112
# paths:
1213
# - "dogfood/**"
14+
# - ".github/workflows/dogfood.yaml"
1315
workflow_dispatch:
1416

1517
jobs:
1618
deploy_image:
17-
runs-on: ubuntu-latest
19+
runs-on: buildjet-4vcpu-ubuntu-2204
1820
steps:
1921
- name: Get branch name
2022
id: branch-name
@@ -57,14 +59,13 @@ jobs:
5759
- name: Get short commit SHA
5860
id: vars
5961
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
60-
- name: "Install latest Coder"
62+
- name: "Get latest Coder binary from the server"
6163
run: |
62-
curl -L https://coder.com/install.sh | sh
63-
# env:
64-
# VERSION: 0.x
64+
curl -fsSL "https://dev.coder.com/bin/coder-linux-amd64" -o "./coder"
65+
chmod +x "./coder"
6566
- name: "Push template"
6667
run: |
67-
coder templates push $CODER_TEMPLATE_NAME --directory $CODER_TEMPLATE_DIR --yes --name=$CODER_TEMPLATE_VERSION
68+
./coder templates push $CODER_TEMPLATE_NAME --directory $CODER_TEMPLATE_DIR --yes --name=$CODER_TEMPLATE_VERSION
6869
env:
6970
# Consumed by Coder CLI
7071
CODER_URL: https://dev.coder.com

.github/workflows/release.yaml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ on:
66
- "v*"
77
workflow_dispatch:
88
inputs:
9-
go_version:
10-
description: "Go version to use for building."
11-
required: false
12-
default: "1.20.4"
139
dry_run:
1410
description: Perform a dry-run release (devel). Note that ref must be an annotated tag when run without dry-run.
1511
type: boolean
@@ -35,7 +31,7 @@ env:
3531
# For some reason, setup-go won't actually pick up a new patch version if
3632
# it has an old one cached. We need to manually specify the versions so we
3733
# can get the latest release. Never use "~1.xx" here!
38-
CODER_GO_VERSION: "1.20.4"
34+
CODER_GO_VERSION: "1.20.5"
3935

4036
jobs:
4137
release:
@@ -98,10 +94,7 @@ jobs:
9894
username: ${{ github.actor }}
9995
password: ${{ secrets.GITHUB_TOKEN }}
10096

101-
- uses: buildjet/setup-go@v4
102-
with:
103-
go-version: ${{ env.CODER_GO_VERSION }}
104-
cache: true
97+
- uses: ./.github/actions/setup-go
10598

10699
- name: Cache Node
107100
id: cache-node

.github/workflows/security.yaml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ concurrency:
1919
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
2020

2121
env:
22-
CODER_GO_VERSION: "1.20.4"
22+
CODER_GO_VERSION: "1.20.5"
2323

2424
jobs:
2525
codeql:
@@ -32,10 +32,7 @@ jobs:
3232
with:
3333
languages: go, javascript
3434

35-
- name: Setup Go
36-
uses: buildjet/setup-go@v4
37-
with:
38-
go-version: ${{ env.CODER_GO_VERSION }}
35+
- uses: ./.github/actions/setup-go
3936

4037
# Workaround to prevent CodeQL from building the dashboard.
4138
- name: Remove Makefile
@@ -63,10 +60,7 @@ jobs:
6360
with:
6461
fetch-depth: 0
6562

66-
- uses: buildjet/setup-go@v4
67-
with:
68-
go-version: ${{ env.CODER_GO_VERSION }}
69-
cache: true
63+
- uses: ./.github/actions/setup-go
7064

7165
- name: Cache Node
7266
id: cache-node

.github/workflows/cron-weekly.yaml renamed to .github/workflows/weekly-docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Weekly Cron
1+
name: weekly-docs
22
# runs every monday at 9 am
33
on:
44
schedule:

cli/agent.go

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,50 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
5858
ctx, cancel := context.WithCancel(inv.Context())
5959
defer cancel()
6060

61-
ignorePorts := map[int]string{}
61+
var (
62+
ignorePorts = map[int]string{}
63+
isLinux = runtime.GOOS == "linux"
6264

63-
isLinux := runtime.GOOS == "linux"
65+
sinks = []slog.Sink{}
66+
logClosers = []func() error{}
67+
)
68+
defer func() {
69+
for _, closer := range logClosers {
70+
_ = closer()
71+
}
72+
}()
73+
74+
addSinkIfProvided := func(sinkFn func(io.Writer) slog.Sink, loc string) error {
75+
switch loc {
76+
case "":
77+
// Do nothing.
78+
79+
case "/dev/stderr":
80+
sinks = append(sinks, sinkFn(inv.Stderr))
81+
82+
case "/dev/stdout":
83+
sinks = append(sinks, sinkFn(inv.Stdout))
84+
85+
default:
86+
fi, err := os.OpenFile(loc, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
87+
if err != nil {
88+
return xerrors.Errorf("open log file %q: %w", loc, err)
89+
}
90+
sinks = append(sinks, sinkFn(fi))
91+
logClosers = append(logClosers, fi.Close)
92+
}
93+
return nil
94+
}
95+
96+
if err := addSinkIfProvided(sloghuman.Sink, slogHumanPath); err != nil {
97+
return xerrors.Errorf("add human sink: %w", err)
98+
}
99+
if err := addSinkIfProvided(slogjson.Sink, slogJSONPath); err != nil {
100+
return xerrors.Errorf("add json sink: %w", err)
101+
}
102+
if err := addSinkIfProvided(slogstackdriver.Sink, slogStackdriverPath); err != nil {
103+
return xerrors.Errorf("add stackdriver sink: %w", err)
104+
}
64105

65106
// Spawn a reaper so that we don't accumulate a ton
66107
// of zombie processes.
@@ -73,45 +114,8 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
73114
}
74115
defer logWriter.Close()
75116

76-
sinks := []slog.Sink{sloghuman.Sink(logWriter)}
77-
closers := []func() error{}
78-
addSinkIfProvided := func(sinkFn func(io.Writer) slog.Sink, loc string) error {
79-
switch loc {
80-
case "":
81-
82-
case "/dev/stdout":
83-
sinks = append(sinks, sinkFn(inv.Stdout))
84-
85-
case "/dev/stderr":
86-
sinks = append(sinks, sinkFn(inv.Stderr))
87-
88-
default:
89-
fi, err := os.OpenFile(loc, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
90-
if err != nil {
91-
return xerrors.Errorf("open log file %q: %w", loc, err)
92-
}
93-
closers = append(closers, fi.Close)
94-
sinks = append(sinks, sinkFn(fi))
95-
}
96-
return nil
97-
}
98-
99-
if err := addSinkIfProvided(sloghuman.Sink, slogHumanPath); err != nil {
100-
return xerrors.Errorf("add human sink: %w", err)
101-
}
102-
if err := addSinkIfProvided(slogjson.Sink, slogJSONPath); err != nil {
103-
return xerrors.Errorf("add json sink: %w", err)
104-
}
105-
if err := addSinkIfProvided(slogstackdriver.Sink, slogStackdriverPath); err != nil {
106-
return xerrors.Errorf("add stackdriver sink: %w", err)
107-
}
108-
117+
sinks = append(sinks, sloghuman.Sink(logWriter))
109118
logger := slog.Make(sinks...).Leveled(slog.LevelDebug)
110-
defer func() {
111-
for _, closer := range closers {
112-
_ = closer()
113-
}
114-
}()
115119

116120
logger.Info(ctx, "spawning reaper process")
117121
// Do not start a reaper on the child process. It's important
@@ -155,7 +159,8 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
155159
logWriter := &closeWriter{w: ljLogger}
156160
defer logWriter.Close()
157161

158-
logger := slog.Make(sloghuman.Sink(inv.Stderr), sloghuman.Sink(logWriter)).Leveled(slog.LevelDebug)
162+
sinks = append(sinks, sloghuman.Sink(logWriter))
163+
logger := slog.Make(sinks...).Leveled(slog.LevelDebug)
159164

160165
version := buildinfo.Version()
161166
logger.Info(ctx, "starting agent",

cli/clitest/clitest.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"github.com/stretchr/testify/assert"
1919
"github.com/stretchr/testify/require"
2020

21+
"cdr.dev/slog"
22+
"cdr.dev/slog/sloggers/slogtest"
2123
"github.com/coder/coder/cli"
2224
"github.com/coder/coder/cli/clibase"
2325
"github.com/coder/coder/cli/config"
@@ -39,16 +41,17 @@ func New(t *testing.T, args ...string) (*clibase.Invocation, config.Root) {
3941

4042
type logWriter struct {
4143
prefix string
42-
t *testing.T
44+
log slog.Logger
4345
}
4446

4547
func (l *logWriter) Write(p []byte) (n int, err error) {
4648
trimmed := strings.TrimSpace(string(p))
4749
if trimmed == "" {
4850
return len(p), nil
4951
}
50-
l.t.Log(
51-
l.prefix + ": " + trimmed,
52+
l.log.Info(
53+
context.Background(),
54+
l.prefix+": "+trimmed,
5255
)
5356
return len(p), nil
5457
}
@@ -57,12 +60,13 @@ func NewWithCommand(
5760
t *testing.T, cmd *clibase.Cmd, args ...string,
5861
) (*clibase.Invocation, config.Root) {
5962
configDir := config.Root(t.TempDir())
63+
logger := slogtest.Make(t, nil)
6064
i := &clibase.Invocation{
6165
Command: cmd,
6266
Args: append([]string{"--global-config", string(configDir)}, args...),
6367
Stdin: io.LimitReader(nil, 0),
64-
Stdout: (&logWriter{prefix: "stdout", t: t}),
65-
Stderr: (&logWriter{prefix: "stderr", t: t}),
68+
Stdout: (&logWriter{prefix: "stdout", log: logger}),
69+
Stderr: (&logWriter{prefix: "stderr", log: logger}),
6670
}
6771
t.Logf("invoking command: %s %s", cmd.Name(), strings.Join(i.Args, " "))
6872

0 commit comments

Comments
 (0)