Skip to content
Merged
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
20 changes: 16 additions & 4 deletions internal/config/docker_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,23 @@ func runDockerInspect(containerID, formatTemplate string) (string, error) {
return "", err
}

logDockerHelpers.Printf("Running docker inspect: containerID=%s, format=%s", containerID, formatTemplate)
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

For log readability/parsing, consider quoting string fields that may contain spaces/special chars. In particular, formatTemplate is a Go template (contains braces/quotes) and containerID is an identifier; using %q for formatTemplate (and possibly for other string fields in these new logs) will make the output unambiguous and help avoid multi-field confusion if the template ever includes whitespace.

Suggested change
logDockerHelpers.Printf("Running docker inspect: containerID=%s, format=%s", containerID, formatTemplate)
logDockerHelpers.Printf("Running docker inspect: containerID=%q, format=%q", containerID, formatTemplate)

Copilot uses AI. Check for mistakes.

cmd := exec.Command("docker", "inspect", "--format", formatTemplate, containerID)
output, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("docker inspect failed: %w", err)
}

return strings.TrimSpace(string(output)), nil
result := strings.TrimSpace(string(output))
logDockerHelpers.Printf("Docker inspect succeeded: output_len=%d", len(result))
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

The output_len field is computed from the trimmed string (len(result)), which may not match the raw docker inspect output size and is counted in bytes (Go string length). Consider either logging len(output) (raw bytes) or renaming the field to something like trimmed_len/result_len to avoid misleading diagnostics.

Suggested change
logDockerHelpers.Printf("Docker inspect succeeded: output_len=%d", len(result))
logDockerHelpers.Printf("Docker inspect succeeded: result_len=%d", len(result))

Copilot uses AI. Check for mistakes.
return result, nil
}

// checkPortMapping uses docker inspect to verify that the specified port is mapped
func checkPortMapping(containerID, port string) (bool, error) {
logDockerHelpers.Printf("Checking port mapping: containerID=%s, port=%s", containerID, port)

output, err := runDockerInspect(containerID, "{{json .NetworkSettings.Ports}}")
if err != nil {
return false, err
Expand All @@ -94,7 +100,9 @@ func checkPortMapping(containerID, port string) (bool, error) {

// Check if the port is in the output with a host binding
// The format is like: {"8000/tcp":[{"HostIp":"0.0.0.0","HostPort":"8000"}]}
return strings.Contains(output, portKey) && strings.Contains(output, "HostPort"), nil
mapped := strings.Contains(output, portKey) && strings.Contains(output, "HostPort")
logDockerHelpers.Printf("Port mapping check result: port=%s, mapped=%v", portKey, mapped)
return mapped, nil
}

// checkStdinInteractive uses docker inspect to verify the container was started with -i flag
Expand All @@ -104,7 +112,9 @@ func checkStdinInteractive(containerID string) bool {
return false
}

return output == "true"
interactive := output == "true"
logDockerHelpers.Printf("Stdin interactive check: containerID=%s, interactive=%v", containerID, interactive)
return interactive
}

// checkLogDirMounted uses docker inspect to verify the log directory is mounted
Expand All @@ -115,7 +125,9 @@ func checkLogDirMounted(containerID, logDir string) bool {
}

// Check if the log directory is in the mounts
return strings.Contains(output, logDir)
mounted := strings.Contains(output, logDir)
logDockerHelpers.Printf("Log dir mount check: containerID=%s, logDir=%s, mounted=%v", containerID, logDir, mounted)
return mounted
}

// ExpandEnvArgs expands Docker -e flags that reference environment variables.
Expand Down
Loading