Skip to content

Commit 9a3e077

Browse files
authored
Merge pull request #2222 from gtardif/use_desktop_proxy_when_up
Use Docker Desktop proxy when available
2 parents 88ef828 + 725de01 commit 9a3e077

33 files changed

Lines changed: 251 additions & 71 deletions

cmd/root/push.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func runPushCommand(cmd *cobra.Command, args []string) error {
5151

5252
out.Printf("Pushing agent %s to %s\n", agentFilename, tag)
5353

54-
err = remote.Push(tag)
54+
err = remote.Push(ctx, tag)
5555
if err != nil {
5656
return fmt.Errorf("failed to push artifact: %w", err)
5757
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ require (
4242
github.com/gorilla/websocket v1.5.3
4343
github.com/junegunn/fzf v0.70.0
4444
github.com/k3a/html2text v1.4.0
45+
github.com/kofalt/go-memoize v0.0.0-20240506050413-9e5eb99a0f2a
4546
github.com/labstack/echo/v4 v4.15.1
4647
github.com/mattn/go-isatty v0.0.20
4748
github.com/mattn/go-runewidth v0.0.21
@@ -183,6 +184,7 @@ require (
183184
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect
184185
github.com/opencontainers/go-digest v1.0.0 // indirect
185186
github.com/opencontainers/image-spec v1.1.1 // indirect
187+
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
186188
github.com/perimeterx/marshmallow v1.1.5 // indirect
187189
github.com/pjbgf/sha1cd v0.3.2 // indirect
188190
github.com/pmezard/go-difflib v1.0.0 // indirect

go.sum

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4
311311
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
312312
github.com/klauspost/compress v1.18.4 h1:RPhnKRAQ4Fh8zU2FY/6ZFDwTVTxgJ/EMydqSTzE9a2c=
313313
github.com/klauspost/compress v1.18.4/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
314+
github.com/kofalt/go-memoize v0.0.0-20240506050413-9e5eb99a0f2a h1:yyeZ0oZLWgSakB9QzPuL/Kyx9kcXYblDOswXaOEx0tg=
315+
github.com/kofalt/go-memoize v0.0.0-20240506050413-9e5eb99a0f2a/go.mod h1:EUxMohcCc4AiiO1SImzCQo3EdrEYj9Xkyrxbepg02nQ=
314316
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
315317
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
316318
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -385,6 +387,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
385387
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
386388
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
387389
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
390+
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
391+
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
388392
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
389393
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
390394
github.com/pjbgf/sha1cd v0.3.2 h1:a9wb0bp1oC2TGwStyn0Umc/IGKQnEgF0vVaZ8QF8eo4=
@@ -431,10 +435,13 @@ github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnB
431435
github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY=
432436
github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82 h1:6C8qej6f1bStuePVkLSFxoU22XBS165D3klxlzRg8F4=
433437
github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82/go.mod h1:xe4pgH49k4SsmkQq5OT8abwhWmnzkhpgnXeekbx2efw=
434-
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
435438
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
439+
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
440+
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
436441
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
437442
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
443+
github.com/smartystreets/gunit v1.4.2 h1:tyWYZffdPhQPfK5VsMQXfauwnJkqg7Tv5DLuQVYxq3Q=
444+
github.com/smartystreets/gunit v1.4.2/go.mod h1:ZjM1ozSIMJlAz/ay4SG8PeKF00ckUp+zMHZXV9/bvak=
438445
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
439446
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
440447
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=

pkg/config/sources.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func (a urlSource) Read(ctx context.Context) ([]byte, error) {
241241
// Add GitHub token authorization for GitHub URLs
242242
a.addGitHubAuth(ctx, req)
243243

244-
resp, err := httpclient.NewHTTPClient().Do(req)
244+
resp, err := httpclient.NewHTTPClient(ctx).Do(req)
245245
if err != nil {
246246
// Network error - try to use cached version
247247
if cachedData, cacheErr := os.ReadFile(cachePath); cacheErr == nil {

pkg/desktop/paths.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "sync"
44

55
type DockerDesktopPaths struct {
66
BackendSocket string
7+
ProxySocket string
78
}
89

910
var Paths = sync.OnceValue(func() DockerDesktopPaths {

pkg/desktop/running.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package desktop
22

33
import (
44
"context"
5+
"time"
56
)
67

78
func IsDockerDesktopRunning(ctx context.Context) bool {
9+
ctx, cancel := context.WithTimeout(ctx, time.Second*3)
10+
defer cancel()
811
err := ClientBackend.Get(ctx, "/ping", nil)
912
return err == nil
1013
}

pkg/desktop/socket/dial.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package socket
2+
3+
import (
4+
"strings"
5+
)
6+
7+
func stripUnixScheme(path string) string {
8+
return strings.TrimPrefix(path, "unix://")
9+
}

pkg/desktop/socket/dial_unix.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build !windows
2+
3+
package socket
4+
5+
import (
6+
"context"
7+
"net"
8+
)
9+
10+
// DialUnix is a simple wrapper for `net.Dial("unix")`.
11+
func DialUnix(ctx context.Context, path string) (net.Conn, error) {
12+
dialer := &net.Dialer{}
13+
return dialer.DialContext(ctx, "unix", stripUnixScheme(path))
14+
}

pkg/desktop/socket/dial_windows.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package socket
2+
3+
import (
4+
"context"
5+
"net"
6+
"strings"
7+
"time"
8+
9+
"github.com/Microsoft/go-winio"
10+
)
11+
12+
// DialUnix is a simple wrapper for `winio.DialPipe(path, 10s)`.
13+
// It provides API compatibility for named pipes with the Unix domain socket API.
14+
func DialUnix(ctx context.Context, path string) (net.Conn, error) {
15+
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
16+
defer cancel()
17+
18+
if strings.HasPrefix(path, "unix://") {
19+
// windows supports AF_UNIX
20+
d := &net.Dialer{}
21+
return d.DialContext(ctx, "unix", stripUnixScheme(path))
22+
}
23+
return winio.DialPipeContext(ctx, path)
24+
}

pkg/desktop/sockets_darwin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ func getDockerDesktopPaths() (DockerDesktopPaths, error) {
1515

1616
return DockerDesktopPaths{
1717
BackendSocket: filepath.Join(data, "backend.sock"),
18+
ProxySocket: filepath.Join(data, "httpproxy.sock"),
1819
}, nil
1920
}

0 commit comments

Comments
 (0)