Skip to content

Commit 78ecbdd

Browse files
committed
Don't assume /home/gitpod
1 parent 37cb858 commit 78ecbdd

File tree

4 files changed

+50
-10
lines changed

4 files changed

+50
-10
lines changed

components/content-service/pkg/git/git.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ func (c *Client) GitWithOutput(ctx context.Context, ignoreErr *string, subcomman
183183
env = append(env, fmt.Sprintf("GIT_AUTH_PASSWORD=%s", pwd))
184184
}
185185

186-
env = append(env, "HOME=/home/gitpod")
187-
188186
fullArgs = append(fullArgs, subcommand)
189187
fullArgs = append(fullArgs, args...)
190188

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
package cmd
6+
7+
import (
8+
"fmt"
9+
10+
csapi "github.com/gitpod-io/gitpod/content-service/api"
11+
"github.com/gitpod-io/gitpod/content-service/pkg/executor"
12+
"github.com/spf13/cobra"
13+
)
14+
15+
var dumpInitializer = &cobra.Command{
16+
Use: "dump-init",
17+
Hidden: true, // this is not official user-facing functionality, but just for debugging
18+
Run: func(cmd *cobra.Command, args []string) {
19+
fc, _ := executor.Prepare(&csapi.WorkspaceInitializer{
20+
Spec: &csapi.WorkspaceInitializer_Git{
21+
Git: &csapi.GitInitializer{
22+
RemoteUri: "https://github.com/gitpod-io/gitpod",
23+
CheckoutLocation: "gitpod",
24+
TargetMode: csapi.CloneTargetMode_REMOTE_BRANCH,
25+
CloneTaget: "main",
26+
Config: &csapi.GitConfig{
27+
Authentication: csapi.GitAuthMethod_NO_AUTH,
28+
},
29+
},
30+
},
31+
}, nil)
32+
fmt.Println(string(fc))
33+
},
34+
}
35+
36+
func init() {
37+
rootCmd.AddCommand(dumpInitializer)
38+
}

components/supervisor/pkg/supervisor/services.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ func (is *InfoService) WorkspaceInfo(context.Context, *api.WorkspaceInfoRequest)
707707
}
708708
}
709709

710-
resp.UserHome = "/home/gitpod"
710+
resp.UserHome = os.Getenv("HOME")
711711

712712
endpoint, host, err := is.cfg.GitpodAPIEndpoint()
713713
if err != nil {
@@ -752,7 +752,7 @@ func (c *ControlService) ExposePort(ctx context.Context, req *api.ExposePortRequ
752752

753753
// CreateSSHKeyPair create a ssh key pair for the workspace.
754754
func (c *ControlService) CreateSSHKeyPair(ctx context.Context, req *api.CreateSSHKeyPairRequest) (response *api.CreateSSHKeyPairResponse, err error) {
755-
home := "/home/gitpod/"
755+
home := os.Getenv("HOME")
756756
if c.privateKey != "" && c.publicKey != "" {
757757
checkKey := func() error {
758758
data, err := os.ReadFile(filepath.Join(home, ".ssh/authorized_keys"))

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,23 +531,25 @@ func installDotfiles(ctx context.Context, cfg *Config, tokenService *InMemoryTok
531531
return
532532
}
533533

534-
const dotfilePath = "/home/gitpod/.dotfiles"
534+
home := os.Getenv("HOME")
535+
536+
dotfilePath := filepath.Join(home, ".dotfiles")
535537
if _, err := os.Stat(dotfilePath); err == nil {
536538
// dotfile path exists already - nothing to do here
537539
return
538540
}
539541

540542
prep := func(cfg *Config, out io.Writer, name string, args ...string) *exec.Cmd {
541543
cmd := exec.Command(name, args...)
542-
cmd.Dir = "/home/gitpod"
544+
cmd.Dir = home
543545
runAsUser(cmd, cfg.WorkspaceLinuxUID, cfg.WorkspaceLinuxGID)
544546
cmd.Stdout = out
545547
cmd.Stderr = out
546548
return cmd
547549
}
548550

549551
err := func() (err error) {
550-
out, err := os.OpenFile("/home/gitpod/.dotfiles.log", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
552+
out, err := os.OpenFile(dotfilePath+".log", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
551553
if err != nil {
552554
return err
553555
}
@@ -661,7 +663,7 @@ func installDotfiles(ctx context.Context, cfg *Config, tokenService *InMemoryTok
661663
return nil
662664
}
663665

664-
homeFN := filepath.Join("/home/gitpod", strings.TrimPrefix(path, dotfilePath))
666+
homeFN := filepath.Join(os.Getenv("HOME"), strings.TrimPrefix(path, dotfilePath))
665667
if _, err := os.Stat(homeFN); err == nil {
666668
// homeFN exists already - do nothing
667669
return nil
@@ -1028,8 +1030,10 @@ func buildChildProcEnv(cfg *Config, envvars []string, runGP bool) []string {
10281030
// - https://github.com/mirror/busybox/blob/24198f652f10dca5603df7c704263358ca21f5ce/libbb/setup_environment.c#L32
10291031
// - https://github.com/mirror/busybox/blob/24198f652f10dca5603df7c704263358ca21f5ce/libbb/login.c#L140-L170
10301032
//
1031-
envs["HOME"] = "/home/gitpod"
1032-
envs["USER"] = "gitpod"
1033+
if cfg.WorkspaceRuntime != WorkspaceRuntimeNextgen {
1034+
envs["HOME"] = "/home/gitpod"
1035+
envs["USER"] = "gitpod"
1036+
}
10331037

10341038
// Particular Java optimisation: Java pre v10 did not gauge it's available memory correctly, and needed explicitly setting "-Xmx" for all Hotspot/openJDK VMs
10351039
if mem, ok := envs["GITPOD_MEMORY"]; ok {

0 commit comments

Comments
 (0)