Skip to content

Commit

Permalink
Add support for insecure registry
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermebr committed Aug 14, 2018
1 parent 3a9b4fe commit 4d90ee7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
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

0 comments on commit 4d90ee7

Please sign in to comment.