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

New flag to oc new-build to produce no output #6101

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions contrib/completions/bash/oc
Expand Up @@ -986,6 +986,7 @@ _oc_new-build()
two_word_flags+=("-l")
flags+=("--name=")
flags+=("--no-headers")
flags+=("--no-output")
flags+=("--output=")
two_word_flags+=("-o")
flags+=("--output-version=")
Expand Down
1 change: 1 addition & 0 deletions contrib/completions/bash/openshift
Expand Up @@ -5713,6 +5713,7 @@ _openshift_cli_new-build()
two_word_flags+=("-l")
flags+=("--name=")
flags+=("--no-headers")
flags+=("--no-output")
flags+=("--output=")
two_word_flags+=("-o")
flags+=("--output-version=")
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/cli/cmd/newbuild.go
Expand Up @@ -108,6 +108,7 @@ func NewCmdNewBuild(fullName string, f *clientcmd.Factory, in io.Reader, out io.
cmd.Flags().BoolVar(&config.AllowMissingImages, "allow-missing-images", false, "If true, indicates that referenced Docker images that cannot be found locally or in a registry should still be used.")
cmd.Flags().StringVar(&config.ContextDir, "context-dir", "", "Context directory to be used for the build.")
cmd.Flags().BoolVar(&config.DryRun, "dry-run", false, "If true, do not actually create resources.")
cmd.Flags().BoolVar(&config.NoOutput, "no-output", false, "If true, the build output will not be pushed anywhere.")
cmdutil.AddPrinterFlags(cmd)

return cmd
Expand Down
4 changes: 4 additions & 0 deletions pkg/generate/app/cmd/newapp.go
Expand Up @@ -66,6 +66,7 @@ type AppConfig struct {
Strategy string
InsecureRegistry bool
OutputDocker bool
NoOutput bool

ExpectToBuild bool
BinaryBuild bool
Expand Down Expand Up @@ -619,6 +620,9 @@ func (c *AppConfig) buildPipelines(components app.ComponentReferences, environme
return nil, fmt.Errorf("can't set up a deployment for %q: %v", refInput, err)
}
}
if c.NoOutput {
pipeline.Build.Output = nil
}
common = append(common, pipeline)
if err := common.Reduce(); err != nil {
return nil, fmt.Errorf("can't create a pipeline from %s: %v", common, err)
Expand Down
50 changes: 50 additions & 0 deletions pkg/generate/app/cmd/newapp_test.go
Expand Up @@ -1073,6 +1073,56 @@ func TestRunBuilds(t *testing.T) {
"imageStream": {"origin"},
},
},
{
name: "successful build with no output",
config: &AppConfig{
Dockerfile: "FROM centos",
NoOutput: true,

dockerSearcher: dockerSearcher,
imageStreamSearcher: app.ImageStreamSearcher{
Client: &client.Fake{},
ImageStreamImages: &client.Fake{},
Namespaces: []string{"default"},
},
imageStreamByAnnotationSearcher: &app.ImageStreamByAnnotationSearcher{
Client: &client.Fake{},
ImageStreamImages: &client.Fake{},
Namespaces: []string{"default"},
},
templateSearcher: app.TemplateSearcher{
Client: &client.Fake{},
TemplateConfigsNamespacer: &client.Fake{},
Namespaces: []string{"openshift", "default"},
},

detector: app.SourceRepositoryEnumerator{
Detectors: source.DefaultDetectors,
Tester: dockerfile.NewTester(),
},
typer: kapi.Scheme,
osclient: &client.Fake{},
originNamespace: "default",
},
expected: map[string][]string{
"buildConfig": {"centos"},
"imageStream": {"centos"},
},
checkResult: func(res *AppResult) error {
for _, item := range res.List.Items {
switch t := item.(type) {
case *buildapi.BuildConfig:
got := t.Spec.Output.To
want := (*kapi.ObjectReference)(nil)
if !reflect.DeepEqual(got, want) {
return fmt.Errorf("build.Spec.Output.To = %v; want %v", got, want)
}
return nil
}
}
return fmt.Errorf("BuildConfig not found; got %v", res.List.Items)
},
},
{
name: "successful build from dockerfile with custom name",
config: &AppConfig{
Expand Down
5 changes: 5 additions & 0 deletions test/cmd/builds.sh
Expand Up @@ -49,6 +49,11 @@ os::cmd::expect_success_and_text "oc get bc/origin-test2 --template '${template}

os::cmd::expect_failure_and_text 'oc new-build centos/ruby-22-centos7~https://github.com/openshift/ruby-ex centos/php-56-centos7~https://github.com/openshift/cakephp-ex --to invalid/argument' 'error: only one component or source repository can be used when specifying an output image reference'

os::cmd::expect_success 'oc delete all --all'

os::cmd::expect_success "oc new-build -D \$'FROM centos:7' --no-output"
os::cmd::expect_success_and_text 'oc get bc/centos -o=jsonpath="{.spec.output.to}"' '^<nil>$'

os::cmd::expect_success 'oc delete all --all'
os::cmd::expect_success 'oc process -f examples/sample-app/application-template-dockerbuild.json -l build=docker | oc create -f -'
os::cmd::expect_success 'oc get buildConfigs'
Expand Down