add skip-tls-verify flag for insecure private registries (#11)

Co-authored-by: beniamin.calota <beniamin.calota@emag.ro>
This commit is contained in:
Beniamin 2021-02-18 10:19:21 +02:00 committed by GitHub
parent 3e4dad8cae
commit 9cca954ec6
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View File

@ -94,6 +94,11 @@ func main() {
Usage: "docker password", Usage: "docker password",
EnvVar: "PLUGIN_PASSWORD", EnvVar: "PLUGIN_PASSWORD",
}, },
cli.BoolFlag {
Name: "skip-tls-verify",
Usage: "Skip registry tls verify",
EnvVar: "PLUGIN_SKIP_TLS_VERIFY",
},
} }
if err := app.Run(os.Args); err != nil { if err := app.Run(os.Args); err != nil {
@ -116,6 +121,7 @@ func run(c *cli.Context) error {
Target: c.String("target"), Target: c.String("target"),
Repo: c.String("repo"), Repo: c.String("repo"),
Labels: c.StringSlice("custom-labels"), Labels: c.StringSlice("custom-labels"),
SkipTlsVerify: c.Bool("skip-tls-verify"),
}, },
} }
return plugin.Exec() return plugin.Exec()

View File

@ -10,13 +10,14 @@ import (
type ( type (
// Build defines Docker build parameters. // Build defines Docker build parameters.
Build struct { Build struct {
Dockerfile string // Docker build Dockerfile Dockerfile string // Docker build Dockerfile
Context string // Docker build context Context string // Docker build context
Tags []string // Docker build tags Tags []string // Docker build tags
Args []string // Docker build args Args []string // Docker build args
Target string // Docker build target Target string // Docker build target
Repo string // Docker build repository Repo string // Docker build repository
Labels []string // Label map Labels []string // Label map
SkipTlsVerify bool // Docker skip tls certificate verify for registry
} }
// Plugin defines the Docker plugin parameters. // Plugin defines the Docker plugin parameters.
@ -57,6 +58,10 @@ func (p Plugin) Exec() error {
cmdArgs = append(cmdArgs, fmt.Sprintf("--target=%s", p.Build.Target)) cmdArgs = append(cmdArgs, fmt.Sprintf("--target=%s", p.Build.Target))
} }
if p.Build.SkipTlsVerify {
cmdArgs = append(cmdArgs, fmt.Sprintf("--skip-tls-verify=true"))
}
cmd := exec.Command("/kaniko/executor", cmdArgs...) cmd := exec.Command("/kaniko/executor", cmdArgs...)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr