Skip to content

Commit c4d42a5

Browse files
committed
Merge branch 'main' into bq/users-filter
2 parents e2938fc + ee45b3d commit c4d42a5

File tree

110 files changed

+3160
-2861
lines changed

Some content is hidden

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

110 files changed

+3160
-2861
lines changed

.github/CODEOWNERS

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

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ runs:
99
steps:
1010
- shell: bash
1111
run: |
12+
owner=${{ github.repository_owner }}
13+
echo "owner: $owner"
14+
if [[ $owner != "coder" ]]; then
15+
echo "Not a pull request from the main repo, skipping..."
16+
exit 0
17+
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
1223
npm install -g @datadog/datadog-ci
1324
datadog-ci junit upload --service coder ./gotests.xml \
1425
--tags os:${{runner.os}} --tags runner_name:${{runner.name}}

.github/dependabot.yaml

Lines changed: 28 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.
@@ -58,6 +61,8 @@ updates:
5861
interval: "monthly"
5962
time: "06:00"
6063
timezone: "America/Chicago"
64+
reviewers:
65+
- "coder/ts"
6166
commit-message:
6267
prefix: "chore"
6368
labels: []
@@ -84,3 +89,26 @@ updates:
8489
ignore:
8590
# We likely want to update this ourselves.
8691
- 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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ 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:
@@ -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/nightly-flake.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: nightly-flake
2+
on:
3+
schedule:
4+
# Every day at midnight
5+
- cron: "0 0 * * *"
6+
workflow_dispatch:
7+
# For testing purposes
8+
# push:
9+
# paths:
10+
# - ".github/workflows/nightly-flake.yaml"
11+
jobs:
12+
test-go-race:
13+
# While GitHub's toaster runners are likelier to flake, we want consistency
14+
# between this environment and the regular test environment for DataDog
15+
# statistics and to only show real workflow threats.
16+
runs-on: "buildjet-8vcpu-ubuntu-2204"
17+
# This runner costs 0.016 USD per minute,
18+
# so 0.016 * 240 = 3.84 USD per run.
19+
timeout-minutes: 240
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- uses: ./.github/actions/setup-go
24+
25+
- uses: hashicorp/setup-terraform@v2
26+
with:
27+
terraform_version: 1.1.9
28+
terraform_wrapper: false
29+
30+
- name: Run Tests
31+
run: |
32+
# -race is likeliest to catch flaky tests
33+
# due to correctness detection and its performance
34+
# impact.
35+
gotestsum --junitfile="gotests.xml" -- -timeout=240m -count=10 -race ./...
36+
37+
- uses: ./.github/actions/upload-datadog
38+
if: always()
39+
with:
40+
api-key: ${{ secrets.DATADOG_API_KEY }}

cli/agent.go

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -58,58 +58,64 @@ 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.
67108
if reaper.IsInitProcess() && !noReap && isLinux {
68109
logWriter := &lumberjack.Logger{
69110
Filename: filepath.Join(logDir, "coder-agent-init.log"),
70111
MaxSize: 5, // MB
112+
// Without this, rotated logs will never be deleted.
113+
MaxBackups: 1,
71114
}
72115
defer logWriter.Close()
73116

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

114120
logger.Info(ctx, "spawning reaper process")
115121
// Do not start a reaper on the child process. It's important
@@ -146,12 +152,15 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
146152
ljLogger := &lumberjack.Logger{
147153
Filename: filepath.Join(logDir, "coder-agent.log"),
148154
MaxSize: 5, // MB
155+
// Without this, rotated logs will never be deleted.
156+
MaxBackups: 1,
149157
}
150158
defer ljLogger.Close()
151159
logWriter := &closeWriter{w: ljLogger}
152160
defer logWriter.Close()
153161

154-
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)
155164

156165
version := buildinfo.Version()
157166
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

cli/cliui/agent.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
4848
// We don't take the fast path for opts.NoWait yet because we want to
4949
// show the message.
5050
if agent.Status == codersdk.WorkspaceAgentConnected &&
51-
(agent.LoginBeforeReady || agent.LifecycleState == codersdk.WorkspaceAgentLifecycleReady) {
51+
(agent.StartupScriptBehavior == codersdk.WorkspaceAgentStartupScriptBehaviorNonBlocking || agent.LifecycleState == codersdk.WorkspaceAgentLifecycleReady) {
5252
return nil
5353
}
5454

@@ -96,7 +96,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
9696
// we do this just before starting the spinner to avoid needless
9797
// spinning.
9898
if agent.Status == codersdk.WorkspaceAgentConnected &&
99-
!agent.LoginBeforeReady && opts.NoWait {
99+
agent.StartupScriptBehavior == codersdk.WorkspaceAgentStartupScriptBehaviorBlocking && opts.NoWait {
100100
showMessage()
101101
return nil
102102
}
@@ -140,7 +140,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
140140
// NOTE(mafredri): Once we have access to the workspace agent's
141141
// startup script logs, we can show them here.
142142
// https://github.com/coder/coder/issues/2957
143-
if !agent.LoginBeforeReady && !opts.NoWait {
143+
if agent.StartupScriptBehavior == codersdk.WorkspaceAgentStartupScriptBehaviorBlocking && !opts.NoWait {
144144
switch agent.LifecycleState {
145145
case codersdk.WorkspaceAgentLifecycleReady:
146146
return nil

0 commit comments

Comments
 (0)