Skip to content

Commit ddaf987

Browse files
Merge remote-tracking branch 'origin/main' into yevhenii/throttle-prebuild-notifications
2 parents 362911e + 5ed0c7a commit ddaf987

File tree

340 files changed

+5431
-1898
lines changed

Some content is hidden

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

340 files changed

+5431
-1898
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ jobs:
902902
# the check to pass. This is desired in PRs, but not in mainline.
903903
- name: Publish to Chromatic (non-mainline)
904904
if: github.ref != 'refs/heads/main' && github.repository_owner == 'coder'
905-
uses: chromaui/action@c50adf8eaa8c2878af3263499a73077854de39d4 # v12.2.0
905+
uses: chromaui/action@b5848056bb67ce5f1cccca8e62a37cbd9dd42871 # v13.0.1
906906
env:
907907
NODE_OPTIONS: "--max_old_space_size=4096"
908908
STORYBOOK: true
@@ -934,7 +934,7 @@ jobs:
934934
# infinitely "in progress" in mainline unless we re-review each build.
935935
- name: Publish to Chromatic (mainline)
936936
if: github.ref == 'refs/heads/main' && github.repository_owner == 'coder'
937-
uses: chromaui/action@c50adf8eaa8c2878af3263499a73077854de39d4 # v12.2.0
937+
uses: chromaui/action@b5848056bb67ce5f1cccca8e62a37cbd9dd42871 # v13.0.1
938938
env:
939939
NODE_OPTIONS: "--max_old_space_size=4096"
940940
STORYBOOK: true

.github/workflows/docker-base.yaml

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

6161
# This uses OIDC authentication, so no auth variables are required.
6262
- name: Build base Docker image via depot.dev
63-
uses: depot/build-push-action@636daae76684e38c301daa0c5eca1c095b24e780 # v1.14.0
63+
uses: depot/build-push-action@2583627a84956d07561420dcc1d0eb1f2af3fac0 # v1.15.0
6464
with:
6565
project: wl5hnrrkns
6666
context: base-build-context

.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@d52d20fa3f981cb852b861fd8f55308b5fe29637 # v45.0.7
31+
- uses: tj-actions/changed-files@666c9d29007687c52e3c7aa2aac6c0ffcadeadc3 # v45.0.7
3232
id: changed-files
3333
with:
3434
files: |

.github/workflows/dogfood.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3636

3737
- name: Setup Nix
38-
uses: nixbuild/nix-quick-install-action@5bb6a3b3abe66fd09bbf250dce8ada94f856a703 # v30
38+
uses: nixbuild/nix-quick-install-action@889f3180bb5f064ee9e3201428d04ae9e41d54ad # v31
3939

4040
- uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3
4141
with:
@@ -72,7 +72,7 @@ jobs:
7272
uses: depot/setup-action@b0b1ea4f69e92ebf5dea3f8713a1b0c37b2126a5 # v1.6.0
7373

7474
- name: Set up Docker Buildx
75-
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
75+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
7676

7777
- name: Login to DockerHub
7878
if: github.ref == 'refs/heads/main'
@@ -82,7 +82,7 @@ jobs:
8282
password: ${{ secrets.DOCKERHUB_PASSWORD }}
8383

8484
- name: Build and push Non-Nix image
85-
uses: depot/build-push-action@636daae76684e38c301daa0c5eca1c095b24e780 # v1.14.0
85+
uses: depot/build-push-action@2583627a84956d07561420dcc1d0eb1f2af3fac0 # v1.15.0
8686
with:
8787
project: b4q6ltmpzh
8888
token: ${{ secrets.DEPOT_TOKEN }}

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ jobs:
364364
# This uses OIDC authentication, so no auth variables are required.
365365
- name: Build base Docker image via depot.dev
366366
if: steps.image-base-tag.outputs.tag != ''
367-
uses: depot/build-push-action@636daae76684e38c301daa0c5eca1c095b24e780 # v1.14.0
367+
uses: depot/build-push-action@2583627a84956d07561420dcc1d0eb1f2af3fac0 # v1.15.0
368368
with:
369369
project: wl5hnrrkns
370370
context: base-build-context

