Skip to content

Commit c0e6e94

Browse files
committed
Merge branch 'main' into template-push-active-options
2 parents cd158c5 + ec5ef51 commit c0e6e94

Some content is hidden

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

59 files changed

+1214
-629
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141

4242
# Check for any typos!
4343
- name: Check for typos
44-
uses: crate-ci/typos@v1.14.8
44+
uses: crate-ci/typos@v1.14.9
4545
with:
4646
config: .github/workflows/typos.toml
4747
- name: Fix the typos

.github/workflows/stale.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Checkout repository
3939
uses: actions/checkout@v2
4040
- name: Run delete-old-branches-action
41-
uses: beatlabs/delete-old-branches-action@v0.0.9
41+
uses: beatlabs/delete-old-branches-action@v0.0.10
4242
with:
4343
repo_token: ${{ github.token }}
4444
date: "6 months ago"

agent/agent.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Options struct {
6262
IgnorePorts map[int]string
6363
SSHMaxTimeout time.Duration
6464
TailnetListenPort uint16
65+
Subsystem codersdk.AgentSubsystem
6566
}
6667

6768
type Client interface {
@@ -119,6 +120,7 @@ func New(options Options) Agent {
119120
ignorePorts: options.IgnorePorts,
120121
connStatsChan: make(chan *agentsdk.Stats, 1),
121122
sshMaxTimeout: options.SSHMaxTimeout,
123+
subsystem: options.Subsystem,
122124
}
123125
a.init(ctx)
124126
return a
@@ -136,6 +138,7 @@ type agent struct {
136138
// listing all listening ports. This is helpful to hide ports that
137139
// are used by the agent, that the user does not care about.
138140
ignorePorts map[int]string
141+
subsystem codersdk.AgentSubsystem
139142

140143
reconnectingPTYs sync.Map
141144
reconnectingPTYTimeout time.Duration
@@ -488,6 +491,7 @@ func (a *agent) run(ctx context.Context) error {
488491
err = a.client.PostStartup(ctx, agentsdk.PostStartupRequest{
489492
Version: buildinfo.Version(),
490493
ExpandedDirectory: manifest.Directory,
494+
Subsystem: a.subsystem,
491495
})
492496
if err != nil {
493497
return xerrors.Errorf("update workspace agent version: %w", err)
@@ -1455,3 +1459,8 @@ func expandDirectory(dir string) (string, error) {
14551459
}
14561460
return dir, nil
14571461
}
1462+
1463+
// EnvAgentSubsystem is the environment variable used to denote the
1464+
// specialized environment in which the agent is running
1465+
// (e.g. envbox, envbuilder).
1466+
const EnvAgentSubsystem = "CODER_AGENT_SUBSYSTEM"

cli/agent.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/coder/coder/agent/reaper"
2727
"github.com/coder/coder/buildinfo"
2828
"github.com/coder/coder/cli/clibase"
29+
"github.com/coder/coder/codersdk"
2930
"github.com/coder/coder/codersdk/agentsdk"
3031
)
3132

@@ -197,6 +198,7 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
197198
return xerrors.Errorf("add executable to $PATH: %w", err)
198199
}
199200

201+
subsystem := inv.Environ.Get(agent.EnvAgentSubsystem)
200202
agnt := agent.New(agent.Options{
201203
Client: client,
202204
Logger: logger,
@@ -218,6 +220,7 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
218220
},
219221
IgnorePorts: ignorePorts,
220222
SSHMaxTimeout: sshMaxTimeout,
223+
Subsystem: codersdk.AgentSubsystem(subsystem),
221224
})
222225

223226
debugSrvClose := ServeHandler(ctx, logger, agnt.HTTPDebug(), debugAddress, "debug")

