Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[supervisor] Persist bash history across workspace restarts PRD-59 #17612

Merged
merged 3 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/supervisor/pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,9 @@ func buildChildProcEnv(cfg *Config, envvars []string, runGP bool) []string {
envs["JAVA_TOOL_OPTIONS"] += fmt.Sprintf(" -Xmx%sm", mem)
}

envs["HISTFILE"] = "/workspace/.gitpod/.bash_history"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe check if SHELL is not specified or bash?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not need, only bash respect this env

I try with zsh, it's just not work

Copy link
Member

@akosyakov akosyakov May 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe we just rename it to .shell_history? not sure

it seems zsh is using the same env var?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe we just rename it to .shell_history? not sure

ok

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check if this two env already exists?

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/.bash_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/.bash_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/.bash_history",
"PROMPT_COMMAND=history -a", "SUPERVISOR_ADDR=localhost:8080", "USER=gitpod"},
},
}

Expand Down