1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-26 04:22:05 +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. // is accepted.
// You can compose filters by using the And and Or filters. // You can compose filters by using the And and Or filters.
func (artifacts *Artifacts) Filter(filter Filter) Artifacts { 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() var result = New()
for _, a := range artifacts.items { for _, a := range artifacts.items {
if filter(a) { if filter(a) {

View File

@ -12,6 +12,7 @@ import (
"github.com/apex/log" "github.com/apex/log"
"github.com/pkg/errors" "github.com/pkg/errors"
"golang.org/x/sync/errgroup"
"github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
@ -69,31 +70,40 @@ func (Pipe) Run(ctx *context.Context) error {
} }
func doRun(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 { for _, docker := range ctx.Config.Dockers {
log.WithField("docker", docker).Debug("looking for binaries matching") docker := docker
var binaries = ctx.Artifacts.Filter( sem <- true
artifact.And( g.Go(func() error {
artifact.ByGoos(docker.Goos), defer func() {
artifact.ByGoarch(docker.Goarch), <-sem
artifact.ByGoarm(docker.Goarm), }()
artifact.ByType(artifact.Binary), log.WithField("docker", docker).Debug("looking for binaries matching")
func(a artifact.Artifact) bool { var binaries = ctx.Artifacts.Filter(
return a.Extra["Binary"] == docker.Binary artifact.And(
}, artifact.ByGoos(docker.Goos),
), artifact.ByGoarch(docker.Goarch),
).List() artifact.ByGoarm(docker.Goarm),
if len(binaries) == 0 { artifact.ByType(artifact.Binary),
log.Warn("no binaries found") func(a artifact.Artifact) bool {
} return a.Extra["Binary"] == docker.Binary
for _, binary := range binaries { },
var err = process(ctx, docker, binary) ),
if err != nil && !pipeline.IsSkip(err) { ).List()
return err 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) { 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 { func publish(ctx *context.Context, docker config.Docker, image, latest string) error {
// TODO: improve this so it can log it to stdout // TODO: improve this so it can log it to stdout
if !ctx.Publish { if !ctx.Publish {
return pipeline.Skip("--skip-publish is set") log.Warn("skipping push because --skip-publish is set")
} return nil
if ctx.Config.Release.Draft {
return pipeline.Skip("release is marked as draft")
} }
if err := dockerPush(ctx, image); err != nil { if err := dockerPush(ctx, image); err != nil {
return err return err