Skip to content

Commit 072f2c8

Browse files
iQQBotroboquat
authored andcommitted
Add private dotfiles repo support
1 parent 913d963 commit 072f2c8

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"io/ioutil"
1818
"net"
1919
"net/http"
20+
"net/url"
2021
"os"
2122
"os/exec"
2223
"os/signal"
@@ -46,6 +47,7 @@ import (
4647
"github.com/gitpod-io/gitpod/common-go/process"
4748
csapi "github.com/gitpod-io/gitpod/content-service/api"
4849
"github.com/gitpod-io/gitpod/content-service/pkg/executor"
50+
"github.com/gitpod-io/gitpod/content-service/pkg/git"
4951
"github.com/gitpod-io/gitpod/content-service/pkg/initializer"
5052
gitpod "github.com/gitpod-io/gitpod/gitpod-protocol"
5153
"github.com/gitpod-io/gitpod/supervisor/api"
@@ -283,7 +285,7 @@ func Run(options ...RunOption) {
283285

284286
// We need to checkout dotfiles first, because they may be changing the path which affects the IDE.
285287
// TODO(cw): provide better feedback if the IDE start fails because of the dotfiles (provide any feedback at all).
286-
installDotfiles(ctx, termMuxSrv, cfg)
288+
installDotfiles(ctx, cfg, tokenService)
287289
}
288290

289291
var ideWG sync.WaitGroup
@@ -370,7 +372,7 @@ func Run(options ...RunOption) {
370372
wg.Wait()
371373
}
372374

373-
func installDotfiles(ctx context.Context, term *terminal.MuxTerminalService, cfg *Config) {
375+
func installDotfiles(ctx context.Context, cfg *Config, tokenService *InMemoryTokenService) {
374376
repo := cfg.DotfileRepo
375377
if repo == "" {
376378
return
@@ -414,12 +416,36 @@ func installDotfiles(ctx context.Context, term *terminal.MuxTerminalService, cfg
414416

415417
done := make(chan error, 1)
416418
go func() {
417-
done <- prep(cfg, out, "git", "clone", "--depth=1", repo, "/home/gitpod/.dotfiles").Run()
419+
repoUrl, err := url.Parse(repo)
420+
if err != nil {
421+
done <- err
422+
close(done)
423+
return
424+
}
425+
authProvider := func() (username string, password string, err error) {
426+
resp, err := tokenService.GetToken(ctx, &api.GetTokenRequest{
427+
Host: repoUrl.Host,
428+
Kind: KindGit,
429+
})
430+
if err != nil {
431+
return
432+
}
433+
username = resp.User
434+
password = resp.Token
435+
return
436+
}
437+
client := &git.Client{
438+
AuthProvider: authProvider,
439+
AuthMethod: git.BasicAuth,
440+
Location: "/home/gitpod/.dotfiles",
441+
RemoteURI: repo,
442+
}
443+
done <- client.Clone(ctx)
418444
close(done)
419445
}()
420446
select {
421447
case err := <-done:
422-
if err != nil {
448+
if err != nil && !process.IsNotChildProcess(err) {
423449
return err
424450
}
425451
case <-time.After(120 * time.Second):
@@ -469,7 +495,9 @@ func installDotfiles(ctx context.Context, term *terminal.MuxTerminalService, cfg
469495

470496
select {
471497
case err = <-done:
472-
return err
498+
if err != nil && !process.IsNotChildProcess(err) {
499+
return err
500+
}
473501
case <-time.After(120 * time.Second):
474502
cmd.Process.Kill()
475503
return xerrors.Errorf("installation process %s tool longer than 120 seconds", fn)

0 commit comments

Comments
 (0)