agent/agent_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ func TestAgent_Stats_SSH(t *testing.T) {
130130
t.Parallel()
131131

132132
for _, port := range sshPorts {
133-
port := port
134133
t.Run(fmt.Sprintf("(:%d)", port), func(t *testing.T) {
135134
t.Parallel()
136135

@@ -342,7 +341,6 @@ func TestAgent_SessionExec(t *testing.T) {
342341
t.Parallel()
343342

344343
for _, port := range sshPorts {
345-
port := port
346344
t.Run(fmt.Sprintf("(:%d)", port), func(t *testing.T) {
347345
t.Parallel()
348346

@@ -468,7 +466,6 @@ func TestAgent_SessionTTYShell(t *testing.T) {
468466
}
469467

470468
for _, port := range sshPorts {
471-
port := port
472469
t.Run(fmt.Sprintf("(%d)", port), func(t *testing.T) {
473470
t.Parallel()
474471

@@ -611,7 +608,6 @@ func TestAgent_Session_TTY_MOTD(t *testing.T) {
611608
}
612609

613610
for _, test := range tests {
614-
test := test
615611
t.Run(test.name, func(t *testing.T) {
616612
t.Parallel()
617613
session := setupSSHSession(t, test.manifest, test.banner, func(fs afero.Fs) {
@@ -688,16 +684,13 @@ func TestAgent_Session_TTY_MOTD_Update(t *testing.T) {
688684

689685
//nolint:paralleltest // These tests need to swap the banner func.
690686
for _, port := range sshPorts {
691-
port := port
692-
693687
sshClient, err := conn.SSHClientOnPort(ctx, port)
694688
require.NoError(t, err)
695689
t.Cleanup(func() {
696690
_ = sshClient.Close()
697691
})
698692

699693
for i, test := range tests {
700-
test := test
701694
t.Run(fmt.Sprintf("(:%d)/%d", port, i), func(t *testing.T) {
702695
// Set new banner func and wait for the agent to call it to update the
703696
// banner.
@@ -1210,7 +1203,6 @@ func TestAgent_CoderEnvVars(t *testing.T) {
12101203
t.Parallel()
12111204

12121205
for _, key := range []string{"CODER", "CODER_WORKSPACE_NAME", "CODER_WORKSPACE_OWNER_NAME", "CODER_WORKSPACE_AGENT_NAME"} {
1213-
key := key
12141206
t.Run(key, func(t *testing.T) {
12151207
t.Parallel()
12161208

@@ -1233,7 +1225,6 @@ func TestAgent_SSHConnectionEnvVars(t *testing.T) {
12331225
// For some reason this test produces a TTY locally and a non-TTY in CI
12341226
// so we don't test for the absence of SSH_TTY.
12351227
for _, key := range []string{"SSH_CONNECTION", "SSH_CLIENT"} {
1236-
key := key
12371228
t.Run(key, func(t *testing.T) {
12381229
t.Parallel()
12391230

@@ -1276,7 +1267,6 @@ func TestAgent_SSHConnectionLoginVars(t *testing.T) {
12761267
},
12771268
}
12781269
for _, tt := range tests {
1279-
tt := tt
12801270
t.Run(tt.key, func(t *testing.T) {
12811271
t.Parallel()
12821272

@@ -1796,7 +1786,6 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
17961786
t.Setenv("LANG", "C")
17971787

17981788
for _, backendType := range backends {
1799-
backendType := backendType
18001789
t.Run(backendType, func(t *testing.T) {
18011790
if backendType == "Screen" {
18021791
if runtime.GOOS != "linux" {
@@ -2496,7 +2485,6 @@ func TestAgent_Dial(t *testing.T) {
24962485
}
24972486

24982487
for _, c := range cases {
2499-
c := c
25002488
t.Run(c.name, func(t *testing.T) {
25012489
t.Parallel()
25022490

agent/agentcontainers/api.go

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"path"
1010
"path/filepath"
11+
"regexp"
1112
"runtime"
1213
"slices"
1314
"strings"
@@ -39,6 +40,8 @@ const (
3940
// by tmpfs or other mounts. This assumes the container root filesystem is
4041
// read-write, which seems sensible for devcontainers.
4142
coderPathInsideContainer = "/.coder-agent/coder"
43+
44+
maxAgentNameLength = 64
4245
)
4346

4447
// API is responsible for container-related operations in the agent.
@@ -583,10 +586,11 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
583586
if dc.Container != nil {
584587
if !api.devcontainerNames[dc.Name] {
585588
// If the devcontainer name wasn't set via terraform, we
586-
// use the containers friendly name as a fallback which
587-
// will keep changing as the devcontainer is recreated.
588-
// TODO(mafredri): Parse the container label (i.e. devcontainer.json) for customization.
589-
dc.Name = safeFriendlyName(dc.Container.FriendlyName)
589+
// will attempt to create an agent name based on the workspace
590+
// folder's name. If it is not possible to generate a valid
591+
// agent name based off of the folder name (i.e. no valid characters),
592+
// we will instead fall back to using the container's friendly name.
593+
dc.Name = safeAgentName(path.Base(filepath.ToSlash(dc.WorkspaceFolder)), dc.Container.FriendlyName)
590594
}
591595
}
592596

@@ -631,6 +635,38 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
631635
api.containersErr = nil
632636
}
633637

638+
var consecutiveHyphenRegex = regexp.MustCompile("-+")
639+
640+
// `safeAgentName` returns a safe agent name derived from a folder name,
641+
// falling back to the container’s friendly name if needed.
642+
func safeAgentName(name string, friendlyName string) string {
643+
// Keep only ASCII letters and digits, replacing everything
644+
// else with a hyphen.
645+
var sb strings.Builder
646+
for _, r := range strings.ToLower(name) {
647+
if (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') {
648+
_, _ = sb.WriteRune(r)
649+
} else {
650+
_, _ = sb.WriteRune('-')
651+
}
652+
}
653+
654+
// Remove any consecutive hyphens, and then trim any leading
655+
// and trailing hyphens.
656+
name = consecutiveHyphenRegex.ReplaceAllString(sb.String(), "-")
657+
name = strings.Trim(name, "-")
658+
659+
// Ensure the name of the agent doesn't exceed the maximum agent
660+
// name length.
661+
name = name[:min(len(name), maxAgentNameLength)]
662+
663+
if provisioner.AgentNameRegex.Match([]byte(name)) {
664+
return name
665+
}
666+
667+
return safeFriendlyName(friendlyName)
668+
}
669+
634670
// safeFriendlyName returns a API safe version of the container's
635671
// friendly name.
636672
//

0 commit comments

Comments
 (0)