option parsing logic: add fallback values
* don't exit on no values provided but instead use sane defaults for username, password and registry * add "--no-push" flag if REPO name has not been specified * only allow setting of TAGS if REPO has been specified as well
This commit is contained in:
parent
73e95f29d3
commit
b6919b2cda
@ -176,13 +176,14 @@ func run(c *cli.Context) error {
|
||||
// Create the docker config file for authentication
|
||||
func createDockerCfgFile(username, password, registry string) error {
|
||||
if username == "" {
|
||||
return fmt.Errorf("Username must be specified")
|
||||
fmt.Println("no username provided, using empty string")
|
||||
}
|
||||
if password == "" {
|
||||
return fmt.Errorf("Password must be specified")
|
||||
fmt.Println("no password provided, using empty string")
|
||||
}
|
||||
if registry == "" {
|
||||
return fmt.Errorf("Registry must be specified")
|
||||
fmt.Println("no registry string provided, using the default value")
|
||||
registry = v1Registry
|
||||
}
|
||||
|
||||
if registry == v2Registry {
|
||||
|
16
kaniko.go
16
kaniko.go
@ -46,10 +46,6 @@ type (
|
||||
|
||||
// Exec executes the plugin step
|
||||
func (p Plugin) Exec() error {
|
||||
if p.Build.Repo == "" {
|
||||
return fmt.Errorf("repository name to publish image must be specified")
|
||||
}
|
||||
|
||||
if _, err := os.Stat(p.Build.Dockerfile); os.IsNotExist(err) {
|
||||
return fmt.Errorf("dockerfile does not exist at path: %s", p.Build.Dockerfile)
|
||||
}
|
||||
@ -59,10 +55,16 @@ func (p Plugin) Exec() error {
|
||||
fmt.Sprintf("--context=dir://%s", p.Build.Context),
|
||||
}
|
||||
|
||||
// Set the destination repository
|
||||
for _, tag := range p.Build.Tags {
|
||||
cmdArgs = append(cmdArgs, fmt.Sprintf("--destination=%s:%s", p.Build.Repo, tag))
|
||||
if p.Build.Repo == "" {
|
||||
fmt.Println("repository name to publish image not specified, adding '--no-push' flag")
|
||||
cmdArgs = append(cmdArgs, fmt.Sprintf("--no-push"))
|
||||
} else {
|
||||
// Set the destination repository
|
||||
for _, tag := range p.Build.Tags {
|
||||
cmdArgs = append(cmdArgs, fmt.Sprintf("--destination=%s:%s", p.Build.Repo, tag))
|
||||
}
|
||||
}
|
||||
|
||||
// Set the build arguments
|
||||
for _, arg := range p.Build.Args {
|
||||
cmdArgs = append(cmdArgs, fmt.Sprintf("--build-arg=%s", arg))
|
||||
|
Loading…
Reference in New Issue
Block a user