Make it consistent between newapp and newbuild
| ... | ... |
@@ -576,7 +576,9 @@ Create a new build configuration |
| 576 | 576 |
|
| 577 | 577 |
[options="nowrap"] |
| 578 | 578 |
---- |
| 579 |
- # Create a build config based on the source code in the current git repository (with a public remote) and a Docker image |
|
| 579 |
+ |
|
| 580 |
+ # Create a build config based on the source code in the current git repository (with a public |
|
| 581 |
+ # remote) and a Docker image |
|
| 580 | 582 |
$ openshift cli new-build . --docker-image=repo/langimage |
| 581 | 583 |
|
| 582 | 584 |
# Create a NodeJS build config based on the provided [image]~[source code] combination |
| ... | ... |
@@ -588,8 +590,8 @@ Create a new build configuration |
| 588 | 588 |
# Create a build config using a Dockerfile specified as an argument |
| 589 | 589 |
$ openshift cli new-build -D $'FROM centos:7\nRUN yum install -y httpd' |
| 590 | 590 |
|
| 591 |
- # Create a build config from a remote repository and add custom environment variables into resulting image |
|
| 592 |
- $ openshift cli new-build https://github.com/openshift/ruby-hello-world --env=RACK_ENV=development |
|
| 591 |
+ # Create a build config from a remote repository and add custom environment variables |
|
| 592 |
+ $ openshift cli new-build https://github.com/openshift/ruby-hello-world RACK_ENV=development |
|
| 593 | 593 |
---- |
| 594 | 594 |
==== |
| 595 | 595 |
|
| ... | ... |
@@ -490,18 +490,36 @@ func handleRunError(c *cobra.Command, err error, fullName string) error {
|
| 490 | 490 |
err = errs.Errors()[0] |
| 491 | 491 |
} |
| 492 | 492 |
} |
| 493 |
- if e, ok := err.(newcmd.ErrRequiresExplicitAccess); ok {
|
|
| 494 |
- return fmt.Errorf("installing %q requires that you grant the image access to run with your credentials; if you trust the provided image, include the flag --grant-install-rights", e.Match.Value)
|
|
| 493 |
+ switch t := err.(type) {
|
|
| 494 |
+ case newcmd.ErrRequiresExplicitAccess: |
|
| 495 |
+ return fmt.Errorf("installing %q requires that you grant the image access to run with your credentials; if you trust the provided image, include the flag --grant-install-rights", t.Match.Value)
|
|
| 496 |
+ case newapp.ErrNoMatch: |
|
| 497 |
+ return fmt.Errorf(`%[1]v |
|
| 498 |
+ |
|
| 499 |
+The '%[2]s' command will match arguments to the following types: |
|
| 500 |
+ |
|
| 501 |
+ 1. Images tagged into image streams in the current project or the 'openshift' project |
|
| 502 |
+ - if you don't specify a tag, we'll add ':latest' |
|
| 503 |
+ 2. Images in the Docker Hub, on remote registries, or on the local Docker engine |
|
| 504 |
+ 3. Templates in the current project or the 'openshift' project |
|
| 505 |
+ 4. Git repository URLs or local paths that point to Git repositories |
|
| 506 |
+ |
|
| 507 |
+--allow-missing-images can be used to point to an image that does not exist yet |
|
| 508 |
+or is only on the local system. |
|
| 509 |
+ |
|
| 510 |
+See '%[2]s' for examples. |
|
| 511 |
+`, t, c.Name()) |
|
| 495 | 512 |
} |
| 496 |
- if err == errNoTokenAvailable {
|
|
| 513 |
+ switch err {
|
|
| 514 |
+ case errNoTokenAvailable: |
|
| 497 | 515 |
// TODO: improve by allowing token generation |
| 498 | 516 |
return fmt.Errorf("to install components you must be logged in with an OAuth token (instead of only a certificate)")
|
| 499 |
- } |
|
| 500 |
- if err == newcmd.ErrNoInputs {
|
|
| 517 |
+ case newcmd.ErrNoInputs: |
|
| 501 | 518 |
// TODO: suggest things to the user |
| 502 | 519 |
return cmdutil.UsageError(c, newAppNoInput, fullName) |
| 520 |
+ default: |
|
| 521 |
+ return err |
|
| 503 | 522 |
} |
| 504 |
- return err |
|
| 505 | 523 |
} |
| 506 | 524 |
|
| 507 | 525 |
func printHumanReadableQueryResult(r *newcmd.QueryResult, out io.Writer, fullName string) error {
|
| ... | ... |
@@ -12,6 +12,7 @@ import ( |
| 12 | 12 |
|
| 13 | 13 |
buildapi "github.com/openshift/origin/pkg/build/api" |
| 14 | 14 |
"github.com/openshift/origin/pkg/cmd/util/clientcmd" |
| 15 |
+ newapp "github.com/openshift/origin/pkg/generate/app" |
|
| 15 | 16 |
newcmd "github.com/openshift/origin/pkg/generate/app/cmd" |
| 16 | 17 |
) |
| 17 | 18 |
|
| ... | ... |
@@ -30,7 +31,9 @@ remote repository that the server can see. |
| 30 | 30 |
Once the build configuration is created a new build will be automatically triggered. |
| 31 | 31 |
You can use '%[1]s status' to check the progress.` |
| 32 | 32 |
|
| 33 |
- newBuildExample = ` # Create a build config based on the source code in the current git repository (with a public remote) and a Docker image |
|
| 33 |
+ newBuildExample = ` |
|
| 34 |
+ # Create a build config based on the source code in the current git repository (with a public |
|
| 35 |
+ # remote) and a Docker image |
|
| 34 | 36 |
$ %[1]s new-build . --docker-image=repo/langimage |
| 35 | 37 |
|
| 36 | 38 |
# Create a NodeJS build config based on the provided [image]~[source code] combination |
| ... | ... |
@@ -42,8 +45,25 @@ You can use '%[1]s status' to check the progress.` |
| 42 | 42 |
# Create a build config using a Dockerfile specified as an argument |
| 43 | 43 |
$ %[1]s new-build -D $'FROM centos:7\nRUN yum install -y httpd' |
| 44 | 44 |
|
| 45 |
- # Create a build config from a remote repository and add custom environment variables into resulting image |
|
| 46 |
- $ %[1]s new-build https://github.com/openshift/ruby-hello-world --env=RACK_ENV=development` |
|
| 45 |
+ # Create a build config from a remote repository and add custom environment variables |
|
| 46 |
+ $ %[1]s new-build https://github.com/openshift/ruby-hello-world RACK_ENV=development` |
|
| 47 |
+ |
|
| 48 |
+ newBuildNoInput = `You must specify one or more images, image streams, or source code locations to create a build. |
|
| 49 |
+ |
|
| 50 |
+To build from an existing image stream tag or Docker image, provide the name of the image and |
|
| 51 |
+the source code location: |
|
| 52 |
+ |
|
| 53 |
+ $ %[1]s new-build openshift/nodejs-010-centos7~https://github.com/openshift/nodejs-ex.git |
|
| 54 |
+ |
|
| 55 |
+If you only specify the source repository location (local or remote), the command will look at |
|
| 56 |
+the repo to determine the type, and then look for a matching image on your server or on the |
|
| 57 |
+default Docker registry. |
|
| 58 |
+ |
|
| 59 |
+ $ %[1]s new-build https://github.com/openshift/nodejs-ex.git |
|
| 60 |
+ |
|
| 61 |
+will look for an image called "nodejs" in your current project, the 'openshift' project, or |
|
| 62 |
+on the Docker Hub. |
|
| 63 |
+` |
|
| 47 | 64 |
) |
| 48 | 65 |
|
| 49 | 66 |
// NewCmdNewBuild implements the OpenShift cli new-build command |
| ... | ... |
@@ -110,16 +130,7 @@ func RunNewBuild(fullName string, f *clientcmd.Factory, out io.Writer, in io.Rea |
| 110 | 110 |
} |
| 111 | 111 |
result, err := config.RunBuilds() |
| 112 | 112 |
if err != nil {
|
| 113 |
- if errs, ok := err.(errors.Aggregate); ok {
|
|
| 114 |
- if len(errs.Errors()) == 1 {
|
|
| 115 |
- err = errs.Errors()[0] |
|
| 116 |
- } |
|
| 117 |
- } |
|
| 118 |
- if err == newcmd.ErrNoInputs {
|
|
| 119 |
- // TODO: suggest things to the user |
|
| 120 |
- return cmdutil.UsageError(c, "You must specify one or more images, image streams and source code locations to create a build configuration.") |
|
| 121 |
- } |
|
| 122 |
- return err |
|
| 113 |
+ return handleBuildError(c, err, fullName) |
|
| 123 | 114 |
} |
| 124 | 115 |
if err := setLabels(config.Labels, result); err != nil {
|
| 125 | 116 |
return err |
| ... | ... |
@@ -146,3 +157,38 @@ func RunNewBuild(fullName string, f *clientcmd.Factory, out io.Writer, in io.Rea |
| 146 | 146 |
|
| 147 | 147 |
return nil |
| 148 | 148 |
} |
| 149 |
+ |
|
| 150 |
+func handleBuildError(c *cobra.Command, err error, fullName string) error {
|
|
| 151 |
+ if err == nil {
|
|
| 152 |
+ return nil |
|
| 153 |
+ } |
|
| 154 |
+ if errs, ok := err.(errors.Aggregate); ok {
|
|
| 155 |
+ if len(errs.Errors()) == 1 {
|
|
| 156 |
+ err = errs.Errors()[0] |
|
| 157 |
+ } |
|
| 158 |
+ } |
|
| 159 |
+ switch t := err.(type) {
|
|
| 160 |
+ case newapp.ErrNoMatch: |
|
| 161 |
+ return fmt.Errorf(`%[1]v |
|
| 162 |
+ |
|
| 163 |
+The '%[2]s' command will match arguments to the following types: |
|
| 164 |
+ |
|
| 165 |
+ 1. Images tagged into image streams in the current project or the 'openshift' project |
|
| 166 |
+ - if you don't specify a tag, we'll add ':latest' |
|
| 167 |
+ 2. Images in the Docker Hub, on remote registries, or on the local Docker engine |
|
| 168 |
+ 3. Git repository URLs or local paths that point to Git repositories |
|
| 169 |
+ |
|
| 170 |
+--allow-missing-images can be used to point to an image that does not exist yet |
|
| 171 |
+or is only on the local system. |
|
| 172 |
+ |
|
| 173 |
+See '%[2]s' for examples. |
|
| 174 |
+`, t, c.Name()) |
|
| 175 |
+ } |
|
| 176 |
+ switch err {
|
|
| 177 |
+ case newcmd.ErrNoInputs: |
|
| 178 |
+ // TODO: suggest things to the user |
|
| 179 |
+ return cmdutil.UsageError(c, newBuildNoInput, fullName) |
|
| 180 |
+ default: |
|
| 181 |
+ return err |
|
| 182 |
+ } |
|
| 183 |
+} |
| ... | ... |
@@ -14,9 +14,9 @@ type ErrNoMatch struct {
|
| 14 | 14 |
|
| 15 | 15 |
func (e ErrNoMatch) Error() string {
|
| 16 | 16 |
if len(e.qualifier) != 0 {
|
| 17 |
- return fmt.Sprintf("no image or template matched %q: %s, specify allow-missing-images to use this image name.", e.value, e.qualifier)
|
|
| 17 |
+ return fmt.Sprintf("no match for %q: %s, specify --allow-missing-images to use this image name.", e.value, e.qualifier)
|
|
| 18 | 18 |
} |
| 19 |
- return fmt.Sprintf("no image or template matched %q, specify --allow-missing-images to use this image name.", e.value)
|
|
| 19 |
+ return fmt.Sprintf("no match for %q, specify --allow-missing-images to use this image name.", e.value)
|
|
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 | 22 |
// UsageError is the usage error message returned when no match is found. |
| ... | ... |
@@ -89,7 +89,7 @@ oc delete all -l app=ruby |
| 89 | 89 |
[ "$(oc new-build mysql https://github.com/openshift/ruby-hello-world --binary 2>&1 | grep -F 'specifying binary builds and source repositories at the same time is not allowed')" ] |
| 90 | 90 |
|
| 91 | 91 |
# do not allow use of non-existent image (should fail) |
| 92 |
-[ "$(oc new-app openshift/bogusImage https://github.com/openshift/ruby-hello-world.git -o yaml 2>&1 | grep "no image or template matched")" ] |
|
| 92 |
+[ "$(oc new-app openshift/bogusImage https://github.com/openshift/ruby-hello-world.git -o yaml 2>&1 | grep "no match for")" ] |
|
| 93 | 93 |
# allow use of non-existent image (should succeed) |
| 94 | 94 |
[ "$(oc new-app openshift/bogusImage https://github.com/openshift/ruby-hello-world.git -o yaml --allow-missing-images)" ] |
| 95 | 95 |
|