Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 471888f

Browse files
authored
Merge pull request #2171 from p1-0tr/ps-docker-cli-sock-from-home
Use Docker CLI socket from home
2 parents 6f3f942 + 19ac0ad commit 471888f

10 files changed

+84
-55
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ RUN --mount=target=. \
108108
make -f builder.Makefile test
109109

110110
FROM base AS check-license-headers
111-
RUN go get -u github.com/kunalkushwaha/ltag
111+
RUN go install github.com/google/addlicense@latest
112112
RUN --mount=target=. \
113113
make -f builder.Makefile check-license-headers
114114

cli/metrics/conn_darwin.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//go:build darwin
2+
// +build darwin
3+
4+
/*
5+
Copyright 2022 Docker Compose CLI authors
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
20+
package metrics
21+
22+
import (
23+
"net"
24+
"path/filepath"
25+
26+
"github.com/docker/docker/pkg/homedir"
27+
)
28+
29+
var (
30+
socket = "/var/run/docker-cli.sock"
31+
)
32+
33+
func init() {
34+
// Attempt to retrieve the Docker CLI socket for the current user.
35+
if home := homedir.Get(); home != "" {
36+
socket = filepath.Join(home, "/Library/Containers/com.docker.docker/Data/docker-cli.sock")
37+
} // else: On macOS Docker Desktop creates symlinks in /var/run, so fall back to the old default.
38+
overrideSocket() // nop, unless built for e2e testing
39+
}
40+
41+
func conn() (net.Conn, error) {
42+
return net.Dial("unix", socket)
43+
}

cli/metrics/conn_e2e.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
//go:build e2e
12
// +build e2e
23

34
/*
4-
Copyright 2020 Docker Compose CLI authors
5+
Copyright 2020, 2022 Docker Compose CLI authors
56
67
Licensed under the Apache License, Version 2.0 (the "License");
78
you may not use this file except in compliance with the License.
@@ -22,7 +23,7 @@ import (
2223
"os"
2324
)
2425

25-
func init() {
26+
func overrideSocket() {
2627
testSocket, defined := os.LookupEnv("TEST_METRICS_SOCKET")
2728
if defined {
2829
socket = testSocket

scripts/validate/template/go.txt cli/metrics/conn_note2e.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
//go:build !e2e
2+
// +build !e2e
3+
14
/*
2-
Copyright 2020 Docker Compose CLI authors
5+
Copyright 2022 Docker Compose CLI authors
36
47
Licensed under the Apache License, Version 2.0 (the "License");
58
you may not use this file except in compliance with the License.
@@ -14,3 +17,7 @@
1417
limitations under the License.
1518
*/
1619

20+
package metrics
21+
22+
func overrideSocket() {
23+
}

cli/metrics/conn_other.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// +build !windows
1+
//go:build !windows,!darwin
2+
// +build !windows,!darwin
23

34
/*
4-
Copyright 2020 Docker Compose CLI authors
5+
Copyright 2020, 2022 Docker Compose CLI authors
56
67
Licensed under the Apache License, Version 2.0 (the "License");
78
you may not use this file except in compliance with the License.
@@ -18,12 +19,25 @@
1819

1920
package metrics
2021

21-
import "net"
22+
import (
23+
"net"
24+
"path/filepath"
25+
26+
"github.com/docker/docker/pkg/homedir"
27+
)
2228

2329
var (
24-
socket = "/var/run/docker-cli.sock"
30+
socket = ""
2531
)
2632

33+
func init() {
34+
// Attempt to retrieve the Docker CLI socket for the current user.
35+
if home := homedir.Get(); home != "" {
36+
socket = filepath.Join(home, ".docker/desktop/docker-cli.sock")
37+
} // else: On Linux we don't expect to have a global CLI socket, so leave it empty and let connections fail.
38+
overrideSocket() // nop, unless built for e2e testing
39+
}
40+
2741
func conn() (net.Conn, error) {
2842
return net.Dial("unix", socket)
2943
}

cli/metrics/conn_windows.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
//go:build windows
12
// +build windows
23

34
/*
4-
Copyright 2020 Docker Compose CLI authors
5+
Copyright 2020, 2022 Docker Compose CLI authors
56
67
Licensed under the Apache License, Version 2.0 (the "License");
78
you may not use this file except in compliance with the License.
@@ -30,6 +31,10 @@ var (
3031
socket = `\\.\pipe\docker_cli`
3132
)
3233

34+
func init() {
35+
overrideSocket() // no-op, unless built for e2e testing
36+
}
37+
3338
func conn() (net.Conn, error) {
3439
if strings.HasPrefix(socket, `\\.\pipe\`) {
3540
timeout := 200 * time.Millisecond

scripts/validate/fileheader

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env sh
22

3-
# Copyright Docker Compose CLI authors
3+
# Copyright 2020, 2022 Docker Compose CLI authors
44

55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -16,12 +16,10 @@
1616

1717
set -eu -o pipefail
1818

19-
if ! command -v ltag; then
20-
>&2 echo "ERROR: ltag not found. Install with:"
21-
>&2 echo " go get -u github.com/kunalkushwaha/ltag"
19+
if ! command -v addlicense; then
20+
>&2 echo "ERROR: addlicense not found. Install with:"
21+
>&2 echo " go install github.com/google/addlicense@latest"
2222
exit 1
2323
fi
2424

25-
BASEPATH="${1-}"
26-
27-
ltag -t "${BASEPATH}scripts/validate/template" -excludes "validate testdata resolvepath" --check -v
25+
find . -regex '.*\.sh' -o -regex '.*\.go' -o -regex '.*Makefile' -o -regex '.*Dockerfile' | xargs addlicense -check -l apache -c 'Docker Compose CLI authors' -ignore validate -ignore testdata -ignore resolvepath -v 1>&2

scripts/validate/template/bash.txt

-13
This file was deleted.

scripts/validate/template/dockerfile.txt

-13
This file was deleted.

scripts/validate/template/makefile.txt

-13
This file was deleted.

0 commit comments

Comments
 (0)