Add support for insecure registry (#169)

This commit is contained in:
Guilherme Rezende 2018-08-15 15:28:16 -03:00 committed by priyawadhwa
parent 3a9b4fe612
commit 60bdda4c49
2 changed files with 18 additions and 3 deletions

View File

@ -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)
}

View File

@ -18,6 +18,7 @@ package executor
import (
"bytes"
"crypto/tls"
"fmt"
"io"
"io/ioutil"
@ -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 {
@ -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)
}
@ -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))