Skip to content

Commit 4baee6f

Browse files
committed
[inner-loop] run Isolated docker in debug workspace
1 parent c98dde3 commit 4baee6f

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

components/docker-up/docker-up/main.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ var opts struct {
4646
UserAccessibleSocket bool
4747
Verbose bool
4848
DontWrapNetNS bool
49+
ContainerIf string
50+
DataRoot string
4951
}
5052

5153
//go:embed docker.tgz
@@ -59,7 +61,6 @@ var aptUpdated = false
5961
const (
6062
dockerSocketFN = "/var/run/docker.sock"
6163
gitpodUserId = 33333
62-
containerIf = "ceth0"
6364
)
6465

6566
func main() {
@@ -71,6 +72,8 @@ func main() {
7172
pflag.BoolVarP(&opts.Verbose, "verbose", "v", false, "enables verbose logging")
7273
pflag.BoolVar(&opts.RuncFacade, "runc-facade", true, "enables the runc-facade to handle rootless idiosyncrasies")
7374
pflag.StringVar(&opts.BinDir, "bin-dir", filepath.Dir(self), "directory where runc-facade is found")
75+
pflag.StringVar(&opts.ContainerIf, "iface", "ceth0", "container iface name")
76+
pflag.StringVar(&opts.ContainerIf, "data-root", "/workspace/.docker-root", "dockerd data root folder")
7477
pflag.BoolVar(&opts.AutoInstall, "auto-install", true, "auto-install prerequisites (docker)")
7578
pflag.BoolVar(&opts.UserAccessibleSocket, "user-accessible-socket", true, "chmod the Docker socket to make it user accessible")
7679
pflag.BoolVar(&opts.DontWrapNetNS, "dont-wrap-netns", os.Getenv("WORKSPACEKIT_WRAP_NETNS") == "true", "wrap the Docker daemon in a network namespace")
@@ -103,7 +106,7 @@ func runWithinNetns() (err error) {
103106
listenFDs, _ := strconv.Atoi(os.Getenv("LISTEN_FDS"))
104107

105108
args := []string{
106-
"--data-root=/workspace/.docker-root",
109+
"--data-root=" + opts.DataRoot,
107110
}
108111

109112
unified, err := cgroups.IsUnifiedCgroupSetup()
@@ -136,9 +139,9 @@ func runWithinNetns() (err error) {
136139
}
137140
args = append(args, userArgs...)
138141

139-
netIface, err := netlink.LinkByName(containerIf)
142+
netIface, err := netlink.LinkByName(opts.ContainerIf)
140143
if err != nil {
141-
return xerrors.Errorf("cannot get container network device %s: %w", containerIf, err)
144+
return xerrors.Errorf("cannot get container network device %s: %w", opts.ContainerIf, err)
142145
}
143146

144147
args = append(args, fmt.Sprintf("--mtu=%v", netIface.Attrs().MTU))

components/gitpod-cli/cmd/rebuild.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,10 @@ func runRebuild(ctx context.Context, supervisorClient *supervisor.SupervisorClie
262262
// volumes
263263
"-v", "/workspace:/workspace",
264264
"-v", "/.supervisor:/.supervisor",
265-
"-v", "/var/run/docker.sock:/var/run/docker.sock",
266265
"-v", "/ide:/ide",
266+
"-v", "/usr/bin/docker-up:/usr/bin/docker-up",
267+
"-v", "/usr/bin/runc-facade:/usr/bin/runc-facade",
268+
"-v", "/usr/local/bin/docker-compose:/usr/local/bin/docker-compose",
267269
// "-v", "/ide-desktop:/ide-desktop", // TODO fix desktop IDEs later
268270
// "-v", "/ide-desktop-plugins:/ide-desktop-plugins", // TODO refactor to keep all IDE deps under ide or ide-desktop
269271

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ func Run(options ...RunOption) {
398398
tasksSuccessChan := make(chan taskSuccess, 1)
399399
go taskManager.Run(ctx, &wg, tasksSuccessChan)
400400

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

406406
if cfg.isHeadless() {
@@ -1499,7 +1499,7 @@ func recordInitializerMetrics(path string, metrics *metrics.SupervisorMetrics) {
14991499
}
15001500
}
15011501

1502-
func socketActivationForDocker(ctx context.Context, wg *sync.WaitGroup, term *terminal.Mux) {
1502+
func socketActivationForDocker(ctx context.Context, wg *sync.WaitGroup, term *terminal.Mux, isDebugWorkspace bool) {
15031503
defer wg.Done()
15041504

15051505
fn := "/var/run/docker.sock"
@@ -1521,6 +1521,10 @@ func socketActivationForDocker(ctx context.Context, wg *sync.WaitGroup, term *te
15211521
cmd := exec.Command("/usr/bin/docker-up")
15221522
cmd.Env = append(os.Environ(), "LISTEN_FDS=1")
15231523
cmd.ExtraFiles = []*os.File{socketFD}
1524+
if isDebugWorkspace {
1525+
cmd.Args = append(cmd.Args, "--iface", "eth0")
1526+
cmd.Args = append(cmd.Args, "--data-root", "/workspace/.docker-root-debug")
1527+
}
15241528
alias, err := term.Start(cmd, terminal.TermOptions{
15251529
Annotations: map[string]string{
15261530
"gitpod.supervisor": "true",

0 commit comments

Comments
 (0)