Răsfoiți Sursa

Rename "--verbose" to the more-apt "--debug", and adjust "docker build" to _always_ capture output (expect when debug mode is enabled and it's piped directly to the user) so that it can be included in the error response if the build fails

Tianon Gravi 9 ani în urmă
părinte
comite
faf6af3ab8

+ 6 - 5
bashbrew/README.md

@@ -21,12 +21,13 @@ COMMANDS:
      from      print FROM for repo:tag
 
 GLOBAL OPTIONS:
-   --verbose, -v            enable more output (esp. "docker build" output) [$BASHBREW_VERBOSE]
+   --debug                  enable more output (esp. all "docker build" output instead of only output on failure) [$BASHBREW_DEBUG]
    --no-sort                do not apply any sorting, even via --build-order
    --constraint value       build constraints (see Constraints in Manifest2822Entry)
    --exclusive-constraints  skip entries which do not have Constraints
-   --library value          where the bodies are buried (default: "/home/jsmith/docker/official-images/library") [$BASHBREW_LIBRARY]
-   --cache value            where the git wizardry is stashed (default: "/home/jsmith/.cache/bashbrew") [$BASHBREW_CACHE]
+   --config value           where default "flags" configuration can be overridden more persistently (default: "/home/tianon/.config/bashbrew") [$BASHBREW_CONFIG]
+   --library value          where the bodies are buried (default: "/home/tianon/docker/official-images/library") [$BASHBREW_LIBRARY]
+   --cache value            where the git wizardry is stashed (default: "/home/tianon/.cache/bashbrew") [$BASHBREW_CACHE]
    --help, -h, -?           show help
 
 ```
@@ -75,7 +76,7 @@ Commands: list
 ApplyConstraints: true
 
 Commands: tag
-Verbose: true
+Debug: true
 ```
 
-In this example, `bashbrew tag` will get both `Namespace` and `Verbose` applied.
+In this example, `bashbrew tag` will get both `Namespace` and `Debug` applied.

+ 0 - 1
bashbrew/go/src/bashbrew/cmd-list.go

@@ -4,7 +4,6 @@ import (
 	"fmt"
 
 	"github.com/codegangsta/cli"
-
 	"github.com/docker-library/go-dockerlibrary/manifest"
 )
 

+ 4 - 4
bashbrew/go/src/bashbrew/config.go

@@ -19,7 +19,7 @@ type FlagsConfigEntry struct {
 
 	Library    string
 	Cache      string
-	Verbose    string
+	Debug      string
 	Unique     string
 	Namespace  string
 	BuildOrder string
@@ -38,8 +38,8 @@ func (dst *FlagsConfigEntry) Apply(src FlagsConfigEntry) {
 	if src.Cache != "" {
 		dst.Cache = src.Cache
 	}
-	if src.Verbose != "" {
-		dst.Verbose = src.Verbose
+	if src.Debug != "" {
+		dst.Debug = src.Debug
 	}
 	if src.Unique != "" {
 		dst.Unique = src.Unique
@@ -63,7 +63,7 @@ func (config FlagsConfigEntry) Vars() map[string]map[string]interface{} {
 		"global": {
 			"library": config.Library,
 			"cache":   config.Cache,
-			"verbose": config.Verbose,
+			"debug":   config.Debug,
 
 			"constraint":            config.Constraints,
 			"exclusive-constraints": config.ExclusiveConstraints,

+ 16 - 5
bashbrew/go/src/bashbrew/docker.go

@@ -2,6 +2,7 @@ package main
 
 import (
 	"bufio"
+	"bytes"
 	"crypto/sha256"
 	"encoding/hex"
 	"fmt"
@@ -11,6 +12,7 @@ import (
 	"path"
 	"strings"
 
+	"github.com/codegangsta/cli"
 	"github.com/docker-library/go-dockerlibrary/manifest"
 )
 
@@ -128,16 +130,25 @@ func dockerBuild(tag string, context io.Reader) error {
 	args = append(args, "-")
 	cmd := exec.Command("docker", args...)
 	cmd.Stdin = context
-	if verboseFlag {
+	if debugFlag {
 		cmd.Stdout = os.Stdout
 		cmd.Stderr = os.Stderr
 		fmt.Printf("$ docker %q\n", args)
+		return cmd.Run()
+	} else {
+		buf := &bytes.Buffer{}
+		cmd.Stdout = buf
+		cmd.Stderr = buf
+		err := cmd.Run()
+		if err != nil {
+			err = cli.NewMultiError(err, fmt.Errorf(`docker build %q output:%s`, args, "\n"+buf.String()))
+		}
+		return err
 	}
-	return cmd.Run()
 }
 
 func dockerTag(tag1 string, tag2 string) error {
-	if verboseFlag {
+	if debugFlag {
 		fmt.Printf("$ docker tag %q %q\n", tag1, tag2)
 	}
 	_, err := exec.Command("docker", "tag", "-f", tag1, tag2).Output()
@@ -150,7 +161,7 @@ func dockerTag(tag1 string, tag2 string) error {
 }
 
 func dockerPush(tag string) error {
-	if verboseFlag {
+	if debugFlag {
 		fmt.Printf("$ docker push %q\n", tag)
 	}
 	_, err := exec.Command("docker", "push", tag).Output()
@@ -163,7 +174,7 @@ func dockerPush(tag string) error {
 }
 
 func dockerPull(tag string) error {
-	if verboseFlag {
+	if debugFlag {
 		fmt.Printf("$ docker pull %q\n", tag)
 	}
 	_, err := exec.Command("docker", "pull", tag).Output()

+ 6 - 7
bashbrew/go/src/bashbrew/main.go

@@ -8,7 +8,6 @@ import (
 	"strings"
 
 	"github.com/codegangsta/cli"
-
 	"pault.ag/go/topsort"
 )
 
@@ -22,8 +21,8 @@ var (
 	constraints          []string
 	exclusiveConstraints bool
 
-	verboseFlag = false
-	noSortFlag  = false
+	debugFlag  = false
+	noSortFlag = false
 )
 
 func initDefaultConfigPath() string {
@@ -133,9 +132,9 @@ func main() {
 	cli.HelpFlag.Name = "help, h, ?" // add "-?" to HelpFlag
 	app.Flags = []cli.Flag{
 		cli.BoolFlag{
-			Name:   "verbose, v",
-			EnvVar: "BASHBREW_VERBOSE",
-			Usage:  `enable more output (esp. "docker build" output)`,
+			Name:   "debug",
+			EnvVar: "BASHBREW_DEBUG",
+			Usage:  `enable more output (esp. all "docker build" output instead of only output on failure)`,
 		},
 		cli.BoolFlag{
 			Name:  "no-sort",
@@ -194,7 +193,7 @@ func main() {
 				return err
 			}
 
-			verboseFlag = c.GlobalBool("verbose")
+			debugFlag = c.GlobalBool("debug")
 			noSortFlag = c.GlobalBool("no-sort")
 
 			constraints = c.GlobalStringSlice("constraint")

+ 1 - 1
test-pr.sh

@@ -32,7 +32,7 @@ if [ -z "$BASHBREW_SECOND_STAGE" ]; then
 		--name "$name" \
 		-e BASHBREW_SECOND_STAGE=1 \
 		-v /var/run/docker.sock:/var/run/docker.sock \
-		-e BASHBREW_VERBOSE \
+		-e BASHBREW_DEBUG \
 		-w /usr/src/pr \
 		bashbrew /usr/src/official-images/test-pr.sh "$pull" "$@"