1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

feat: docker in parallel

This commit is contained in:
Carlos Alexandro Becker 2017-12-25 23:27:06 -02:00
parent 60001bf63c
commit 32ca896a24
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 36 additions and 26 deletions

View File

@ -141,6 +141,8 @@ func And(filters ...Filter) Filter {
// is accepted.
// You can compose filters by using the And and Or filters.
func (artifacts *Artifacts) Filter(filter Filter) Artifacts {
// TODO: this could be done lazily and the real job could be done in the
// #List() method maybe?
var result = New()
for _, a := range artifacts.items {
if filter(a) {

View File

@ -12,6 +12,7 @@ import (
"github.com/apex/log"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
@ -69,31 +70,40 @@ func (Pipe) Run(ctx *context.Context) error {
}
func doRun(ctx *context.Context) error {
// TODO: could be done in parallel.
var g errgroup.Group
sem := make(chan bool, ctx.Parallelism)
for _, docker := range ctx.Config.Dockers {
log.WithField("docker", docker).Debug("looking for binaries matching")
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 {
return a.Extra["Binary"] == docker.Binary
},
),
).List()
if len(binaries) == 0 {
log.Warn("no binaries found")
}
for _, binary := range binaries {
var err = process(ctx, docker, binary)
if err != nil && !pipeline.IsSkip(err) {
return err
docker := docker
sem <- true
g.Go(func() error {
defer func() {
<-sem
}()
log.WithField("docker", docker).Debug("looking for binaries matching")
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 {
return a.Extra["Binary"] == docker.Binary
},
),
).List()
if len(binaries) == 0 {
log.Warn("no binaries found")
}
}
for _, binary := range binaries {
var err = process(ctx, docker, binary)
if err != nil {
return err
}
}
return nil
})
}
return nil
return g.Wait()
}
func tagName(ctx *context.Context, docker config.Docker) (string, error) {
@ -167,10 +177,8 @@ func link(src, dest string) error {
func publish(ctx *context.Context, docker config.Docker, image, latest string) error {
// TODO: improve this so it can log it to stdout
if !ctx.Publish {
return pipeline.Skip("--skip-publish is set")
}
if ctx.Config.Release.Draft {
return pipeline.Skip("release is marked as draft")
log.Warn("skipping push because --skip-publish is set")
return nil
}
if err := dockerPush(ctx, image); err != nil {
return err