Skip to content

Commit 12985c5

Browse files
committed
Merge remote-tracking branch 'origin/main' into ssncferreira/fix-deprecated-templates
2 parents b344266 + 15bd7a3 commit 12985c5

File tree

38 files changed

+161
-122
lines changed

38 files changed

+161
-122
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ runs:
2626
export GOCACHE_DIR="$RUNNER_TEMP""\go-cache"
2727
export GOMODCACHE_DIR="$RUNNER_TEMP""\go-mod-cache"
2828
export GOPATH_DIR="$RUNNER_TEMP""\go-path"
29+
export GOTMP_DIR="$RUNNER_TEMP""\go-tmp"
2930
mkdir -p "$GOCACHE_DIR"
3031
mkdir -p "$GOMODCACHE_DIR"
3132
mkdir -p "$GOPATH_DIR"
33+
mkdir -p "$GOTMP_DIR"
3234
go env -w GOCACHE="$GOCACHE_DIR"
3335
go env -w GOMODCACHE="$GOMODCACHE_DIR"
3436
go env -w GOPATH="$GOPATH_DIR"
35-
37+
go env -w GOTMPDIR="$GOTMP_DIR"
3638
- name: Setup Go
3739
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
3840
with:

.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ jobs:
454454
api-key: ${{ secrets.DATADOG_API_KEY }}
455455

456456
test-go-pg:
457-
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'depot-ubuntu-22.04-4' || matrix.os }}
457+
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || matrix.os }}
458458
needs: changes
459459
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
460460
# This timeout must be greater than the timeout set by `go test` in

.github/workflows/nightly-gauntlet.yaml

+58-17
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ permissions:
1212

1313
jobs:
1414
test-go-pg:
15-
runs-on: ${{ matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'depot-macos-latest' || matrix.os == 'windows-2022' && github.repository_owner == 'coder' && 'windows-latest-16-cores' || matrix.os }}
16-
if: github.ref == 'refs/heads/main'
15+
# make sure to adjust NUM_PARALLEL_PACKAGES and NUM_PARALLEL_TESTS below
16+
# when changing runner sizes
17+
runs-on: ${{ matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'depot-macos-latest' || matrix.os == 'windows-2022' && github.repository_owner == 'coder' && 'depot-windows-2022-16' || matrix.os }}
1718
# This timeout must be greater than the timeout set by `go test` in
1819
# `make test-postgres` to ensure we receive a trace of running
1920
# goroutines. Setting this to the timeout +5m should work quite well
@@ -31,22 +32,39 @@ jobs:
3132
with:
3233
egress-policy: audit
3334

35+
# macOS indexes all new files in the background. Our Postgres tests
36+
# create and destroy thousands of databases on disk, and Spotlight
37+
# tries to index all of them, seriously slowing down the tests.
38+
- name: Disable Spotlight Indexing
39+
if: runner.os == 'macOS'
40+
run: |
41+
sudo mdutil -a -i off
42+
sudo mdutil -X /
43+
sudo launchctl bootout system /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
44+
45+
# Set up RAM disks to speed up the rest of the job. This action is in
46+
# a separate repository to allow its use before actions/checkout.
47+
- name: Setup RAM Disks
48+
if: runner.os == 'Windows'
49+
uses: coder/setup-ramdisk-action@79dacfe70c47ad6d6c0dd7f45412368802641439
50+
3451
- name: Checkout
3552
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3653
with:
3754
fetch-depth: 1
3855

3956
- name: Setup Go
4057
uses: ./.github/actions/setup-go
58+
with:
59+
# Runners have Go baked-in and Go will automatically
60+
# download the toolchain configured in go.mod, so we don't
61+
# need to reinstall it. It's faster on Windows runners.
62+
use-preinstalled-go: ${{ runner.os == 'Windows' }}
63+
use-temp-cache-dirs: ${{ runner.os == 'Windows' }}
4164

4265
- name: Setup Terraform
4366
uses: ./.github/actions/setup-tf
4467

