Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bcca07a

Browse files
committed
Merge remote-tracking branch 'origin/main' into stevenmasley/template_update_params
2 parents 5f881aa + 3415b9d commit bcca07a

File tree

124 files changed

+4518
-1964
lines changed

Some content is hidden

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

124 files changed

+4518
-1964
lines changed

.github/workflows/coder.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ jobs:
209209
run: gotestsum --junitfile="gotests.xml" --packages="./..." --
210210
-covermode=atomic -coverprofile="gotests.coverage"
211211
-coverpkg=./...,github.com/coder/coder/codersdk
212-
-timeout=3m -count=$GOCOUNT -short -failfast
212+
-timeout=5m -count=$GOCOUNT -short -failfast
213213

214214
- name: Upload DataDog Trace
215215
if: always() && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
@@ -316,7 +316,7 @@ jobs:
316316
deploy:
317317
name: "deploy"
318318
runs-on: ubuntu-latest
319-
timeout-minutes: 20
319+
timeout-minutes: 30
320320
if: github.ref == 'refs/heads/main' && !github.event.pull_request.head.repo.fork
321321
permissions:
322322
contents: read

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ test: test-clean
115115
.PHONY: test-postgres
116116
test-postgres: test-clean
117117
DB=ci gotestsum --junitfile="gotests.xml" --packages="./..." -- \
118-
-covermode=atomic -coverprofile="gotests.coverage" -timeout=5m \
118+
-covermode=atomic -coverprofile="gotests.coverage" -timeout=30m \
119119
-coverpkg=./...,github.com/coder/coder/codersdk \
120-
-count=1 -parallel=1 -race -failfast
120+
-count=1 -race -failfast
121121

122122

123123
.PHONY: test-postgres-docker

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Visit our docs [here](https://coder.com/docs/coder-oss).
6565

6666
## Comparison
6767

68-
Please file [an issue](https://github.com/coder/coder/issues/new) if any information is out of date. Also refer to: [What Coder is not](https://coder.com/docs/coder-oss/latest/about#what-coder-is-not).
68+
Please file [an issue](https://github.com/coder/coder/issues/new) if any information is out of date. Also refer to: [What Coder is not](https://coder.com/docs/coder-oss/latest/index#what-coder-is-not).
6969

7070
| Tool | Type | Delivery Model | Cost | Environments |
7171
| :---------------------------------------------------------- | :------- | :----------------- | :---------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- |

agent/agent.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,11 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
328328
command := rawCommand
329329
if len(command) == 0 {
330330
command = shell
331+
if runtime.GOOS != "windows" {
332+
// On Linux and macOS, we should start a login
333+
// shell to consume juicy environment variables!
334+
command += " -l"
335+
}
331336
}
332337

333338
// OpenSSH executes all commands with the users current shell.
@@ -348,7 +353,6 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
348353
return nil, xerrors.Errorf("getting os executable: %w", err)
349354
}
350355
cmd.Env = append(cmd.Env, fmt.Sprintf("USER=%s", username))
351-
cmd.Env = append(cmd.Env, fmt.Sprintf(`PATH=%s%c%s`, os.Getenv("PATH"), filepath.ListSeparator, filepath.Dir(executablePath)))
352356
// Git on Windows resolves with UNIX-style paths.
353357
// If using backslashes, it's unable to find the executable.
354358
unixExecutablePath := strings.ReplaceAll(executablePath, "\\", "/")
@@ -363,7 +367,10 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
363367
// Load environment variables passed via the agent.
364368
// These should override all variables we manually specify.
365369
for key, value := range metadata.EnvironmentVariables {
366-
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", key, value))
370+
// Expanding environment variables allows for customization
371+
// of the $PATH, among other variables. Customers can prepand
372+
// or append to the $PATH, so allowing expand is required!
373+
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", key, os.ExpandEnv(value)))
367374
}
368375

369376
// Agent-level environment variables should take over all!

agent/agent_test.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,6 @@ func TestAgent(t *testing.T) {
6868
require.True(t, strings.HasSuffix(strings.TrimSpace(string(output)), "gitssh --"))
6969
})
7070

71-
t.Run("PATHHasCoder", func(t *testing.T) {
72-
t.Parallel()
73-
session := setupSSHSession(t, agent.Metadata{})
74-
command := "sh -c 'echo $PATH'"
75-
if runtime.GOOS == "windows" {
76-
command = "cmd.exe /c echo %PATH%"
77-
}
78-
output, err := session.Output(command)
79-
require.NoError(t, err)
80-
ex, err := os.Executable()
81-
t.Log(ex)
82-
require.NoError(t, err)
83-
require.True(t, strings.Contains(strings.TrimSpace(string(output)), filepath.Dir(ex)))
84-
})
85-
8671
t.Run("SessionTTY", func(t *testing.T) {
8772
t.Parallel()
8873
if runtime.GOOS == "windows" {
@@ -182,6 +167,28 @@ func TestAgent(t *testing.T) {
182167
require.Equal(t, value, strings.TrimSpace(string(output)))
183168
})
184169

170+
t.Run("EnvironmentVariableExpansion", func(t *testing.T) {
171+
t.Parallel()
172+
key := "EXAMPLE"
173+
session := setupSSHSession(t, agent.Metadata{
174+
EnvironmentVariables: map[string]string{
175+
key: "$SOMETHINGNOTSET",
176+
},
177+
})
178+
command := "sh -c 'echo $" + key + "'"
179+
if runtime.GOOS == "windows" {
180+
command = "cmd.exe /c echo %" + key + "%"
181+
}
182+
output, err := session.Output(command)
183+
require.NoError(t, err)
184+
expect := ""
185+
if runtime.GOOS == "windows" {
186+
expect = "%EXAMPLE%"
187+
}
188+
// Output should be empty, because the variable is not set!
189+
require.Equal(t, expect, strings.TrimSpace(string(output)))
190+
})
191+
185192
t.Run("StartupScript", func(t *testing.T) {
186193
t.Parallel()
187194
tempPath := filepath.Join(os.TempDir(), "content.txt")

cli/agent.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cli
22

33
import (
44
"context"
5+
"fmt"
56
"net/http"
67
_ "net/http/pprof" //nolint: gosec
78
"net/url"
@@ -138,6 +139,15 @@ func workspaceAgent() *cobra.Command {
138139
}
139140
}
140141

142+
executablePath, err := os.Executable()
143+
if err != nil {
144+
return xerrors.Errorf("getting os executable: %w", err)
145+
}
146+
err = os.Setenv("PATH", fmt.Sprintf("%s%c%s", os.Getenv("PATH"), filepath.ListSeparator, filepath.Dir(executablePath)))
147+
if err != nil {
148+
return xerrors.Errorf("add executable to $PATH: %w", err)
149+
}
150+
141151
closer := agent.New(client.ListenWorkspaceAgent, &agent.Options{
142152
Logger: logger,
143153
EnvironmentVariables: map[string]string{

cli/autostart.go

Lines changed: 0 additions & 244 deletions
This file was deleted.

0 commit comments

Comments
 (0)