Skip to content

Commit

Permalink
make EnvAPIClient and docker-cli have same behavior towards env DOCKE…
Browse files Browse the repository at this point in the history
…R_TLS_VERIFY
  • Loading branch information
terloo committed Jul 9, 2023
1 parent f288c1a commit 7b8887a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/skaffold/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"strings"
"sync"

cliconfig "github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/connhelper"
"github.com/docker/docker/client"
"github.com/docker/go-connections/tlsconfig"
Expand Down Expand Up @@ -109,6 +110,18 @@ func newEnvAPIClient() ([]string, client.CommonAPIClient, error) {
}
}

if os.Getenv("DOCKER_TLS_VERIFY") != "" {
opts = append(opts, client.WithScheme("https"))
if os.Getenv("DOCKER_CERT_PATH") == "" {
dockerCertPath := cliconfig.Dir()
opts = append(opts, client.WithTLSClientConfig(
filepath.Join(dockerCertPath, "ca.pem"),
filepath.Join(dockerCertPath, "cert.pem"),
filepath.Join(dockerCertPath, "key.pem"),
))
}
}

cli, err := client.NewClientWithOpts(opts...)
if err != nil {
return nil, nil, fmt.Errorf("error getting docker client: %s", err)
Expand Down
9 changes: 9 additions & 0 deletions pkg/skaffold/docker/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ func TestNewEnvClient(t *testing.T) {
},
shouldErr: false,
},
{
description: "specified enable tls",
envs: map[string]string{
"DOCKER_HOST": "tcp://127.0.0.1:8080",
"DOCKER_TLS_VERIFY": "1",
},
// can't found tls file
shouldErr: true,
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
Expand Down

0 comments on commit 7b8887a

Please sign in to comment.