45-
# Sets up the ImDisk toolkit for Windows and creates a RAM disk on drive R:.
46-
- name: Setup ImDisk
47-
if: runner.os == 'Windows'
48-
uses: ./.github/actions/setup-imdisk
49-
5068
- name: Test with PostgreSQL Database
5169
env:
5270
POSTGRES_VERSION: "13"
@@ -55,6 +73,19 @@ jobs:
5573
LC_ALL: "en_US.UTF-8"
5674
shell: bash
5775
run: |
76+
if [ "${{ runner.os }}" == "Windows" ]; then
77+
# Create a temp dir on the R: ramdisk drive for Windows. The default
78+
# C: drive is extremely slow: https://github.com/actions/runner-images/issues/8755
79+
mkdir -p "R:/temp/embedded-pg"
80+
go run scripts/embedded-pg/main.go -path "R:/temp/embedded-pg"
81+
fi
82+
if [ "${{ runner.os }}" == "macOS" ]; then
83+
# Postgres runs faster on a ramdisk on macOS too
84+
mkdir -p /tmp/tmpfs
85+
sudo mount_tmpfs -o noowners -s 8g /tmp/tmpfs
86+
go run scripts/embedded-pg/main.go -path /tmp/tmpfs/embedded-pg
87+
fi
88+
5889
# if macOS, install google-chrome for scaletests
5990
# As another concern, should we really have this kind of external dependency
6091
# requirement on standard CI?
@@ -72,19 +103,29 @@ jobs:
72103
touch ~/.bash_profile && echo "export BASH_SILENCE_DEPRECATION_WARNING=1" >> ~/.bash_profile
73104
fi
74105
106+
# Golang's default for these 2 variables is the number of logical CPUs.
107+
# Our Windows and Linux runners have 16 cores, so they match up there.
108+
NUM_PARALLEL_PACKAGES=16
109+
NUM_PARALLEL_TESTS=16
75110
if [ "${{ runner.os }}" == "Windows" ]; then
76-
# Create a temp dir on the R: ramdisk drive for Windows. The default
77-
# C: drive is extremely slow: https://github.com/actions/runner-images/issues/8755
78-
mkdir -p "R:/temp/embedded-pg"
79-
go run scripts/embedded-pg/main.go -path "R:/temp/embedded-pg"
80-
else
81-
go run scripts/embedded-pg/main.go
111+
# On Windows Postgres chokes up when we have 16x16=256 tests
112+
# running in parallel, and dbtestutil.NewDB starts to take more than
113+
# 10s to complete sometimes causing test timeouts. With 16x8=128 tests
114+
# Postgres tends not to choke.
115+
NUM_PARALLEL_PACKAGES=8
116+
fi
117+
if [ "${{ runner.os }}" == "macOS" ]; then
118+
# Our macOS runners have 8 cores. We leave NUM_PARALLEL_TESTS at 16
119+
# because the tests complete faster and Postgres doesn't choke. It seems
120+
# that macOS's tmpfs is faster than the one on Windows.
121+
NUM_PARALLEL_PACKAGES=8
82122
fi
83123
84-
# Reduce test parallelism, mirroring what we do for race tests.
85-
# We'd been encountering issues with timing related flakes, and
86-
# this seems to help.
87-
DB=ci gotestsum --format standard-quiet -- -v -short -count=1 -parallel 4 -p 4 ./...
124+
# We rerun failing tests to counteract flakiness coming from Postgres
125+
# choking on macOS and Windows sometimes.
126+
DB=ci gotestsum --rerun-fails=2 --rerun-fails-max-failures=1000 \
127+
--format standard-quiet --packages "./..." \
128+
-- -v -p $NUM_PARALLEL_PACKAGES -parallel=$NUM_PARALLEL_TESTS -count=1
88129
89130
- name: Upload test stats to Datadog
90131
timeout-minutes: 1

agent/agenttest/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
agentproto "github.com/coder/coder/v2/agent/proto"
2525
"github.com/coder/coder/v2/codersdk"
2626
"github.com/coder/coder/v2/codersdk/agentsdk"
27-
drpcsdk "github.com/coder/coder/v2/codersdk/drpc"
27+
"github.com/coder/coder/v2/codersdk/drpcsdk"
2828
"github.com/coder/coder/v2/tailnet"
2929
"github.com/coder/coder/v2/tailnet/proto"
3030
"github.com/coder/coder/v2/testutil"

cli/exp_mcp_test.go

+18-15
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,29 @@ func TestExpMcpServer(t *testing.T) {
133133
require.Equal(t, 1.0, initializeResponse["id"])
134134
require.NotNil(t, initializeResponse["result"])
135135
})
136+
}
136137

