Skip to content

Construct Compose provider URLs through container inspection #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2025

Conversation

xenoscopic
Copy link
Contributor

This PR switches from hardcoded URLs that require a special host definition to dynamic, inspection-based URLs.

There's just a smidgen of skullduggery in
ensureStandaloneRunnerAvailable, but I can clean it up in the next PR (which will allow fully dynamic Docker CE and cloud ports).

This commit switches from hardcoded URLs that require a special host
definition to dynamic, inspection-based URLs.

There's just a smidgen of skullduggery in
ensureStandaloneRunnerAvailable, but I can clean it up in the next PR
(which will allow fully dynamic Docker CE and cloud ports).

Signed-off-by: Jacob Howard <jacob.howard@docker.com>
@xenoscopic xenoscopic requested review from a team, fiam and silvin-lubecki June 12, 2025 00:22
Comment on lines +61 to +63
if port.IP == "127.0.0.1" {
result.hostPort = port.PublicPort
} else {

Choose a reason for hiding this comment

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

nit: should we use net.ParseIP(port.IP).IsLoopback() instead ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think not neccesarily, it seems to me the idea is to match the hardcoded IP here

portBindings := []nat.PortBinding{{HostIP: "127.0.0.1", HostPort: portStr}}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we want to leave it matching the hardcoded because in theory we may be talking to a remote Docker CE instance where IsLoopback() might behave differently (though the current impl looks consistent). I'll keep this in the back pocket though. net.ParseIP might be useful for identifying IP classes in general.

Copy link

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@fiam fiam left a comment

Choose a reason for hiding this comment

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

LGTM with a couple of minor comments

We need to address the TOCTOU (Jim actually ran into it yesterday), but I think it's better to do that separately.

// inspectStandaloneRunner inspects a standalone runner container and extracts
// its configuration.
func inspectStandaloneRunner(container container.Summary) *standaloneRunner {
result := &standaloneRunner{}
Copy link
Contributor

Choose a reason for hiding this comment

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

question: would adding a label with the <host>:<port> where the DMR is running to the container on creation and then reading it here be more robust?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to avoid that because I think we may want a fully dynamic binding mode for standalone runners where they bind on :0 and we inspect the port once running.

Comment on lines +61 to +63
if port.IP == "127.0.0.1" {
result.hostPort = port.PublicPort
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think not neccesarily, it seems to me the idea is to match the hardcoded IP here

portBindings := []nat.PortBinding{{HostIP: "127.0.0.1", HostPort: portStr}}

Copy link
Contributor

@fiam fiam left a comment

Choose a reason for hiding this comment

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

LGTM with a couple of minor comments

Copy link
Collaborator

@doringeman doringeman left a comment

Choose a reason for hiding this comment

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

LGTM!
Just an unused field. And I agree with TOCTOU.

// standaloneRunner encodes the standalone runner configuration, if one exists.
type standaloneRunner struct {
// hostPort is the port that the runner is listening to on the host.
hostPort uint16
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't seem to be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm planning to use it in a future PR where we make the listener port configurable. If I don't manage, I'll remove it, scout's honor ✋

Signed-off-by: Jacob Howard <jacob.howard@docker.com>
@xenoscopic xenoscopic merged commit 3e384bc into main Jun 12, 2025
6 checks passed
@xenoscopic xenoscopic deleted the compose-gateway-url branch June 12, 2025 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants