Skip to content

Commit e689179

Browse files
committed
Merge branch 'main' of https://github.com/coder/coder into bq/notification-components
2 parents 0473e7b + 5285c12 commit e689179

File tree

429 files changed

+4259
-2222
lines changed

Some content is hidden

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

429 files changed

+4259
-2222
lines changed

.github/ISSUE_TEMPLATE/1-bug.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: "🐞 Bug"
22
description: "File a bug report."
3-
title: "<title>"
3+
title: "bug: "
44
labels: ["needs-triage"]
55
body:
66
- type: checkboxes

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ runs:
77
- name: Install Terraform
88
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
99
with:
10-
terraform_version: 1.10.5
10+
terraform_version: 1.11.0
1111
terraform_wrapper: false

.github/dependabot.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ updates:
3737
# Update our Dockerfile.
3838
- package-ecosystem: "docker"
3939
directories:
40-
- "/dogfood/contents"
40+
- "/dogfood/coder"
41+
- "/dogfood/coder-envbuilder"
4142
- "/scripts"
4243
- "/examples/templates/docker/build"
4344
- "/examples/parameters/build"

.github/workflows/ci.yaml

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

173173
- name: Get golangci-lint cache dir
174174
run: |
175-
linter_ver=$(egrep -o 'GOLANGCI_LINT_VERSION=\S+' dogfood/contents/Dockerfile | cut -d '=' -f 2)
175+
linter_ver=$(egrep -o 'GOLANGCI_LINT_VERSION=\S+' dogfood/coder/Dockerfile | cut -d '=' -f 2)
176176
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$linter_ver
177177
dir=$(golangci-lint cache status | awk '/Dir/ { print $2 }')
178178
echo "LINT_CACHE_DIR=$dir" >> $GITHUB_ENV

.github/workflows/dogfood.yaml

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

3737
- name: Setup Nix
38-
uses: DeterminateSystems/nix-installer-action@e50d5f73bfe71c2dd0aa4218de8f4afa59f8f81d # v16
38+
uses: nixbuild/nix-quick-install-action@5bb6a3b3abe66fd09bbf250dce8ada94f856a703 # v30
39+
40+
- uses: nix-community/cache-nix-action@aee88ae5efbbeb38ac5d9862ecbebdb404a19e69 # v6.1.1
41+
with:
42+
# restore and save a cache using this key
43+
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
44+
# if there's no cache hit, restore a cache by this prefix
45+
restore-prefixes-first-match: nix-${{ runner.os }}-
46+
# collect garbage until Nix store size (in bytes) is at most this number
47+
# before trying to save a new cache
48+
# 1G = 1073741824
49+
gc-max-store-size-linux: 5G
50+
# do purge caches
51+
purge: true
52+
# purge all versions of the cache
53+
purge-prefixes: nix-${{ runner.os }}-
54+
# created more than this number of seconds ago relative to the start of the `Post Restore` phase
55+
purge-created: 0
56+
# except the version with the `primary-key`, if it exists
57+
purge-primary-key: never
3958

4059
- name: Get branch name
4160
id: branch-name
@@ -68,7 +87,7 @@ jobs:
6887
project: b4q6ltmpzh
6988
token: ${{ secrets.DEPOT_TOKEN }}
7089
buildx-fallback: true
71-
context: "{{defaultContext}}:dogfood/contents"
90+
context: "{{defaultContext}}:dogfood/coder"
7291
pull: true
7392
save: true
7493
push: ${{ github.ref == 'refs/heads/main' }}
@@ -113,12 +132,18 @@ jobs:
113132

114133
- name: Terraform init and validate
115134
run: |
116-
cd dogfood
117-
terraform init -upgrade
135+
pushd dogfood/
136+
terraform init
137+
terraform validate
138+
popd
139+
pushd dogfood/coder
140+
terraform init
118141
terraform validate
119-
cd contents
120-
terraform init -upgrade
142+
popd
143+
pushd dogfood/coder-envbuilder
144+
terraform init
121145
terraform validate
146+
popd
122147
123148
- name: Get short commit SHA
124149
if: github.ref == 'refs/heads/main'
@@ -142,6 +167,6 @@ jobs:
142167
# Template source & details
143168
TF_VAR_CODER_TEMPLATE_NAME: ${{ secrets.CODER_TEMPLATE_NAME }}
144169
TF_VAR_CODER_TEMPLATE_VERSION: ${{ steps.vars.outputs.sha_short }}
145-
TF_VAR_CODER_TEMPLATE_DIR: ./contents
170+
TF_VAR_CODER_TEMPLATE_DIR: ./coder
146171
TF_VAR_CODER_TEMPLATE_MESSAGE: ${{ steps.message.outputs.pr_title }}
147172
TF_LOG: info