137-
t.Run("NoCredentials", func(t *testing.T) {
138-
t.Parallel()
138+
func TestExpMcpServerNoCredentials(t *testing.T) {
139+
// Ensure that no credentials are set from the environment.
140+
t.Setenv("CODER_AGENT_TOKEN", "")
141+
t.Setenv("CODER_AGENT_TOKEN_FILE", "")
142+
t.Setenv("CODER_SESSION_TOKEN", "")
139143

140-
ctx := testutil.Context(t, testutil.WaitShort)
141-
cancelCtx, cancel := context.WithCancel(ctx)
142-
t.Cleanup(cancel)
144+
ctx := testutil.Context(t, testutil.WaitShort)
145+
cancelCtx, cancel := context.WithCancel(ctx)
146+
t.Cleanup(cancel)
143147

144-
client := coderdtest.New(t, nil)
145-
inv, root := clitest.New(t, "exp", "mcp", "server")
146-
inv = inv.WithContext(cancelCtx)
148+
client := coderdtest.New(t, nil)
149+
inv, root := clitest.New(t, "exp", "mcp", "server")
150+
inv = inv.WithContext(cancelCtx)
147151

148-
pty := ptytest.New(t)
149-
inv.Stdin = pty.Input()
150-
inv.Stdout = pty.Output()
151-
clitest.SetupConfig(t, client, root)
152+
pty := ptytest.New(t)
153+
inv.Stdin = pty.Input()
154+
inv.Stdout = pty.Output()
155+
clitest.SetupConfig(t, client, root)
152156

153-
err := inv.Run()
154-
assert.ErrorContains(t, err, "are not logged in")
155-
})
157+
err := inv.Run()
158+
assert.ErrorContains(t, err, "are not logged in")
156159
}
157160

158161
//nolint:tparallel,paralleltest

