Skip to content

[inner-loop] run Isolated docker in debug workspace #16363

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

Merged
merged 1 commit into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
69 changes: 56 additions & 13 deletions components/gitpod-cli/cmd/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,28 @@ func runRebuild(ctx context.Context, supervisorClient *supervisor.SupervisorClie
return err
}

// we don't pass context on purporse to handle graceful shutdown
// and output all logs properly below
runCmd := exec.Command(
dockerPath,
type mnte struct {
IsFile bool
Target string
Source string
Permission os.FileMode
}

prepareFS := []mnte{
{Source: "/workspace"},
{Source: "/.supervisor"},
{Source: "/ide"},
{Source: "/workspace/.gitpod-debug/.docker-root", Target: "/workspace/.docker-root", Permission: 0710},
{Source: "/workspace/.gitpod-debug/.gitpod", Target: "/workspace/.gitpod", Permission: 0751},
{Source: "/workspace/.gitpod-debug/.vscode-remote", Target: "/workspace/.vscode-remote", Permission: 0751},
{Source: "/workspace/.gitpod-debug/.cache", Target: "/workspace/.cache", Permission: 0751},
{Source: "/workspace/.gitpod-debug/.config", Target: "/workspace/.config", Permission: 0751},
{Source: "/usr/bin/docker-up", IsFile: true},
{Source: "/usr/bin/runc-facade", IsFile: true},
{Source: "/usr/local/bin/docker-compose", IsFile: true},
}

dockerArgs := []string{
"run",
"--rm",
"--user", "root",
Expand All @@ -258,17 +276,42 @@ func runRebuild(ctx context.Context, supervisorClient *supervisor.SupervisorClie
"-p", "25001:23001", // SSH
// 23002 dekstop IDE port, but it is covered by debug workspace proxy
"-p", "25003:23003", // debug workspace proxy
}

// volumes
"-v", "/workspace:/workspace",
"-v", "/.supervisor:/.supervisor",
"-v", "/var/run/docker.sock:/var/run/docker.sock",
"-v", "/ide:/ide",
// "-v", "/ide-desktop:/ide-desktop", // TODO fix desktop IDEs later
// "-v", "/ide-desktop-plugins:/ide-desktop-plugins", // TODO refactor to keep all IDE deps under ide or ide-desktop
for _, mnt := range prepareFS {
fd, err := os.Stat(mnt.Source)
if err != nil {
if !os.IsNotExist(err) {
return err
}
if mnt.IsFile {
return err
}
err = os.MkdirAll(mnt.Source, mnt.Permission)
if err != nil {
return err
}
fd, err = os.Stat(mnt.Source)
if err != nil {
return err
}
}
if fd.IsDir() != !mnt.IsFile {
return xerrors.Errorf("invalid file type for %s", mnt.Source)
}
if mnt.Target == "" {
mnt.Target = mnt.Source
}
dockerArgs = append(dockerArgs, "-v", fmt.Sprintf("%s:%s", mnt.Source, mnt.Target))
}

dockerArgs = append(dockerArgs, image, "/.supervisor/supervisor", "init")

image,
"/.supervisor/supervisor", "init",
// we don't pass context on purporse to handle graceful shutdown
// and output all logs properly below
runCmd := exec.Command(
dockerPath,
dockerArgs...,
)

debugSupervisor, err := supervisor.New(ctx, &supervisor.SupervisorClientOption{
Expand Down
2 changes: 1 addition & 1 deletion components/supervisor/pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func Run(options ...RunOption) {
tasksSuccessChan := make(chan taskSuccess, 1)
go taskManager.Run(ctx, &wg, tasksSuccessChan)

if !opts.RunGP && !cfg.isDebugWorkspace() {
if !opts.RunGP {
Copy link
Member

Choose a reason for hiding this comment

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

in this file we only need to remove a guard

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will change after #16368 merged

wg.Add(1)
go socketActivationForDocker(ctx, &wg, termMux, cfg, telemetry)
}
Expand Down