Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when user gives build args with non-Docker strat #13257

Merged
merged 1 commit into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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