cli/server.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import (
6666
"github.com/coder/coder/v2/coderd/notifications/reports"
6767
"github.com/coder/coder/v2/coderd/runtimeconfig"
6868
"github.com/coder/coder/v2/coderd/webpush"
69+
"github.com/coder/coder/v2/codersdk/drpcsdk"
6970

7071
"github.com/coder/coder/v2/buildinfo"
7172
"github.com/coder/coder/v2/cli/clilog"
@@ -102,7 +103,6 @@ import (
102103
"github.com/coder/coder/v2/coderd/workspaceapps/appurl"
103104
"github.com/coder/coder/v2/coderd/workspacestats"
104105
"github.com/coder/coder/v2/codersdk"
105-
"github.com/coder/coder/v2/codersdk/drpc"
106106
"github.com/coder/coder/v2/cryptorand"
107107
"github.com/coder/coder/v2/provisioner/echo"
108108
"github.com/coder/coder/v2/provisioner/terraform"
@@ -1447,7 +1447,7 @@ func newProvisionerDaemon(
14471447
for _, provisionerType := range provisionerTypes {
14481448
switch provisionerType {
14491449
case codersdk.ProvisionerTypeEcho:
1450-
echoClient, echoServer := drpc.MemTransportPipe()
1450+
echoClient, echoServer := drpcsdk.MemTransportPipe()
14511451
wg.Add(1)
14521452
go func() {
14531453
defer wg.Done()
@@ -1481,7 +1481,7 @@ func newProvisionerDaemon(
14811481
}
14821482

14831483
tracer := coderAPI.TracerProvider.Tracer(tracing.TracerName)
1484-
terraformClient, terraformServer := drpc.MemTransportPipe()
1484+
terraformClient, terraformServer := drpcsdk.MemTransportPipe()
14851485
wg.Add(1)
14861486
go func() {
14871487
defer wg.Done()

coderd/coderd.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import (
8484
"github.com/coder/coder/v2/coderd/workspaceapps"
8585
"github.com/coder/coder/v2/coderd/workspacestats"
8686
"github.com/coder/coder/v2/codersdk"
87-
"github.com/coder/coder/v2/codersdk/drpc"
87+
"github.com/coder/coder/v2/codersdk/drpcsdk"
8888
"github.com/coder/coder/v2/codersdk/healthsdk"
8989
"github.com/coder/coder/v2/provisionerd/proto"
9090
"github.com/coder/coder/v2/provisionersdk"
@@ -1725,7 +1725,7 @@ func (api *API) CreateInMemoryProvisionerDaemon(dialCtx context.Context, name st
17251725

17261726
func (api *API) CreateInMemoryTaggedProvisionerDaemon(dialCtx context.Context, name string, provisionerTypes []codersdk.ProvisionerType, provisionerTags map[string]string) (client proto.DRPCProvisionerDaemonClient, err error) {
17271727
tracer := api.TracerProvider.Tracer(tracing.TracerName)
1728-
clientSession, serverSession := drpc.MemTransportPipe()
1728+
clientSession, serverSession := drpcsdk.MemTransportPipe()
17291729
defer func() {
17301730
if err != nil {
17311731
_ = clientSession.Close()

coderd/coderdtest/coderdtest.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import (
8484
"github.com/coder/coder/v2/coderd/workspacestats"
8585
"github.com/coder/coder/v2/codersdk"
8686
"github.com/coder/coder/v2/codersdk/agentsdk"
87-
"github.com/coder/coder/v2/codersdk/drpc"
87+
"github.com/coder/coder/v2/codersdk/drpcsdk"
8888
"github.com/coder/coder/v2/codersdk/healthsdk"
8989
"github.com/coder/coder/v2/cryptorand"
9090
"github.com/coder/coder/v2/provisioner/echo"
@@ -657,7 +657,7 @@ func NewTaggedProvisionerDaemon(t testing.TB, coderAPI *coderd.API, name string,
657657
// seems t.TempDir() is not safe to call from a different goroutine
658658
workDir := t.TempDir()
659659

660-
echoClient, echoServer := drpc.MemTransportPipe()
660+
echoClient, echoServer := drpcsdk.MemTransportPipe()
661661
ctx, cancelFunc := context.WithCancel(context.Background())
662662
t.Cleanup(func() {
663663
_ = echoClient.Close()

coderd/provisionerdserver/provisionerdserver.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
protobuf "google.golang.org/protobuf/proto"
2727

2828
"cdr.dev/slog"
29+
"github.com/coder/coder/v2/codersdk/drpcsdk"
2930

3031
"github.com/coder/quartz"
3132

@@ -43,7 +44,6 @@ import (
4344
"github.com/coder/coder/v2/coderd/tracing"
4445
"github.com/coder/coder/v2/coderd/wspubsub"
4546
"github.com/coder/coder/v2/codersdk"
46-
"github.com/coder/coder/v2/codersdk/drpc"
4747
"github.com/coder/coder/v2/provisioner"
4848
"github.com/coder/coder/v2/provisionerd/proto"
4949
"github.com/coder/coder/v2/provisionersdk"
@@ -707,8 +707,8 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo
707707
default:
708708
return nil, failJob(fmt.Sprintf("unsupported storage method: %s", job.StorageMethod))
709709
}
710-
if protobuf.Size(protoJob) > drpc.MaxMessageSize {
711-
return nil, failJob(fmt.Sprintf("payload was too big: %d > %d", protobuf.Size(protoJob), drpc.MaxMessageSize))
710+
if protobuf.Size(protoJob) > drpcsdk.MaxMessageSize {
711+
return nil, failJob(fmt.Sprintf("payload was too big: %d > %d", protobuf.Size(protoJob), drpcsdk.MaxMessageSize))
712712
}
713713

714714
return protoJob, err

codersdk/agentsdk/agentsdk.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/coder/coder/v2/agent/proto"
2323
"github.com/coder/coder/v2/apiversion"
2424
"github.com/coder/coder/v2/codersdk"
25-
drpcsdk "github.com/coder/coder/v2/codersdk/drpc"
25+
"github.com/coder/coder/v2/codersdk/drpcsdk"
2626
tailnetproto "github.com/coder/coder/v2/tailnet/proto"
2727
"github.com/coder/websocket"
2828
)

codersdk/drpc/transport.go renamed to codersdk/drpcsdk/transport.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package drpc
1+
package drpcsdk
22

33
import (
44
"context"

codersdk/provisionerdaemons.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"golang.org/x/xerrors"
1818

1919
"github.com/coder/coder/v2/buildinfo"
20-
"github.com/coder/coder/v2/codersdk/drpc"
20+
"github.com/coder/coder/v2/codersdk/drpcsdk"
2121
"github.com/coder/coder/v2/codersdk/wsjson"
2222
"github.com/coder/coder/v2/provisionerd/proto"
2323
"github.com/coder/coder/v2/provisionerd/runner"
@@ -332,7 +332,7 @@ func (c *Client) ServeProvisionerDaemon(ctx context.Context, req ServeProvisione
332332
_ = wsNetConn.Close()
333333
return nil, xerrors.Errorf("multiplex client: %w", err)
334334
}
335-
return proto.NewDRPCProvisionerDaemonClient(drpc.MultiplexedConn(session)), nil
335+
return proto.NewDRPCProvisionerDaemonClient(drpcsdk.MultiplexedConn(session)), nil
336336
}
337337

338338
type ProvisionerKeyTags map[string]string

enterprise/cli/provisionerdaemonstart.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/coder/coder/v2/cli/cliutil"
2626
"github.com/coder/coder/v2/coderd/database"
2727
"github.com/coder/coder/v2/codersdk"
28-
"github.com/coder/coder/v2/codersdk/drpc"
28+
"github.com/coder/coder/v2/codersdk/drpcsdk"
2929
"github.com/coder/coder/v2/provisioner/terraform"
3030
"github.com/coder/coder/v2/provisionerd"
3131
provisionerdproto "github.com/coder/coder/v2/provisionerd/proto"
@@ -173,7 +173,7 @@ func (r *RootCmd) provisionerDaemonStart() *serpent.Command {
173173
return err
174174
}
175175

176-
terraformClient, terraformServer := drpc.MemTransportPipe()
176+
terraformClient, terraformServer := drpcsdk.MemTransportPipe()
177177
go func() {
178178
<-ctx.Done()
179179
_ = terraformClient.Close()

enterprise/coderd/coderdenttest/coderdenttest.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/coder/coder/v2/coderd/database/dbmem"
2626
"github.com/coder/coder/v2/coderd/database/pubsub"
2727
"github.com/coder/coder/v2/codersdk"
28-
"github.com/coder/coder/v2/codersdk/drpc"
28+
"github.com/coder/coder/v2/codersdk/drpcsdk"
2929
"github.com/coder/coder/v2/enterprise/coderd"
3030
"github.com/coder/coder/v2/enterprise/coderd/license"
3131
"github.com/coder/coder/v2/enterprise/dbcrypt"
@@ -344,7 +344,7 @@ func newExternalProvisionerDaemon(t testing.TB, client *codersdk.Client, org uui
344344
return nil
345345
}
346346

347-
provisionerClient, provisionerSrv := drpc.MemTransportPipe()
347+
provisionerClient, provisionerSrv := drpcsdk.MemTransportPipe()
348348
ctx, cancelFunc := context.WithCancel(context.Background())
349349
serveDone := make(chan struct{})
350350
t.Cleanup(func() {

enterprise/coderd/provisionerdaemons_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/coder/coder/v2/coderd/rbac"
2626
"github.com/coder/coder/v2/coderd/util/ptr"
2727
"github.com/coder/coder/v2/codersdk"
28-
"github.com/coder/coder/v2/codersdk/drpc"
28+
"github.com/coder/coder/v2/codersdk/drpcsdk"
2929
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
3030
"github.com/coder/coder/v2/enterprise/coderd/license"
3131
"github.com/coder/coder/v2/provisioner/echo"
@@ -396,7 +396,7 @@ func TestProvisionerDaemonServe(t *testing.T) {
396396
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
397397
defer cancel()
398398

399-
terraformClient, terraformServer := drpc.MemTransportPipe()
399+
terraformClient, terraformServer := drpcsdk.MemTransportPipe()
400400
go func() {
401401
<-ctx.Done()
402402
_ = terraformClient.Close()

provisioner/echo/serve_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/stretchr/testify/assert"
88
"github.com/stretchr/testify/require"
99

10-
"github.com/coder/coder/v2/codersdk/drpc"
10+
"github.com/coder/coder/v2/codersdk/drpcsdk"
1111
"github.com/coder/coder/v2/provisioner/echo"
1212
"github.com/coder/coder/v2/provisionersdk"
1313
"github.com/coder/coder/v2/provisionersdk/proto"
@@ -20,7 +20,7 @@ func TestEcho(t *testing.T) {
2020
workdir := t.TempDir()
2121

2222
// Create an in-memory provisioner to communicate with.
23-
client, server := drpc.MemTransportPipe()
23+
client, server := drpcsdk.MemTransportPipe()
2424
ctx, cancelFunc := context.WithCancel(context.Background())
2525
t.Cleanup(func() {
2626
_ = client.Close()

0 commit comments

Comments
 (0)