From 60901d31f38db4fede96057a3586f9a444b6b3d0 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 11 Sep 2017 23:42:36 -0300 Subject: [PATCH] improvements --- .goreleaser.yml | 8 ++------ config/config.go | 4 ++-- pipeline/defaults/defaults.go | 15 +++++++++++++++ pipeline/docker/docker.go | 16 ++++++---------- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index cd70c0a22..b1d277187 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -13,12 +13,8 @@ builds: # - arm64 checksum: name_template: '{{ .ProjectName }}_checksums.txt' -docker: - - goos: linux - goarch: amd64 - binary: goreleaser - dockerfile: Dockerfile - image: caarlos0/goreleaser +dockers: + - image: goreleaser/goreleaser archive: name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' replacements: diff --git a/config/config.go b/config/config.go index 867690955..995657c37 100644 --- a/config/config.go +++ b/config/config.go @@ -183,7 +183,7 @@ type Project struct { Snapcraft Snapcraft `yaml:",omitempty"` Snapshot Snapshot `yaml:",omitempty"` Checksum Checksum `yaml:",omitempty"` - Docker []Docker `yaml:",omitempty"` + Dockers []Docker `yaml:",omitempty"` // this is a hack ¯\_(ツ)_/¯ SingleBuild Build `yaml:"build,omitempty"` @@ -245,7 +245,7 @@ func checkOverflows(config Project) error { } overflow.check(config.Snapshot.XXX, "snapshot") overflow.check(config.Checksum.XXX, "checksum") - for i, docker := range config.Docker { + for i, docker := range config.Dockers { overflow.check(docker.XXX, fmt.Sprintf("docker[%d]", i)) } return overflow.err() diff --git a/pipeline/defaults/defaults.go b/pipeline/defaults/defaults.go index 5f6a8070c..b3715f7c6 100644 --- a/pipeline/defaults/defaults.go +++ b/pipeline/defaults/defaults.go @@ -57,6 +57,21 @@ func (Pipe) Run(ctx *context.Context) error { } ctx.Config.Brew.Install = strings.Join(installs, "\n") } + if len(ctx.Config.Dockers) == 1 { + if ctx.Config.Dockers[0].Goos == "" { + ctx.Config.Dockers[0].Goos = "linux" + } + if ctx.Config.Dockers[0].Goarch == "" { + ctx.Config.Dockers[0].Goarch = "amd64" + } + if ctx.Config.Dockers[0].Binary == "" { + ctx.Config.Dockers[0].Binary = ctx.Config.Builds[0].Binary + } + if ctx.Config.Dockers[0].Dockerfile == "" { + ctx.Config.Dockers[0].Dockerfile = "Dockerfile" + } + } + err := setArchiveDefaults(ctx) log.WithField("config", ctx.Config).Debug("defaults set") return err diff --git a/pipeline/docker/docker.go b/pipeline/docker/docker.go index b1b1c7442..250765433 100644 --- a/pipeline/docker/docker.go +++ b/pipeline/docker/docker.go @@ -25,13 +25,13 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) (err error) { - if ctx.Config.Docker[0].Image == "" { + if ctx.Config.Dockers[0].Image == "" { return pipeline.Skip("docker section is not configured") } if ctx.Config.Release.Draft { return pipeline.Skip("release is marked as draft") } - for _, docker := range ctx.Config.Docker { + for _, docker := range ctx.Config.Dockers { var imagePlatform = docker.Goos + docker.Goarch + docker.Goarm for platform, groups := range ctx.Binaries { if platform != imagePlatform { @@ -53,14 +53,10 @@ func (Pipe) Run(ctx *context.Context) (err error) { return nil } -func processDocker(ctx *context.Context, docker config.Docker) error { - -} - func doRun(ctx *context.Context, folder string, docker config.Docker, binary context.Binary) error { var root = filepath.Join(ctx.Config.Dist, folder) var dockerfile = filepath.Join(root, "Dockerfile") - var image = fmt.Sprintf("%s:%s", docker.Image, ctx.Version) + var image = fmt.Sprintf("%s:%s", docker.Image, ctx.Git.CurrentTag) bts, err := ioutil.ReadFile(docker.Dockerfile) if err != nil { @@ -69,7 +65,7 @@ func doRun(ctx *context.Context, folder string, docker config.Docker, binary con if err := ioutil.WriteFile(dockerfile, bts, 0755); err != nil { return err } - log.WithField("file", dockerfile).Info("wrote dockerfile") + log.WithField("file", dockerfile).Debug("wrote dockerfile") if err := dockerBuild(root, image); err != nil { return err } @@ -83,7 +79,7 @@ func doRun(ctx *context.Context, folder string, docker config.Docker, binary con } func dockerBuild(root, image string) error { - log.Infof("building docker image: %s", image) + log.WithField("image", image).Info("building docker image") var cmd = exec.Command("docker", "build", "-t", image, root) log.WithField("cmd", cmd).Debug("executing") out, err := cmd.CombinedOutput() @@ -95,7 +91,7 @@ func dockerBuild(root, image string) error { } func dockerPush(image string) error { - log.Infof("pushing docker image: %s", image) + log.WithField("image", image).Info("pushing docker image") var cmd = exec.Command("docker", "push", image) log.WithField("cmd", cmd).Debug("executing") out, err := cmd.CombinedOutput()