Repository: goreleaser/goreleaser
Pull request #1276 (2019-12-26 16:17:13)

feat: moved sign log to info and stream output
refs #1227

cc/ @joemiller 

codecov-io: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1276?src=pr&el=h1) Report
> Merging [#1276](https://codecov.io/gh/goreleaser/goreleaser/pull/1276?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/c5e9ba938da9fc103a3f1cdcd296a4c5fc1fec60?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/1276/graphs/tree.svg?width=650&token=3bJvv6b7hN&height=150&src=pr)](https://codecov.io/gh/goreleaser/goreleaser/pull/1276?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #1276   +/-   ##
=======================================
  Coverage   83.75%   83.75%           
=======================================
  Files          58       58           
  Lines        3342     3342           
=======================================
  Hits         2799     2799           
  Misses        461      461           
  Partials       82       82
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/1276?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [internal/pipe/sign/sign.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1276/diff?src=pr&el=tree#diff-aW50ZXJuYWwvcGlwZS9zaWduL3NpZ24uZ28=) | `94.87% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1276?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1276?src=pr&el=footer). Last update [c5e9ba9...e419088](https://codecov.io/gh/goreleaser/goreleaser/pull/1276?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/go.mod b/go.mod
index fcdefd7f..f112fd04 100644
--- a/go.mod
+++ b/go.mod
@@ -7,6 +7,7 @@ require (
 	github.com/Masterminds/semver/v3 v3.0.3
 	github.com/apex/log v1.1.1
 	github.com/aws/aws-sdk-go v1.25.11
+	github.com/caarlos0/cmdstream v0.1.0
 	github.com/caarlos0/ctrlc v1.0.0
 	github.com/campoy/unique v0.0.0-20180121183637-88950e537e7e
 	github.com/fatih/color v1.7.0
diff --git a/go.sum b/go.sum
index 8b841321..6496adbc 100644
--- a/go.sum
+++ b/go.sum
@@ -44,6 +44,8 @@ github.com/aws/aws-sdk-go v1.25.11/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpi
 github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I=
 github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb h1:m935MPodAbYS46DG4pJSv7WO+VECIWUQ7OJYSoTrMh4=
 github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb/go.mod h1:PkYb9DJNAwrSvRx5DYA+gUcOIgTGVMNkfSCbZM8cWpI=
+github.com/caarlos0/cmdstream v0.1.0 h1:Y9EOUEp0e7Lh09vaVXq0psc6gqUYXnLzfD+WAciRW50=
+github.com/caarlos0/cmdstream v0.1.0/go.mod h1:JV0/yP9NA7jR+rYk7gDk0K43FxcxaduXpGhYEe8olNc=
 github.com/caarlos0/ctrlc v1.0.0 h1:2DtF8GSIcajgffDFJzyG15vO+1PuBWOMUdFut7NnXhw=
 github.com/caarlos0/ctrlc v1.0.0/go.mod h1:CdXpj4rmq0q/1Eb44M9zi2nKB0QraNKuRGYGrrHhcQw=
 github.com/campoy/unique v0.0.0-20180121183637-88950e537e7e h1:V9a67dfYqPLAvzk5hMQOXYJlZ4SLIXgyKIE+ZiHzgGQ=
diff --git a/internal/logext/writer.go b/internal/logext/writer.go
new file mode 100644
index 00000000..935e8fc6
--- /dev/null
+++ b/internal/logext/writer.go
@@ -0,0 +1,18 @@
+package logext
+
+import "github.com/apex/log"
+
+// Writer writes with log.Info
+type Writer struct {
+	ctx *log.Entry
+}
+
+// NewWriter creates a new log writer
+func NewWriter(ctx *log.Entry) Writer {
+	return Writer{ctx: ctx}
+}
+
+func (t Writer) Write(p []byte) (n int, err error) {
+	t.ctx.Info(string(p))
+	return len(p), nil
+}
diff --git a/internal/pipe/docker/docker.go b/internal/pipe/docker/docker.go
index b4e1981e..1ff46eed 100644
--- a/internal/pipe/docker/docker.go
+++ b/internal/pipe/docker/docker.go
@@ -55,6 +55,11 @@ func (Pipe) Default(ctx *context.Context) error {
 			ctx.Config.Builds[0].Binary,
 		}
 	}
+	if len(ctx.Config.Dockers[0].Builds) == 0 {
+		ctx.Config.Dockers[0].Builds = []string{
+			ctx.Config.Builds[0].ID,
+		}
+	}
 	if ctx.Config.Dockers[0].Dockerfile == "" {
 		ctx.Config.Dockers[0].Dockerfile = "Dockerfile"
 	}
@@ -98,22 +103,24 @@ func doRun(ctx *context.Context) error {
 				}
 				binaryNames[i] = bin
 			}
-			var binaries = ctx.Artifacts.Filter(
-				artifact.And(
-					artifact.ByGoos(docker.Goos),
-					artifact.ByGoarch(docker.Goarch),
-					artifact.ByGoarm(docker.Goarm),
-					artifact.ByType(artifact.Binary),
-					func(a *artifact.Artifact) bool {
-						for _, bin := range binaryNames {
-							if a.ExtraOr("Binary", "").(string) == bin {
-								return true
-							}
+			var filters = []artifact.Filter{
+				artifact.ByGoos(docker.Goos),
+				artifact.ByGoarch(docker.Goarch),
+				artifact.ByGoarm(docker.Goarm),
+				artifact.ByType(artifact.Binary),
+				func(a *artifact.Artifact) bool {
+					for _, bin := range binaryNames {
+						if a.ExtraOr("Binary", "").(string) == bin {
+							return true
 						}
-						return false
-					},
-				),
-			).List()
+					}
+					return false
+				},
+			}
+			if len(docker.Builds) > 0 {
+				filters = append(filters, artifact.ByIDs(docker.Builds...))
+			}
+			var binaries = ctx.Artifacts.Filter(artifact.And(filters...)).List()
 			// TODO: not so good of a check, if one binary match multiple
 			// binaries and the other match none, this will still pass...
 			if len(binaries) != len(docker.Binaries) {
diff --git a/internal/pipe/sign/sign.go b/internal/pipe/sign/sign.go
index ce00ede7..d948a597 100644
--- a/internal/pipe/sign/sign.go
+++ b/internal/pipe/sign/sign.go
@@ -8,8 +8,11 @@ import (
 	"reflect"
 
 	"github.com/apex/log"
+	"github.com/caarlos0/cmdstream"
+
 	"github.com/goreleaser/goreleaser/internal/artifact"
 	"github.com/goreleaser/goreleaser/internal/deprecate"
+	"github.com/goreleaser/goreleaser/internal/logext"
 	"github.com/goreleaser/goreleaser/internal/pipe"
 	"github.com/goreleaser/goreleaser/internal/semerrgroup"
 	"github.com/goreleaser/goreleaser/pkg/config"
@@ -114,10 +117,11 @@ func signone(ctx *context.Context, cfg config.Sign, a *artifact.Artifact) (*arti
 	// tells the scanner to ignore this.
 	// #nosec
 	cmd := exec.CommandContext(ctx, cfg.Cmd, args...)
-	log.WithField("cmd", cmd.Args).Debug("running")
-	output, err := cmd.CombinedOutput()
-	if err != nil {
-		return nil, fmt.Errorf("sign: %s failed with %q", cfg.Cmd, string(output))
+	log.WithField("cmd", cmd.Args).Info("signing")
+	if err := cmdstream.Stream(
+		cmd, logext.NewWriter(log.WithField("cmd", cfg.Cmd)),
+	); err != nil {
+		return nil, fmt.Errorf("sign: %s failed", cfg.Cmd)
 	}
 
 	artifactPathBase, _ := filepath.Split(a.Path)
diff --git a/pkg/config/config.go b/pkg/config/config.go
index da0323bd..e9b3176d 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -276,6 +276,7 @@ type Checksum struct {
 // Docker image config
 type Docker struct {
 	Binaries           []string `yaml:",omitempty"`
+	Builds             []string `yaml:",omitempty"`
 	Goos               string   `yaml:",omitempty"`
 	Goarch             string   `yaml:",omitempty"`
 	Goarm              string   `yaml:",omitempty"`
diff --git a/www/content/docker.md b/www/content/docker.md
index 7fd751c9..04715e98 100644
--- a/www/content/docker.md
+++ b/www/content/docker.md
@@ -50,13 +50,21 @@ dockers:
   -
     # GOOS of the built binary that should be used.
     goos: linux
+
     # GOARCH of the built binary that should be used.
     goarch: amd64
+
     # GOARM of the built binary that should be used.
     goarm: ''
+
     # Name templates of the built binaries that should be used.
     binaries:
     - mybinary
+
+    # Build IDs to gather the binaries from.
+    builds:
+    - mybuild
+
     # Templates of the Docker image names.
     image_templates:
     - "myuser/myimage:latest"
@@ -64,19 +72,23 @@ dockers:
     - "myuser/myimage:{{ .Tag }}-{{ .Env.GO_VERSION }}"
     - "myuser/myimage:v{{ .Major }}"
     - "gcr.io/myuser/myimage:latest"
+
     # Skips the docker push. Could be useful if you also do draft releases.
     # If set to auto, the release will not be pushed to the docker repository
     # in case there is an indicator for prerelease in the tag e.g. v1.0.0-rc1
     # Defaults to false.
     skip_push: false
+
     # Path to the Dockerfile (from the project root).
     dockerfile: Dockerfile
+
     # Template of the docker build flags.
     build_flag_templates:
     - "--label=org.label-schema.schema-version=1.0"
     - "--label=org.label-schema.version={{.Version}}"
     - "--label=org.label-schema.name={{.ProjectName}}"
     - "--build-arg=FOO={{.Env.Bar}}"
+
     # If your Dockerfile copies files other than the binary itself,
     # you should list them here as well.
     # Note that goreleaser will create the same structure inside the temporary


Test patch:
diff --git a/internal/logext/writer_test.go b/internal/logext/writer_test.go
new file mode 100644
index 00000000..d76a6352
--- /dev/null
+++ b/internal/logext/writer_test.go
@@ -0,0 +1,14 @@
+package logext
+
+import (
+	"testing"
+
+	"github.com/apex/log"
+	"github.com/stretchr/testify/require"
+)
+
+func TestWriter(t *testing.T) {
+	l, err := NewWriter(log.WithField("foo", "bar")).Write([]byte("foo bar"))
+	require.NoError(t, err)
+	require.Equal(t, 7, l)
+}
diff --git a/internal/pipe/docker/docker_test.go b/internal/pipe/docker/docker_test.go
index f92120a0..29621779 100644
--- a/internal/pipe/docker/docker_test.go
+++ b/internal/pipe/docker/docker_test.go
@@ -153,6 +153,26 @@ func TestRunPipe(t *testing.T) {
 			assertError:    shouldNotErr,
 			pubAssertError: shouldNotErr,
 		},
+		"valid-with-builds": {
+			dockers: []config.Docker{
+				{
+					ImageTemplates: []string{
+						registry + "goreleaser/test_run_pipe_build:latest",
+					},
+					Goos:       "linux",
+					Goarch:     "amd64",
+					Dockerfile: "testdata/Dockerfile",
+					Binaries:   []string{"mybin"},
+					Builds:     []string{"mybin"},
+				},
+			},
+			expect: []string{
+				registry + "goreleaser/test_run_pipe_build:latest",
+			},
+			assertImageLabels: noLabels,
+			assertError:       shouldNotErr,
+			pubAssertError:    shouldNotErr,
+		},
 		"multiple images with same extra file": {
 			dockers: []config.Docker{
 				{
@@ -583,6 +603,7 @@ func TestRunPipe(t *testing.T) {
 							Type:   artifact.Binary,
 							Extra: map[string]interface{}{
 								"Binary": bin,
+								"ID":     bin,
 							},
 						})
 					}
@@ -707,6 +728,11 @@ func TestDefault(t *testing.T) {
 func TestDefaultBinaries(t *testing.T) {
 	var ctx = &context.Context{
 		Config: config.Project{
+			Builds: []config.Build{
+				{
+					ID: "foo",
+				},
+			},
 			Dockers: []config.Docker{
 				{
 					Binaries: []string{"foo"},
@@ -715,7 +741,7 @@ func TestDefaultBinaries(t *testing.T) {
 		},
 	}
 	assert.NoError(t, Pipe{}.Default(ctx))
-	assert.Len(t, ctx.Config.Dockers, 1)
+	require.Len(t, ctx.Config.Dockers, 1)
 	var docker = ctx.Config.Dockers[0]
 	assert.Equal(t, "linux", docker.Goos)
 	assert.Equal(t, "amd64", docker.Goarch)
@@ -765,6 +791,7 @@ func TestDefaultSet(t *testing.T) {
 		Config: config.Project{
 			Dockers: []config.Docker{
 				{
+					Builds:     []string{"foo"},
 					Goos:       "windows",
 					Goarch:     "i386",
 					Binaries:   []string{"bar"},
@@ -779,12 +806,18 @@ func TestDefaultSet(t *testing.T) {
 	assert.Equal(t, "windows", docker.Goos)
 	assert.Equal(t, "i386", docker.Goarch)
 	assert.Equal(t, "bar", docker.Binaries[0])
+	assert.Equal(t, "foo", docker.Builds[0])
 	assert.Equal(t, "Dockerfile.foo", docker.Dockerfile)
 }
 
 func Test_processImageTemplates(t *testing.T) {
 	var ctx = &context.Context{
 		Config: config.Project{
+			Builds: []config.Build{
+				{
+					ID: "default",
+				},
+			},
 			Dockers: []config.Docker{
 				{
 					Binaries:   []string{"foo"},