Skip to content

Commit 96a6ffd

Browse files
committed
Merge branch 'main' of https://github.com/coder/coder into bq/more-actions-workspaces
2 parents 84b65a8 + f9817af commit 96a6ffd

File tree

164 files changed

+6091
-1033
lines changed

Some content is hidden

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

164 files changed

+6091
-1033
lines changed

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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ jobs:
188188
189189
# Check for any typos
190190
- name: Check for typos
191-
uses: crate-ci/typos@b1a1ef3893ff35ade0cfa71523852a49bfd05d19 # v1.31.1
191+
uses: crate-ci/typos@0f0ccba9ed1df83948f0c15026e4f5ccfce46109 # v1.32.0
192192
with:
193193
config: .github/workflows/typos.toml
194194

@@ -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/dependabot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
steps:
2424
- name: Dependabot metadata
2525
id: metadata
26-
uses: dependabot/fetch-metadata@d7267f607e9d3fb96fc2fbe83e0af444713e90b7 # v2.3.0
26+
uses: dependabot/fetch-metadata@08eff52bf64351f401fb50d4972fa95b9f2c2d1b # v2.4.0
2727
with:
2828
github-token: "${{ secrets.GITHUB_TOKEN }}"
2929

.github/workflows/docs-ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Setup Node
2929
uses: ./.github/actions/setup-node
3030

31-
- uses: tj-actions/changed-files@5426ecc3f5c2b10effaefbd374f0abdc6a571b2f # v45.0.7
31+
- uses: tj-actions/changed-files@480f49412651059a414a6a5c96887abb1877de8a # v45.0.7
3232
id: changed-files
3333
with:
3434
files: |

.github/workflows/nightly-gauntlet.yaml

Lines changed: 58 additions & 17 deletions
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

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ jobs:
4747

4848
# Upload the results to GitHub's code scanning dashboard.
4949
- name: "Upload to code-scanning"
50-
uses: github/codeql-action/upload-sarif@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
50+
uses: github/codeql-action/upload-sarif@60168efe1c415ce0f5521ea06d5c2062adbeed1b # v3.28.17
5151
with:
5252
sarif_file: results.sarif

.github/workflows/security.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
uses: ./.github/actions/setup-go
3939

4040
- name: Initialize CodeQL
41-
uses: github/codeql-action/init@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
41+
uses: github/codeql-action/init@60168efe1c415ce0f5521ea06d5c2062adbeed1b # v3.28.17
4242
with:
4343
languages: go, javascript
4444

@@ -48,7 +48,7 @@ jobs:
4848
rm Makefile
4949
5050
- name: Perform CodeQL Analysis
51-
uses: github/codeql-action/analyze@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
51+
uses: github/codeql-action/analyze@60168efe1c415ce0f5521ea06d5c2062adbeed1b # v3.28.17
5252

5353
- name: Send Slack notification on failure
5454
if: ${{ failure() }}
@@ -150,7 +150,7 @@ jobs:
150150
severity: "CRITICAL,HIGH"
151151

152152
- name: Upload Trivy scan results to GitHub Security tab
153-
uses: github/codeql-action/upload-sarif@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
153+
uses: github/codeql-action/upload-sarif@60168efe1c415ce0f5521ea06d5c2062adbeed1b # v3.28.17
154154
with:
155155
sarif_file: trivy-results.sarif
156156
category: "Trivy"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ site/stats/
5050
*.tfplan
5151
*.lock.hcl
5252
.terraform/
53+
!provisioner/terraform/testdata/modules-source-caching/.terraform/
5354

5455
**/.coderv2/*
5556
**/__debug_bin

