Skip to content

Commit 884a177

Browse files
authored
[inner-loop] run Isolated docker in debug workspace (#16363)
1 parent 329e565 commit 884a177

File tree

2 files changed

+57
-14
lines changed

2 files changed

+57
-14
lines changed

components/gitpod-cli/cmd/rebuild.go

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,28 @@ func runRebuild(ctx context.Context, supervisorClient *supervisor.SupervisorClie
251251
return err
252252
}
253253

254-
// we don't pass context on purporse to handle graceful shutdown
255-
// and output all logs properly below
256-
runCmd := exec.Command(
257-
dockerPath,
254+
type mnte struct {
255+
IsFile bool
256+
Target string
257+
Source string
258+
Permission os.FileMode
259+
}
260+
261+
prepareFS := []mnte{
262+
{Source: "/workspace"},
263+
{Source: "/.supervisor"},
264+
{Source: "/ide"},
265+
{Source: "/workspace/.gitpod-debug/.docker-root", Target: "/workspace/.docker-root", Permission: 0710},
266+
{Source: "/workspace/.gitpod-debug/.gitpod", Target: "/workspace/.gitpod", Permission: 0751},
267+
{Source: "/workspace/.gitpod-debug/.vscode-remote", Target: "/workspace/.vscode-remote", Permission: 0751},
268+
{Source: "/workspace/.gitpod-debug/.cache", Target: "/workspace/.cache", Permission: 0751},
269+
{Source: "/workspace/.gitpod-debug/.config", Target: "/workspace/.config", Permission: 0751},
270+
{Source: "/usr/bin/docker-up", IsFile: true},
271+
{Source: "/usr/bin/runc-facade", IsFile: true},
272+
{Source: "/usr/local/bin/docker-compose", IsFile: true},
273+
}
274+
275+
dockerArgs := []string{
258276
"run",
259277
"--rm",
260278
"--user", "root",
@@ -268,17 +286,42 @@ func runRebuild(ctx context.Context, supervisorClient *supervisor.SupervisorClie
268286
"-p", "25001:23001", // SSH
269287
// 23002 dekstop IDE port, but it is covered by debug workspace proxy
270288
"-p", "25003:23003", // debug workspace proxy
289+
}
271290

272-
// volumes
273-
"-v", "/workspace:/workspace",
274-
"-v", "/.supervisor:/.supervisor",
275-
"-v", "/var/run/docker.sock:/var/run/docker.sock",
276-
"-v", "/ide:/ide",
277-
// "-v", "/ide-desktop:/ide-desktop", // TODO fix desktop IDEs later
278-
// "-v", "/ide-desktop-plugins:/ide-desktop-plugins", // TODO refactor to keep all IDE deps under ide or ide-desktop
291+
for _, mnt := range prepareFS {
292+
fd, err := os.Stat(mnt.Source)
293+
if err != nil {
294+
if !os.IsNotExist(err) {
295+
return err
296+
}
297+
if mnt.IsFile {
298+
return err
299+
}
300+
err = os.MkdirAll(mnt.Source, mnt.Permission)
301+
if err != nil {
302+
return err
303+
}
304+
fd, err = os.Stat(mnt.Source)
305+
if err != nil {
306+
return err
307+
}
308+
}
309+
if fd.IsDir() != !mnt.IsFile {
310+
return xerrors.Errorf("invalid file type for %s", mnt.Source)
311+
}
312+
if mnt.Target == "" {
313+
mnt.Target = mnt.Source
314+
}
315+
dockerArgs = append(dockerArgs, "-v", fmt.Sprintf("%s:%s", mnt.Source, mnt.Target))
316+
}
279317

280-
image,
281-
"/.supervisor/supervisor", "init",
318+
dockerArgs = append(dockerArgs, image, "/.supervisor/supervisor", "init")
319+
320+
// we don't pass context on purporse to handle graceful shutdown
321+
// and output all logs properly below
322+
runCmd := exec.Command(
323+
dockerPath,
324+
dockerArgs...,
282325
)
283326

284327
debugSupervisor, err := supervisor.New(ctx, &supervisor.SupervisorClientOption{

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func Run(options ...RunOption) {
400400
tasksSuccessChan := make(chan taskSuccess, 1)
401401
go taskManager.Run(ctx, &wg, tasksSuccessChan)
402402

403-
if !opts.RunGP && !cfg.isDebugWorkspace() {
403+
if !opts.RunGP {
404404
wg.Add(1)
405405
go socketActivationForDocker(ctx, &wg, termMux, cfg, telemetry)
406406
}

0 commit comments

Comments
 (0)