Skip to content

Commit 1145285

Browse files
committed
fix: Create no longer drops appPorts. Exec ignores -f if a running container is found.
1 parent 2c0fecc commit 1145285

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

‎pkg/commands/create.go‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,17 @@ func generateDevcontainerConfig(p interact.Printer, baseConfigPath, featureRef s
419419
}
420420
cfg.SetFeature(featureRef, featureOpts)
421421
interceptAddr := fmt.Sprintf(":%d", interceptPort)
422-
cfg.AppPort = devcontainer.PortMappings{
423-
{HostPort: appPort, ContainerPort: appPort},
424-
{HostPort: interceptPort, ContainerPort: interceptPort},
422+
// Remove any existing entry for the app port to avoid duplicates.
423+
filtered := cfg.AppPort[:0]
424+
for _, m := range cfg.AppPort {
425+
if m.ContainerPort != appPort {
426+
filtered = append(filtered, m)
427+
}
425428
}
429+
cfg.AppPort = append(filtered,
430+
devcontainer.PortMapping{HostPort: appPort, ContainerPort: appPort},
431+
devcontainer.PortMapping{HostPort: interceptPort, ContainerPort: interceptPort},
432+
)
426433
cfg.EnsureContainerEnv(meta.EnvInterceptorAddr, interceptAddr)
427434
cfg.EnsureCapAdd("NET_ADMIN")
428435
cfg.EnsureRunArgs("-l", labelBridgeDeployment+"="+dcName)

‎pkg/commands/exec.go‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,11 @@ func runExec(ctx context.Context, c *cli.Command) error {
7676
return fmt.Errorf("interceptor is not healthy: %w", err)
7777
}
7878

79-
dcConfigPath := c.String("devcontainer-config")
80-
if dcConfigPath == "" {
81-
label, err := ct.InspectLabel(ctx, containerID, meta.LabelDevcontainerConfigFile)
82-
if err != nil || label == "" {
83-
return fmt.Errorf("could not determine config path for running bridge %q", deploymentName)
84-
}
85-
dcConfigPath = label
79+
// Always read the config from the container — this is the config it
80+
// was actually created with, regardless of what -f points to now.
81+
dcConfigPath, err := ct.InspectLabel(ctx, containerID, meta.LabelDevcontainerConfigFile)
82+
if err != nil || dcConfigPath == "" {
83+
return fmt.Errorf("could not determine config path for running bridge %q", deploymentName)
8684
}
8785
workspaceFolder, _ := filepath.Abs(filepath.Dir(filepath.Dir(filepath.Dir(dcConfigPath))))
8886
return execInDevcontainer(ctx, workspaceFolder, dcConfigPath, nil, cmdArgs)

0 commit comments

Comments
 (0)