-
Notifications
You must be signed in to change notification settings - Fork 97
migrate to moby modules #694
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
Open
thaJeztah
wants to merge
1
commit into
docker:main
Choose a base branch
from
thaJeztah:migrate_moby
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+200
−173
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,12 +15,11 @@ import ( | |
| "github.com/docker/cli/cli/command" | ||
| "github.com/docker/cli/cli/connhelper" | ||
| "github.com/docker/cli/cli/context/docker" | ||
| "github.com/docker/docker/api/types/container" | ||
| clientpkg "github.com/docker/docker/client" | ||
| "github.com/docker/model-runner/cmd/cli/pkg/standalone" | ||
| "github.com/docker/model-runner/cmd/cli/pkg/types" | ||
| "github.com/docker/model-runner/pkg/inference" | ||
| modeltls "github.com/docker/model-runner/pkg/tls" | ||
| "github.com/moby/moby/api/types/container" | ||
| "github.com/moby/moby/client" | ||
| ) | ||
|
|
||
|
|
@@ -75,7 +74,7 @@ func isCloudContext(cli *command.DockerCli) bool { | |
| } | ||
|
|
||
| // DockerClientForContext creates a Docker client for the specified context. | ||
| func DockerClientForContext(cli *command.DockerCli, name string) (*clientpkg.Client, error) { | ||
| func DockerClientForContext(cli *command.DockerCli, name string) (*client.Client, error) { | ||
thaJeztah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| c, err := cli.ContextStore().GetMetadata(name) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to load context metadata: %w", err) | ||
|
|
@@ -85,10 +84,9 @@ func DockerClientForContext(cli *command.DockerCli, name string) (*clientpkg.Cli | |
| return nil, fmt.Errorf("unable to determine context endpoint: %w", err) | ||
| } | ||
|
|
||
| opts := []clientpkg.Opt{ | ||
| clientpkg.FromEnv, | ||
| clientpkg.WithAPIVersionNegotiation(), | ||
| clientpkg.WithHost(endpoint.Host), | ||
| opts := []client.Opt{ | ||
| client.FromEnv, | ||
| client.WithHost(endpoint.Host), | ||
thaJeztah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| helper, err := connhelper.GetConnectionHelper(endpoint.Host) | ||
|
|
@@ -97,12 +95,12 @@ func DockerClientForContext(cli *command.DockerCli, name string) (*clientpkg.Cli | |
| } | ||
| if helper != nil { | ||
| opts = append(opts, | ||
| clientpkg.WithHost(helper.Host), | ||
| clientpkg.WithDialContext(helper.Dialer), | ||
| client.WithHost(helper.Host), | ||
| client.WithDialContext(helper.Dialer), | ||
thaJeztah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| } | ||
|
|
||
| return clientpkg.NewClientWithOpts(opts...) | ||
| return client.New(opts...) | ||
thaJeztah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // ModelRunnerContext encodes the operational context of a Model CLI command and | ||
|
|
@@ -205,11 +203,14 @@ func wakeUpCloudIfIdle(ctx context.Context, cli *command.DockerCli) error { | |
| if err != nil { | ||
| return fmt.Errorf("failed to create Docker client: %w", err) | ||
| } | ||
| defer dockerClient.Close() | ||
thaJeztah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // The call is expected to fail with a client error due to nil arguments, but it triggers | ||
| // Docker Cloud to wake up from idle. Only return unexpected failures (network issues, | ||
| // server errors) so they're logged as warnings. | ||
| _, err = dockerClient.ContainerCreate(ctx, &container.Config{}, nil, nil, nil, "") | ||
| _, err = dockerClient.ContainerCreate(ctx, client.ContainerCreateOptions{ | ||
| Config: &container.Config{}, | ||
| }) | ||
thaJeztah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil && !errdefs.IsInvalidArgument(err) { | ||
| return fmt.Errorf("failed to wake up Docker Cloud: %w", err) | ||
| } | ||
|
|
@@ -337,11 +338,21 @@ func DetectContext(ctx context.Context, cli *command.DockerCli, printer standalo | |
| // Construct the HTTP client. | ||
| var httpClient DockerHttpClient | ||
| if kind == types.ModelRunnerEngineKindDesktop { | ||
| dockerClient, err := DockerClientForContext(cli, cli.CurrentContext()) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to create model runner client: %w", err) | ||
| if useTLS { | ||
| // For Desktop context, if TLS is enabled, we should either fully support it or fail fast | ||
| // Since Desktop context uses Docker client, we need to handle TLS differently | ||
| // For now, we'll fail fast to make the behavior clear | ||
| return nil, fmt.Errorf("TLS is not supported for Desktop contexts") | ||
thaJeztah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| httpClient = dockerClient.HTTPClient() | ||
|
|
||
| // FIXME(thaJeztah): can we get the user-agent in some other way? (or just use a default, specific to DMR)? | ||
| // dockerClient, err := DockerClientForContext(cli, cli.CurrentContext()) | ||
| // if err != nil { | ||
| // return nil, fmt.Errorf("unable to create model runner client: %w", err) | ||
| // } | ||
| // httpClient = dockerClient.HTTPClient() | ||
| // dockerClient.Close() | ||
|
Comment on lines
+348
to
+354
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part should probably be looked into; what user-agent do we want to use here? Could model-runner use its own?
thaJeztah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| httpClient = http.DefaultClient | ||
| } else { | ||
| httpClient = http.DefaultClient | ||
| } | ||
|
|
@@ -353,13 +364,6 @@ func DetectContext(ctx context.Context, cli *command.DockerCli, printer standalo | |
| // Construct TLS client if TLS is enabled | ||
| var tlsClient DockerHttpClient | ||
| if useTLS { | ||
| if kind == types.ModelRunnerEngineKindDesktop { | ||
| // For Desktop context, if TLS is enabled, we should either fully support it or fail fast | ||
| // Since Desktop context uses Docker client, we need to handle TLS differently | ||
| // For now, we'll fail fast to make the behavior clear | ||
| return nil, fmt.Errorf("TLS is not supported for Desktop contexts") | ||
| } | ||
|
|
||
| tlsConfig, err := modeltls.LoadClientTLSConfig(tlsCACert, tlsSkipVerify) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to load TLS configuration: %w", err) | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
port.IP.IsLoopback()is a more robust and idiomatic way to check for loopback addresses compared to a string comparison with "127.0.0.1". This change correctly leverages thenetippackage's functionality.