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

Fix support for insecure registry #169

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var RootCmd = &cobra.Command{
os.Exit(1)
}

if err := executor.DoPush(image, destinations, tarPath); err != nil {
if err := executor.DoPush(image, destinations, tarPath, dockerInsecureSkipTLSVerify); err != nil {
logrus.Error(err)
os.Exit(1)
}
Expand Down
19 changes: 17 additions & 2 deletions pkg/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package executor

import (
"bytes"
"crypto/tls"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -180,7 +181,7 @@ func (w *withUserAgent) RoundTrip(r *http.Request) (*http.Response, error) {
return w.t.RoundTrip(r)
}

func DoPush(image v1.Image, destinations []string, tarPath string) error {
func DoPush(image v1.Image, destinations []string, tarPath string, dockerInsecureSkipTLSVerify bool) error {

// continue pushing unless an error occurs
for _, destination := range destinations {
Expand All @@ -190,6 +191,14 @@ func DoPush(image v1.Image, destinations []string, tarPath string) error {
return err
}

if dockerInsecureSkipTLSVerify {
newReg, err := name.NewInsecureRegistry(destRef.Repository.Registry.Name(), name.WeakValidation)
if err != nil {
return err
}
destRef.Repository.Registry = newReg
}

if tarPath != "" {
return tarball.WriteToFile(tarPath, destRef, image, nil)
}
Expand All @@ -205,7 +214,13 @@ func DoPush(image v1.Image, destinations []string, tarPath string) error {
}

// Create a transport to set our user-agent.
rt := &withUserAgent{t: http.DefaultTransport}
tr := http.DefaultTransport
if dockerInsecureSkipTLSVerify {
tr.(*http.Transport).TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
}
rt := &withUserAgent{t: tr}

if err := remote.Write(destRef, image, pushAuth, rt, remote.WriteOptions{}); err != nil {
logrus.Error(fmt.Errorf("Failed to push to destination %s", destination))
Expand Down