.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@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3.28.10
50+
uses: github/codeql-action/upload-sarif@6bb031afdd8eb862ea3fc1848194185e076637e5 # v3.28.11
5151
with:
5252
sarif_file: results.sarif

.github/workflows/security.yaml

Lines changed: 4 additions & 4 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@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3.28.10
41+
uses: github/codeql-action/init@6bb031afdd8eb862ea3fc1848194185e076637e5 # v3.28.11
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@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3.28.10
51+
uses: github/codeql-action/analyze@6bb031afdd8eb862ea3fc1848194185e076637e5 # v3.28.11
5252

5353
- name: Send Slack notification on failure
5454
if: ${{ failure() }}
@@ -99,7 +99,7 @@ jobs:
9999
# version in the comments will differ. This is also defined in
100100
# ci.yaml.
101101
set -euxo pipefail
102-
cd dogfood/contents
102+
cd dogfood/coder
103103
mkdir -p /usr/local/bin
104104
mkdir -p /usr/local/include
105105
@@ -144,7 +144,7 @@ jobs:
144144
severity: "CRITICAL,HIGH"
145145

146146
- name: Upload Trivy scan results to GitHub Security tab
147-
uses: github/codeql-action/upload-sarif@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3.28.10
147+
uses: github/codeql-action/upload-sarif@6bb031afdd8eb862ea3fc1848194185e076637e5 # v3.28.11
148148
with:
149149
sarif_file: trivy-results.sarif
150150
category: "Trivy"

.vscode/markdown.code-snippets

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
// For info about snippets, visit https://code.visualstudio.com/docs/editor/userdefinedsnippets
3+
// https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts
34

