Skip to content

Commit

Permalink
[supervisor] Persist bash history across workspace restarts PRD-59 (#…
Browse files Browse the repository at this point in the history
…17612)

* persistence command history

* fix test

* addressed feedback
  • Loading branch information
iQQBot authored May 15, 2023
1 parent eb9e41c commit 744eb49
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions components/supervisor/pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,11 @@ func buildChildProcEnv(cfg *Config, envvars []string, runGP bool) []string {
envs["JAVA_TOOL_OPTIONS"] += fmt.Sprintf(" -Xmx%sm", mem)
}

if _, ok := envs["HISTFILE"]; !ok {
envs["HISTFILE"] = "/workspace/.gitpod/.shell_history"
envs["PROMPT_COMMAND"] = "history -a"
}

var env, envn []string
for nme, val := range envs {
log.WithField("envvar", nme).Debug("passing environment variable to IDE")
Expand Down
20 changes: 12 additions & 8 deletions components/supervisor/pkg/supervisor/supervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func TestBuildChildProcEnv(t *testing.T) {
"SUPERVISOR_ADDR=localhost:8080",
"HOME=/home/gitpod",
"USER=gitpod",
"HISTFILE=/workspace/.gitpod/.shell_history",
"PROMPT_COMMAND=history -a",
)
}

Expand Down Expand Up @@ -85,16 +87,18 @@ func TestBuildChildProcEnv(t *testing.T) {
},
},
{
Name: "ots",
Input: []string{},
OTS: `[{"name":"foo","value":"bar"},{"name":"GITPOD_TOKENS","value":"foobar"}]`,
Expectation: []string{"HOME=/home/gitpod", "SUPERVISOR_ADDR=localhost:8080", "USER=gitpod", "foo=bar"},
Name: "ots",
Input: []string{},
OTS: `[{"name":"foo","value":"bar"},{"name":"GITPOD_TOKENS","value":"foobar"}]`,
Expectation: []string{"HOME=/home/gitpod", "HISTFILE=/workspace/.gitpod/.shell_history",
"PROMPT_COMMAND=history -a", "SUPERVISOR_ADDR=localhost:8080", "USER=gitpod", "foo=bar"},
},
{
Name: "failed ots",
Input: []string{},
OTS: `invalid json`,
Expectation: []string{"HOME=/home/gitpod", "SUPERVISOR_ADDR=localhost:8080", "USER=gitpod"},
Name: "failed ots",
Input: []string{},
OTS: `invalid json`,
Expectation: []string{"HOME=/home/gitpod", "HISTFILE=/workspace/.gitpod/.shell_history",
"PROMPT_COMMAND=history -a", "SUPERVISOR_ADDR=localhost:8080", "USER=gitpod"},
},
}

Expand Down

0 comments on commit 744eb49

Please sign in to comment.