cli/agent_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import (
1212
"github.com/stretchr/testify/assert"
1313
"github.com/stretchr/testify/require"
1414

15+
"github.com/coder/coder/agent"
1516
"github.com/coder/coder/cli/clitest"
1617
"github.com/coder/coder/coderd/coderdtest"
18+
"github.com/coder/coder/codersdk"
1719
"github.com/coder/coder/provisioner/echo"
1820
"github.com/coder/coder/provisionersdk/proto"
1921
"github.com/coder/coder/pty/ptytest"
@@ -235,4 +237,43 @@ func TestWorkspaceAgent(t *testing.T) {
235237
_, err = uuid.Parse(strings.TrimSpace(string(token)))
236238
require.NoError(t, err)
237239
})
240+
241+
t.Run("PostStartup", func(t *testing.T) {
242+
t.Parallel()
243+
244+
authToken := uuid.NewString()
245+
client := coderdtest.New(t, &coderdtest.Options{
246+
IncludeProvisionerDaemon: true,
247+
})
248+
user := coderdtest.CreateFirstUser(t, client)
249+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
250+
Parse: echo.ParseComplete,
251+
ProvisionApply: echo.ProvisionApplyWithAgent(authToken),
252+
})
253+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
254+
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
255+
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
256+
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
257+
258+
logDir := t.TempDir()
259+
inv, _ := clitest.New(t,
260+
"agent",
261+
"--auth", "token",
262+
"--agent-token", authToken,
263+
"--agent-url", client.URL.String(),
264+
"--log-dir", logDir,
265+
)
266+
// Set the subsystem for the agent.
267+
inv.Environ.Set(agent.EnvAgentSubsystem, string(codersdk.AgentSubsystemEnvbox))
268+
269+
pty := ptytest.New(t).Attach(inv)
270+
271+
clitest.Start(t, inv)
272+
pty.ExpectMatch("starting agent")
273+
274+
resources := coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
275+
require.Len(t, resources, 1)
276+
require.Len(t, resources[0].Agents, 1)
277+
require.Equal(t, codersdk.AgentSubsystemEnvbox, resources[0].Agents[0].Subsystem)
278+
})
238279
}

cli/clitest/clitest.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func Start(t *testing.T, inv *clibase.Invocation) {
137137
// before ours.
138138
waiter := StartWithWaiter(t, inv)
139139
t.Cleanup(func() {
140+
waiter.Cancel()
140141
<-closeCh
141142
})
142143

@@ -163,11 +164,16 @@ func Run(t *testing.T, inv *clibase.Invocation) {
163164
type ErrorWaiter struct {
164165
waitOnce sync.Once
165166
cachedError error
167+
cancelFunc context.CancelFunc
166168

167169
c <-chan error
168170
t *testing.T
169171
}
170172

173+
func (w *ErrorWaiter) Cancel() {
174+
w.cancelFunc()
175+
}
176+
171177
func (w *ErrorWaiter) Wait() error {
172178
w.waitOnce.Do(func() {
173179
var ok bool
@@ -241,5 +247,5 @@ func StartWithWaiter(t *testing.T, inv *clibase.Invocation) *ErrorWaiter {
241247
cleaningUp.Store(true)
242248
<-doneCh
243249
})
244-
return &ErrorWaiter{c: errCh, t: t}
250+
return &ErrorWaiter{c: errCh, t: t, cancelFunc: cancel}
245251
}

cli/gitssh_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ func prepareTestGitSSH(ctx context.Context, t *testing.T) (*codersdk.Client, str
5858

5959
// start workspace agent
6060
inv, root := clitest.New(t, "agent", "--agent-token", agentToken, "--agent-url", client.URL.String())
61-
agentClient := client
61+
agentClient := codersdk.New(client.URL)
62+
agentClient.SetSessionToken(agentToken)
6263
clitest.SetupConfig(t, agentClient, root)
63-
6464
clitest.Start(t, inv)
6565

6666
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)

cli/server_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ func TestServer(t *testing.T) {
121121
)
122122

123123
const superDuperLong = testutil.WaitSuperLong * 3
124-
125124
ctx := testutil.Context(t, superDuperLong)
126125
clitest.Start(t, inv.WithContext(ctx))
127126

@@ -1430,6 +1429,7 @@ func TestServer(t *testing.T) {
14301429
wantConfig.Options[i].Name,
14311430
)
14321431
}
1432+
w.Cancel()
14331433
w.RequireSuccess()
14341434
})
14351435
})
@@ -1460,8 +1460,8 @@ func TestServer(t *testing.T) {
14601460
})
14611461
}
14621462

1463-
//nolint:tparallel,paralleltest // This test spawns or connects to an existing PostgreSQL instance.
14641463
func TestServer_Production(t *testing.T) {
1464+
t.Parallel()
14651465
if runtime.GOOS != "linux" || testing.Short() {
14661466
// Skip on non-Linux because it spawns a PostgreSQL instance.
14671467
t.SkipNow()
@@ -1471,7 +1471,8 @@ func TestServer_Production(t *testing.T) {
14711471
defer closeFunc()
14721472

14731473
// Postgres + race detector + CI = slow.
1474-
ctx := testutil.Context(t, testutil.WaitSuperLong*3)
1474+
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitSuperLong*3)
1475+
defer cancelFunc()
14751476

14761477
inv, cfg := clitest.New(t,
14771478
"server",

cli/vscodessh_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func TestVSCodeSSH(t *testing.T) {
6868
}
6969
return len(entries) > 0
7070
}, testutil.WaitLong, testutil.IntervalFast)
71+
waiter.Cancel()
7172

7273
if err := waiter.Wait(); err != nil {
7374
waiter.RequireIs(context.Canceled)

coderd/apidoc/docs.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)