4-
"admonition": {
5-
"prefix": "#callout",
5+
"alert": {
6+
"prefix": "#alert",
67
"body": [
7-
"<blockquote class=\"admonition ${1|caution,important,note,tip,warning|}\">\n",
8-
"${TM_SELECTED_TEXT:${2:add info here}}\n",
9-
"</blockquote>\n"
8+
"> [!${1|CAUTION,IMPORTANT,NOTE,TIP,WARNING|}]",
9+
"> ${TM_SELECTED_TEXT:${2:add info here}}\n"
1010
],
11-
"description": "callout admonition caution info note tip warning"
11+
"description": "callout admonition caution important note tip warning"
1212
},
1313
"fenced code block": {
1414
"prefix": "#codeblock",
@@ -23,9 +23,8 @@
2323
"premium-feature": {
2424
"prefix": "#premium-feature",
2525
"body": [
26-
"<blockquote class=\"info\">\n",
27-
"${1:feature} ${2|is,are|} an Enterprise and Premium feature. [Learn more](https://coder.com/pricing#compare-plans).\n",
28-
"</blockquote>"
26+
"> [!NOTE]\n",
27+
"> ${1:feature} ${2|is,are|} an Enterprise and Premium feature. [Learn more](https://coder.com/pricing#compare-plans).\n"
2928
]
3029
},
3130
"tabs": {

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ lint/ts: site/node_modules/.installed
505505
lint/go:
506506
./scripts/check_enterprise_imports.sh
507507
./scripts/check_codersdk_imports.sh
508-
linter_ver=$(shell egrep -o 'GOLANGCI_LINT_VERSION=\S+' dogfood/contents/Dockerfile | cut -d '=' -f 2)
508+
linter_ver=$(shell egrep -o 'GOLANGCI_LINT_VERSION=\S+' dogfood/coder/Dockerfile | cut -d '=' -f 2)
509509
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v$$linter_ver run
510510
.PHONY: lint/go
511511

@@ -963,5 +963,5 @@ else
963963
endif
964964
.PHONY: test-e2e
965965

966-
dogfood/contents/nix.hash: flake.nix flake.lock
967-
sha256sum flake.nix flake.lock >./dogfood/contents/nix.hash
966+
dogfood/coder/nix.hash: flake.nix flake.lock
967+
sha256sum flake.nix flake.lock >./dogfood/coder/nix.hash

agent/agent_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import (
5151
"github.com/coder/coder/v2/agent/agentssh"
5252
"github.com/coder/coder/v2/agent/agenttest"
5353
"github.com/coder/coder/v2/agent/proto"
54+
"github.com/coder/coder/v2/agent/usershell"
5455
"github.com/coder/coder/v2/codersdk"
5556
"github.com/coder/coder/v2/codersdk/agentsdk"
5657
"github.com/coder/coder/v2/codersdk/workspacesdk"
@@ -1193,6 +1194,53 @@ func TestAgent_SSHConnectionEnvVars(t *testing.T) {
11931194
}
11941195
}
11951196

1197+
func TestAgent_SSHConnectionLoginVars(t *testing.T) {
1198+
t.Parallel()
1199+
1200+
envInfo := usershell.SystemEnvInfo{}
1201+
u, err := envInfo.User()
1202+
require.NoError(t, err, "get current user")
1203+
shell, err := envInfo.Shell(u.Username)
1204+
require.NoError(t, err, "get current shell")
1205+
1206+
tests := []struct {
1207+
key string
1208+
want string
1209+
}{
1210+
{
1211+
key: "USER",
1212+
want: u.Username,
1213+
},
1214+
{
1215+
key: "LOGNAME",
1216+
want: u.Username,
1217+
},
1218+
{
1219+
key: "HOME",
1220+
want: u.HomeDir,
1221+
},
1222+
{
1223+
key: "SHELL",
1224+
want: shell,
1225+
},
1226+
}
1227+
for _, tt := range tests {
1228+
tt := tt
1229+
t.Run(tt.key, func(t *testing.T) {
1230+
t.Parallel()
1231+
1232+
session := setupSSHSession(t, agentsdk.Manifest{}, codersdk.ServiceBannerConfig{}, nil)
1233+
command := "sh -c 'echo $" + tt.key + "'"
1234+
if runtime.GOOS == "windows" {
1235+
command = "cmd.exe /c echo %" + tt.key + "%"
1236+
}
1237+
output, err := session.Output(command)
1238+
require.NoError(t, err)
1239+
require.Equal(t, tt.want, strings.TrimSpace(string(output)))
1240+
})
1241+
}
1242+
}
1243+
11961244
func TestAgent_Metadata(t *testing.T) {
11971245
t.Parallel()
11981246

agent/agentcontainers/containers_dockercli.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,18 @@ func devcontainerEnv(ctx context.Context, execer agentexec.Execer, container str
182182
if !ok {
183183
return nil, nil
184184
}
185-
meta := struct {
186-
RemoteEnv map[string]string `json:"remoteEnv"`
187-
}{}
185+
186+
meta := make([]DevContainerMeta, 0)
188187
if err := json.Unmarshal([]byte(rawMeta), &meta); err != nil {
189188
return nil, xerrors.Errorf("unmarshal devcontainer.metadata: %w", err)
190189
}
191190

192191
// The environment variables are stored in the `remoteEnv` key.
193-
env := make([]string, 0, len(meta.RemoteEnv))
194-
for k, v := range meta.RemoteEnv {
195-
env = append(env, fmt.Sprintf("%s=%s", k, v))
192+
env := make([]string, 0)
193+
for _, m := range meta {
194+
for k, v := range m.RemoteEnv {
195+
env = append(env, fmt.Sprintf("%s=%s", k, v))
196+
}
196197
}
197198
slices.Sort(env)
198199
return env, nil

agent/agentcontainers/containers_internal_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestIntegrationDocker(t *testing.T) {
5353
Cmd: []string{"sleep", "infnity"},
5454
Labels: map[string]string{
5555
"com.coder.test": testLabelValue,
56-
"devcontainer.metadata": `{"remoteEnv": {"FOO": "bar", "MULTILINE": "foo\nbar\nbaz"}}`,
56+
"devcontainer.metadata": `[{"remoteEnv": {"FOO": "bar", "MULTILINE": "foo\nbar\nbaz"}}]`,
5757
},
5858
Mounts: []string{testTempDir + ":" + testTempDir},
5959
ExposedPorts: []string{fmt.Sprintf("%d/tcp", testRandPort)},
@@ -437,38 +437,46 @@ func TestDockerEnvInfoer(t *testing.T) {
437437
}{
438438
{
439439
image: "busybox:latest",
440-
labels: map[string]string{`devcontainer.metadata`: `{"remoteEnv": {"FOO": "bar", "MULTILINE": "foo\nbar\nbaz"}}`},
440+
labels: map[string]string{`devcontainer.metadata`: `[{"remoteEnv": {"FOO": "bar", "MULTILINE": "foo\nbar\nbaz"}}]`},
441441

442442
expectedEnv: []string{"FOO=bar", "MULTILINE=foo\nbar\nbaz"},
443443
expectedUsername: "root",
444444
expectedUserShell: "/bin/sh",
445445
},
446446
{
447447
image: "busybox:latest",
448-
labels: map[string]string{`devcontainer.metadata`: `{"remoteEnv": {"FOO": "bar", "MULTILINE": "foo\nbar\nbaz"}}`},
448+
labels: map[string]string{`devcontainer.metadata`: `[{"remoteEnv": {"FOO": "bar", "MULTILINE": "foo\nbar\nbaz"}}]`},
449449
expectedEnv: []string{"FOO=bar", "MULTILINE=foo\nbar\nbaz"},
450450
containerUser: "root",
451451
expectedUsername: "root",
452452
expectedUserShell: "/bin/sh",
453453
},
454454
{
455455
image: "codercom/enterprise-minimal:ubuntu",
456-
labels: map[string]string{`devcontainer.metadata`: `{"remoteEnv": {"FOO": "bar", "MULTILINE": "foo\nbar\nbaz"}}`},
456+
labels: map[string]string{`devcontainer.metadata`: `[{"remoteEnv": {"FOO": "bar", "MULTILINE": "foo\nbar\nbaz"}}]`},
457457
expectedEnv: []string{"FOO=bar", "MULTILINE=foo\nbar\nbaz"},
458458
expectedUsername: "coder",
459459
expectedUserShell: "/bin/bash",
460460
},
461461
{
462462
image: "codercom/enterprise-minimal:ubuntu",
463-
labels: map[string]string{`devcontainer.metadata`: `{"remoteEnv": {"FOO": "bar", "MULTILINE": "foo\nbar\nbaz"}}`},
463+
labels: map[string]string{`devcontainer.metadata`: `[{"remoteEnv": {"FOO": "bar", "MULTILINE": "foo\nbar\nbaz"}}]`},
464464
expectedEnv: []string{"FOO=bar", "MULTILINE=foo\nbar\nbaz"},
465465
containerUser: "coder",
466466
expectedUsername: "coder",
467467
expectedUserShell: "/bin/bash",
468468
},
469469
{
470470
image: "codercom/enterprise-minimal:ubuntu",
471-
labels: map[string]string{`devcontainer.metadata`: `{"remoteEnv": {"FOO": "bar", "MULTILINE": "foo\nbar\nbaz"}}`},
471+
labels: map[string]string{`devcontainer.metadata`: `[{"remoteEnv": {"FOO": "bar", "MULTILINE": "foo\nbar\nbaz"}}]`},
472+
expectedEnv: []string{"FOO=bar", "MULTILINE=foo\nbar\nbaz"},
473+
containerUser: "root",
474+
expectedUsername: "root",
475+
expectedUserShell: "/bin/bash",
476+
},
477+
{
478+
image: "codercom/enterprise-minimal:ubuntu",
479+
labels: map[string]string{`devcontainer.metadata`: `[{"remoteEnv": {"FOO": "bar"}},{"remoteEnv": {"MULTILINE": "foo\nbar\nbaz"}}]`},
472480
expectedEnv: []string{"FOO=bar", "MULTILINE=foo\nbar\nbaz"},
473481
containerUser: "root",
474482
expectedUsername: "root",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package agentcontainers
2+
3+
type DevContainerMeta struct {
4+
RemoteEnv map[string]string `json:"remoteEnv,omitempty"`
5+
}

agent/agentssh/agentssh.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,10 @@ func (s *Server) CreateCommand(ctx context.Context, script string, env []string,
900900
cmd.Dir = homedir
901901
}
902902
cmd.Env = append(ei.Environ(), env...)
903+
// Set login variables (see `man login`).
903904
cmd.Env = append(cmd.Env, fmt.Sprintf("USER=%s", username))
905+
cmd.Env = append(cmd.Env, fmt.Sprintf("LOGNAME=%s", username))
906+
cmd.Env = append(cmd.Env, fmt.Sprintf("SHELL=%s", shell))
904907

905908
// Set SSH connection environment variables (these are also set by OpenSSH
906909
// and thus expected to be present by SSH clients). Since the agent does

agent/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (a *agent) apiHandler() http.Handler {
4141
r.Get("/api/v0/containers", ch.ServeHTTP)
4242
r.Get("/api/v0/listening-ports", lp.handler)
4343
r.Get("/api/v0/netcheck", a.HandleNetcheck)
44+
r.Post("/api/v0/list-directory", a.HandleLS)
4445
r.Get("/debug/logs", a.HandleHTTPDebugLogs)
4546
r.Get("/debug/magicsock", a.HandleHTTPDebugMagicsock)
4647
r.Get("/debug/magicsock/debug-logging/{state}", a.HandleHTTPMagicsockDebugLoggingState)

0 commit comments

Comments
 (0)