Skip to content

Commit

Permalink
Error when user gives build args with non-Docker strat
Browse files Browse the repository at this point in the history
  • Loading branch information
oatmealraisin committed Mar 8, 2017
1 parent b1201dd commit 7e52d29
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/cmd/cli/cmd/newapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,10 @@ func CompleteAppConfig(config *newcmd.AppConfig, f *clientcmd.Factory, c *cobra.
if config.BinaryBuild && config.Strategy == generate.StrategyPipeline {
return kcmdutil.UsageError(c, "specifying binary builds and the pipeline strategy at the same time is not allowed.")
}

if len(config.BuildArgs) > 0 && config.Strategy != generate.StrategyUnspecified && config.Strategy != generate.StrategyDocker {
return kcmdutil.UsageError(c, "Cannot use '--build-arg' without a Docker build")
}
return nil
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/generate/app/cmd/newapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ func (c *AppConfig) buildPipelines(components app.ComponentReferences, environme
}
}

numDockerBuilds := 0

pipelineBuilder := app.NewPipelineBuilder(c.Name, c.GetBuildEnvironment(), DockerStrategyOptions, c.OutputDocker).To(c.To)
for _, group := range components.Group() {
glog.V(4).Infof("found group: %v", group)
Expand All @@ -382,10 +384,15 @@ func (c *AppConfig) buildPipelines(components app.ComponentReferences, environme
switch {
case refInput.ExpectToBuild:
glog.V(4).Infof("will add %q secrets into a build for a source build of %q", strings.Join(c.Secrets, ","), refInput.Uses)

if err := refInput.Uses.AddBuildSecrets(c.Secrets); err != nil {
return nil, fmt.Errorf("unable to add build secrets %q: %v", strings.Join(c.Secrets, ","), err)
}

if refInput.Uses.GetStrategy() == generate.StrategyDocker {
numDockerBuilds++
}

var (
image *app.ImageRef
err error
Expand Down Expand Up @@ -443,6 +450,16 @@ func (c *AppConfig) buildPipelines(components app.ComponentReferences, environme
}
pipelines = append(pipelines, common...)
}

if len(c.BuildArgs) > 0 {
if numDockerBuilds == 0 {
return nil, fmt.Errorf("Cannot use '--build-arg' without a Docker build")
}
if numDockerBuilds > 1 {
fmt.Fprintf(c.ErrOut, "--> WARNING: Applying --build-arg to multiple Docker builds.\n")
}
}

return pipelines, nil
}

Expand Down
6 changes: 5 additions & 1 deletion test/cmd/newapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,13 @@ os::cmd::expect_success "oc new-build --binary php --build-env-file /dev/null --
os::cmd::expect_failure_and_text "echo 'fo%(o=bar' | oc new-build --binary php --build-env-file -" 'invalid parameter assignment'
os::cmd::expect_failure_and_text "echo 'S P A C E S=test' | oc new-build --binary php --build-env-file -" 'invalid parameter assignment'

# new-build - check that we can set build-args in DockerStrategy
# new-build - check that we can set build args in DockerStrategy
os::cmd::expect_success_and_text "oc new-build ${OS_ROOT}/test/testdata/build-arg-dockerfile --build-arg 'foo=bar' --to 'test' -o jsonpath='{.items[?(@.kind==\"BuildConfig\")].spec.strategy.dockerStrategy.buildArgs[?(@.name==\"foo\")].value}'" 'bar'

# check that we cannot set build args in a non-DockerStrategy build
os::cmd::expect_failure_and_text "oc new-build https://github.com/openshift/ruby-hello-world --strategy=source --build-arg 'foo=bar'" "error: Cannot use '--build-arg' without a Docker build"
os::cmd::expect_failure_and_text "oc new-build https://github.com/openshift/ruby-ex --build-arg 'foo=bar'" "error: Cannot use '--build-arg' without a Docker build"

#
# verify we can create from a template when some objects in the template declare an app label
# the app label will not be applied to any objects in the template.
Expand Down

0 comments on commit 7e52d29

Please sign in to comment.