Skip to content
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

feat(desktop): add Docker Desktop detection and client skeleton #11593

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

milas
Copy link
Contributor

@milas milas commented Mar 8, 2024

What I did
Use the system info Engine API to auto-discover the Desktop integration API endpoint (a local AF_UNIX socket or named pipe).

If present and responding to a /ping, the client is populated on the Compose service for use. Otherwise, it's left nil, and Compose will not try to use any functionality that relies on Docker Desktop (e.g. opening docker-desktop:// deep links to the GUI).

This refactors some of the in-memory socket dialer code, so we can share it easier (time to bring back docker/go-connections? 🤔) and make it slightly more robust.

Related issue
JIRA: COMP-457

(not mandatory) A picture of a cute animal, if possible in relation to what you did
badger

@milas milas added the area/desktop Features that are integrated with Docker Desktop label Mar 8, 2024
@milas milas requested a review from a team March 8, 2024 20:17
@milas milas self-assigned this Mar 8, 2024
@milas milas requested review from ndeloof, glours and jhrotko and removed request for a team March 8, 2024 20:17
Copy link

codecov bot commented Mar 8, 2024

Codecov Report

Attention: Patch coverage is 15.62500% with 108 lines in your changes are missing coverage. Please review.

Project coverage is 57.75%. Comparing base (4efb897) to head (7452a14).

Files Patch % Lines
internal/desktop/client.go 0.00% 37 Missing ⚠️
pkg/compose/desktop.go 14.28% 24 Missing ⚠️
internal/memnet/conn.go 0.00% 21 Missing ⚠️
pkg/compose/compose.go 0.00% 9 Missing ⚠️
cmd/compose/compose.go 68.42% 5 Missing and 1 partial ⚠️
internal/memnet/conn_unix.go 0.00% 5 Missing ⚠️
cmd/main.go 50.00% 2 Missing and 1 partial ⚠️
internal/tracing/docker_context.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11593      +/-   ##
==========================================
- Coverage   58.20%   57.75%   -0.45%     
==========================================
  Files         135      138       +3     
  Lines       11611    11717     +106     
==========================================
+ Hits         6758     6767       +9     
- Misses       4182     4277      +95     
- Partials      671      673       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +79 to +84
if s.dockerCli != nil {
errs = append(errs, s.dockerCli.Client().Close())
}
if s.desktopCli != nil {
errs = append(errs, s.desktopCli.Close())
}
Copy link
Contributor

@jhrotko jhrotko Mar 11, 2024

Choose a reason for hiding this comment

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

merge if statements?

Copy link
Contributor

Choose a reason for hiding this comment

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

not the same CLI here

Copy link
Contributor

Choose a reason for hiding this comment

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

I dont know how to read :)

@jhrotko
Copy link
Contributor

jhrotko commented Mar 11, 2024

Could we also add an e2e test for this cases? unix, windows and darwin?

if err != nil {
return err
}
cmd.SetContext(ctx)

// (6) Desktop integration
if db, ok := backend.(desktop.IntegrationService); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish we refactor this init sequence so we don't mutate backend but use setup builder according to options:

backend := compose.NewComposeService(dockerCli, WithDryRun(xx), WithDesktopIntegration(xx))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed 😞 the init is overly complicated, especially because of the split between Docker/CLI/plugins, Compose itself, and Cobra 🐍

This was already kind of hacky - I didn't want to add this to api.Service but the concrete composeService implementation is unexported

I'll see if I can refactor this in another PR to swap to options an consolidate some things, e.g. we have several lazy/memoized components but they all happen in different ways currently

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't want to add this to api.Service

why not ?

@milas
Copy link
Contributor Author

milas commented Mar 11, 2024

Could we also add an e2e test for this cases? unix, windows and darwin?

Yes, this is a great call out! This will require me to sort out a couple things first - need to get updated Docker Desktop builds on our CI runners & service accounts on Hub for them to log in as, so I made a ticket in JIRA.

I'll go ahead and get started on the test and t.Skip() it for the moment at least

Use the system info Engine API to auto-discover the Desktop
integration API endpoint (a local `AF_UNIX` socket or named pipe).

If present and responding to a `/ping`, the client is populated
on the Compose service for use. Otherwise, it's left `nil`, and
Compose will not try to use any functionality that relies on
Docker Desktop (e.g. opening `docker-desktop://` deep links to
the GUI).

Signed-off-by: Milas Bowman <milas.bowman@docker.com>
var d net.Dialer
switch network {
case "unix":
if err := validateSocketPath(addr); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

build is complaining this is undefined for windows arch

return winio.DialPipeContext(ctx, addr)
}

func validateUnixSocketPath(addr string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to validateSocketPath to avoid build errors

Comment on lines +79 to +84
if s.dockerCli != nil {
errs = append(errs, s.dockerCli.Client().Close())
}
if s.desktopCli != nil {
errs = append(errs, s.desktopCli.Close())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont know how to read :)

@milas milas merged commit 17d4229 into docker:main Mar 12, 2024
28 checks passed
@milas milas deleted the desktop-detection branch March 12, 2024 13:47
rarguelloF pushed a commit to rarguelloF/compose that referenced this pull request Mar 15, 2024
temenuzhka-thede pushed a commit to temenuzhka-thede/compose that referenced this pull request Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/desktop Features that are integrated with Docker Desktop
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants