Skip to content

Commit 56db55f

Browse files
committed
[inner-loop] run Isolated docker in debug workspace
1 parent 8eb9d8c commit 56db55f

File tree

1 file changed

+50
-13
lines changed

1 file changed

+50
-13
lines changed

components/gitpod-cli/cmd/rebuild.go

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/gitpod-io/gitpod/common-go/log"
2121
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/supervisor"
2222
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/utils"
23+
"github.com/pkg/errors"
2324
"github.com/sirupsen/logrus"
2425
"github.com/spf13/cobra"
2526
"golang.org/x/xerrors"
@@ -241,10 +242,28 @@ func runRebuild(ctx context.Context, supervisorClient *supervisor.SupervisorClie
241242
return err
242243
}
243244

244-
// we don't pass context on purporse to handle graceful shutdown
245-
// and output all logs properly below
246-
runCmd := exec.Command(
247-
dockerPath,
245+
type mnte struct {
246+
IsFile bool
247+
Target string
248+
Source string
249+
Permission os.FileMode
250+
}
251+
252+
prepareFS := []mnte{
253+
{Source: "/workspace"},
254+
{Source: "/.supervisor"},
255+
{Source: "/ide"},
256+
{Source: "/workspace/.gitpod-debug/.docker-root", Target: "/workspace/.docker-root", Permission: 0710},
257+
{Source: "/workspace/.gitpod-debug/.gitpod", Target: "/workspace/.gitpod", Permission: 0751},
258+
{Source: "/workspace/.gitpod-debug/.vscode-remote", Target: "/workspace/.vscode-remote", Permission: 0751},
259+
{Source: "/workspace/.gitpod-debug/.cache", Target: "/workspace/.cache", Permission: 0751},
260+
{Source: "/workspace/.gitpod-debug/.config", Target: "/workspace/.config", Permission: 0751},
261+
{Source: "/usr/bin/docker-up", IsFile: true},
262+
{Source: "/usr/bin/runc-facade", IsFile: true},
263+
{Source: "/usr/local/bin/docker-compose", IsFile: true},
264+
}
265+
266+
dockerArgs := []string{
248267
"run",
249268
"--rm",
250269
"--user", "root",
@@ -258,17 +277,35 @@ func runRebuild(ctx context.Context, supervisorClient *supervisor.SupervisorClie
258277
"-p", "25001:23001", // SSH
259278
// 23002 dekstop IDE port, but it is covered by debug workspace proxy
260279
"-p", "25003:23003", // debug workspace proxy
280+
}
281+
282+
for _, mnt := range prepareFS {
283+
fd, err := os.Stat(mnt.Source)
284+
if err != nil {
285+
if !os.IsNotExist(err) {
286+
return err
287+
}
288+
if mnt.IsFile {
289+
return err
290+
}
291+
err = os.MkdirAll(mnt.Source, mnt.Permission)
292+
if err != nil {
293+
return err
294+
}
295+
}
296+
if fd.IsDir() != !mnt.IsFile {
297+
return errors.Errorf("invalid file type for %s", mnt.Source)
298+
}
299+
dockerArgs = append(dockerArgs, "-v", fmt.Sprintf("%s:%s", mnt.Source, mnt.Target))
300+
}
261301

262-
// volumes
263-
"-v", "/workspace:/workspace",
264-
"-v", "/.supervisor:/.supervisor",
265-
"-v", "/var/run/docker.sock:/var/run/docker.sock",
266-
"-v", "/ide:/ide",
267-
// "-v", "/ide-desktop:/ide-desktop", // TODO fix desktop IDEs later
268-
// "-v", "/ide-desktop-plugins:/ide-desktop-plugins", // TODO refactor to keep all IDE deps under ide or ide-desktop
302+
dockerArgs = append(dockerArgs, image, "/.supervisor/supervisor", "init")
269303

270-
image,
271-
"/.supervisor/supervisor", "init",
304+
// we don't pass context on purporse to handle graceful shutdown
305+
// and output all logs properly below
306+
runCmd := exec.Command(
307+
dockerPath,
308+
dockerArgs...,
272309
)
273310

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

0 commit comments

Comments
 (0)