agent/agent.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ type Options struct {
8989
ServiceBannerRefreshInterval time.Duration
9090
BlockFileTransfer bool
9191
Execer agentexec.Execer
92+
SubAgent bool
9293

9394
ExperimentalDevcontainersEnabled bool
9495
ContainerAPIOptions []agentcontainers.Option // Enable ExperimentalDevcontainersEnabled for these to be effective.
@@ -190,6 +191,8 @@ func New(options Options) Agent {
190191
metrics: newAgentMetrics(prometheusRegistry),
191192
execer: options.Execer,
192193

194+
subAgent: options.SubAgent,
195+
193196
experimentalDevcontainersEnabled: options.ExperimentalDevcontainersEnabled,
194197
containerAPIOptions: options.ContainerAPIOptions,
195198
}
@@ -272,6 +275,8 @@ type agent struct {
272275
metrics *agentMetrics
273276
execer agentexec.Execer
274277

278+
subAgent bool
279+
275280
experimentalDevcontainersEnabled bool
276281
containerAPIOptions []agentcontainers.Option
277282
containerAPI atomic.Pointer[agentcontainers.API] // Set by apiHandler.
@@ -1085,6 +1090,8 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
10851090
if err != nil {
10861091
return xerrors.Errorf("expand directory: %w", err)
10871092
}
1093+
// Normalize all devcontainer paths by making them absolute.
1094+
manifest.Devcontainers = agentcontainers.ExpandAllDevcontainerPaths(a.logger, expandPathToAbs, manifest.Devcontainers)
10881095
subsys, err := agentsdk.ProtoFromSubsystems(a.subsystems)
10891096
if err != nil {
10901097
a.logger.Critical(ctx, "failed to convert subsystems", slog.Error(err))
@@ -1127,7 +1134,7 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
11271134
)
11281135
if a.experimentalDevcontainersEnabled {
11291136
var dcScripts []codersdk.WorkspaceAgentScript
1130-
scripts, dcScripts = agentcontainers.ExtractAndInitializeDevcontainerScripts(a.logger, expandPathToAbs, manifest.Devcontainers, scripts)
1137+
scripts, dcScripts = agentcontainers.ExtractAndInitializeDevcontainerScripts(manifest.Devcontainers, scripts)
11311138
// See ExtractAndInitializeDevcontainerScripts for motivation
11321139
// behind running dcScripts as post start scripts.
11331140
scriptRunnerOpts = append(scriptRunnerOpts, agentscripts.WithPostStartScripts(dcScripts...))

agent/agent_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,8 +1998,9 @@ func TestAgent_ReconnectingPTYContainer(t *testing.T) {
19981998
// You can run it manually as follows:
19991999
//
20002000
// CODER_TEST_USE_DOCKER=1 go test -count=1 ./agent -run TestAgent_DevcontainerAutostart
2001+
//
2002+
//nolint:paralleltest // This test sets an environment variable.
20012003
func TestAgent_DevcontainerAutostart(t *testing.T) {
2002-
t.Parallel()
20032004
if os.Getenv("CODER_TEST_USE_DOCKER") != "1" {
20042005
t.Skip("Set CODER_TEST_USE_DOCKER=1 to run this test")
20052006
}
@@ -2012,9 +2013,12 @@ func TestAgent_DevcontainerAutostart(t *testing.T) {
20122013

20132014
// Prepare temporary devcontainer for test (mywork).
20142015
devcontainerID := uuid.New()
2015-
tempWorkspaceFolder := t.TempDir()
2016-
tempWorkspaceFolder = filepath.Join(tempWorkspaceFolder, "mywork")
2016+
tmpdir := t.TempDir()
2017+
t.Setenv("HOME", tmpdir)
2018+
tempWorkspaceFolder := filepath.Join(tmpdir, "mywork")
2019+
unexpandedWorkspaceFolder := filepath.Join("~", "mywork")
20172020
t.Logf("Workspace folder: %s", tempWorkspaceFolder)
2021+
t.Logf("Unexpanded workspace folder: %s", unexpandedWorkspaceFolder)
20182022
devcontainerPath := filepath.Join(tempWorkspaceFolder, ".devcontainer")
20192023
err = os.MkdirAll(devcontainerPath, 0o755)
20202024
require.NoError(t, err, "create devcontainer directory")
@@ -2031,9 +2035,10 @@ func TestAgent_DevcontainerAutostart(t *testing.T) {
20312035
// is expected to be prepared by the provisioner normally.
20322036
Devcontainers: []codersdk.WorkspaceAgentDevcontainer{
20332037
{
2034-
ID: devcontainerID,
2035-
Name: "test",
2036-
WorkspaceFolder: tempWorkspaceFolder,
2038+
ID: devcontainerID,
2039+
Name: "test",
2040+
// Use an unexpanded path to test the expansion.
2041+
WorkspaceFolder: unexpandedWorkspaceFolder,
20372042
},
20382043
},
20392044
Scripts: []codersdk.WorkspaceAgentScript{

agent/agentcontainers/devcontainer.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ devcontainer up %s
3636
// initialize the workspace (e.g. git clone, npm install, etc). This is
3737
// important if e.g. a Coder module to install @devcontainer/cli is used.
3838
func ExtractAndInitializeDevcontainerScripts(
39-
logger slog.Logger,
40-
expandPath func(string) (string, error),
4139
devcontainers []codersdk.WorkspaceAgentDevcontainer,
4240
scripts []codersdk.WorkspaceAgentScript,
4341
) (filteredScripts []codersdk.WorkspaceAgentScript, devcontainerScripts []codersdk.WorkspaceAgentScript) {
@@ -47,7 +45,6 @@ ScriptLoop:
4745
// The devcontainer scripts match the devcontainer ID for
4846
// identification.
4947
if script.ID == dc.ID {
50-
dc = expandDevcontainerPaths(logger, expandPath, dc)
5148
devcontainerScripts = append(devcontainerScripts, devcontainerStartupScript(dc, script))
5249
continue ScriptLoop
5350
}
@@ -75,6 +72,17 @@ func devcontainerStartupScript(dc codersdk.WorkspaceAgentDevcontainer, script co
7572
return script
7673
}
7774

75+
// ExpandAllDevcontainerPaths expands all devcontainer paths in the given
76+
// devcontainers. This is required by the devcontainer CLI, which requires
77+
// absolute paths for the workspace folder and config path.
78+
func ExpandAllDevcontainerPaths(logger slog.Logger, expandPath func(string) (string, error), devcontainers []codersdk.WorkspaceAgentDevcontainer) []codersdk.WorkspaceAgentDevcontainer {
79+
expanded := make([]codersdk.WorkspaceAgentDevcontainer, 0, len(devcontainers))
80+
for _, dc := range devcontainers {
81+
expanded = append(expanded, expandDevcontainerPaths(logger, expandPath, dc))
82+
}
83+
return expanded
84+
}
85+
7886
func expandDevcontainerPaths(logger slog.Logger, expandPath func(string) (string, error), dc codersdk.WorkspaceAgentDevcontainer) codersdk.WorkspaceAgentDevcontainer {
7987
logger = logger.With(slog.F("devcontainer", dc.Name), slog.F("workspace_folder", dc.WorkspaceFolder), slog.F("config_path", dc.ConfigPath))
8088

agent/agentcontainers/devcontainer_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,7 @@ func TestExtractAndInitializeDevcontainerScripts(t *testing.T) {
242242
}
243243
}
244244
gotFilteredScripts, gotDevcontainerScripts := agentcontainers.ExtractAndInitializeDevcontainerScripts(
245-
logger,
246-
tt.args.expandPath,
247-
tt.args.devcontainers,
245+
agentcontainers.ExpandAllDevcontainerPaths(logger, tt.args.expandPath, tt.args.devcontainers),
248246
tt.args.scripts,
249247
)
250248

agent/agenttest/client.go

Lines changed: 2 additions & 1 deletion
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"
@@ -60,6 +60,7 @@ func NewClient(t testing.TB,
6060
err = agentproto.DRPCRegisterAgent(mux, fakeAAPI)
6161
require.NoError(t, err)
6262
server := drpcserver.NewWithOptions(mux, drpcserver.Options{
63+
Manager: drpcsdk.DefaultDRPCOptions(nil),
6364
Log: func(err error) {
6465
if xerrors.Is(err, io.EOF) {
6566
return

cli/agent.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (r *RootCmd) workspaceAgent() *serpent.Command {
5353
blockFileTransfer bool
5454
agentHeaderCommand string
5555
agentHeader []string
56+
subAgent bool
5657

5758
experimentalDevcontainersEnabled bool
5859
)
@@ -350,6 +351,7 @@ func (r *RootCmd) workspaceAgent() *serpent.Command {
350351
PrometheusRegistry: prometheusRegistry,
351352
BlockFileTransfer: blockFileTransfer,
352353
Execer: execer,
354+
SubAgent: subAgent,
353355

354356
ExperimentalDevcontainersEnabled: experimentalDevcontainersEnabled,
355357
})
@@ -481,6 +483,17 @@ func (r *RootCmd) workspaceAgent() *serpent.Command {
481483
Description: "Allow the agent to automatically detect running devcontainers.",
482484
Value: serpent.BoolOf(&experimentalDevcontainersEnabled),
483485
},
486+
{
487+
Flag: "is-sub-agent",
488+
Default: "false",
489+
Env: "CODER_AGENT_IS_SUB_AGENT",
490+
Description: "Specify whether this is a sub agent or not.",
491+
Value: serpent.BoolOf(&subAgent),
492+
// As `coderd` handles the creation of sub-agents, it does not make
493+
// sense for this to be exposed. We do not want people setting an
494+
// agent as a sub-agent if it is not.
495+
Hidden: true,
496+
},
484497
}
485498

486499
return cmd

0 commit comments

Comments
 (0)