mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-21 21:07:19 +02:00
refactor: fixed docker and archive pipes
This commit is contained in:
parent
bdacb33cea
commit
e9b276923a
pipeline
@ -103,7 +103,7 @@ func create(ctx *context.Context, artifacts []artifact.Artifact) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.Artifacts.Add(artifact.Artifact{
|
ctx.Artifacts.Add(artifact.Artifact{
|
||||||
Type: artifact.Uploadable,
|
Type: artifact.UploadableArchive,
|
||||||
Name: folder + "." + format,
|
Name: folder + "." + format,
|
||||||
Path: archivePath,
|
Path: archivePath,
|
||||||
Goos: artifacts[0].Goos,
|
Goos: artifacts[0].Goos,
|
||||||
@ -116,7 +116,7 @@ func create(ctx *context.Context, artifacts []artifact.Artifact) error {
|
|||||||
func skip(ctx *context.Context, artifacts []artifact.Artifact) error {
|
func skip(ctx *context.Context, artifacts []artifact.Artifact) error {
|
||||||
for _, a := range artifacts {
|
for _, a := range artifacts {
|
||||||
log.WithField("binary", a.Name).Info("skip archiving")
|
log.WithField("binary", a.Name).Info("skip archiving")
|
||||||
a.Type = artifact.Uploadable
|
a.Type = artifact.UploadableBinary
|
||||||
ctx.Artifacts.Add(a)
|
ctx.Artifacts.Add(a)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -9,11 +9,14 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||||
|
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/config"
|
"github.com/goreleaser/goreleaser/config"
|
||||||
"github.com/goreleaser/goreleaser/context"
|
"github.com/goreleaser/goreleaser/context"
|
||||||
"github.com/goreleaser/goreleaser/pipeline"
|
"github.com/goreleaser/goreleaser/pipeline"
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrNoDocker is shown when docker cannot be found in $PATH
|
// ErrNoDocker is shown when docker cannot be found in $PATH
|
||||||
@ -26,18 +29,6 @@ func (Pipe) String() string {
|
|||||||
return "creating Docker images"
|
return "creating Docker images"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the pipe
|
|
||||||
func (Pipe) Run(ctx *context.Context) error {
|
|
||||||
if len(ctx.Config.Dockers) == 0 || ctx.Config.Dockers[0].Image == "" {
|
|
||||||
return pipeline.Skip("docker section is not configured")
|
|
||||||
}
|
|
||||||
_, err := exec.LookPath("docker")
|
|
||||||
if err != nil {
|
|
||||||
return ErrNoDocker
|
|
||||||
}
|
|
||||||
return doRun(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default sets the pipe defaults
|
// Default sets the pipe defaults
|
||||||
func (Pipe) Default(ctx *context.Context) error {
|
func (Pipe) Default(ctx *context.Context) error {
|
||||||
for i := range ctx.Config.Dockers {
|
for i := range ctx.Config.Dockers {
|
||||||
@ -64,26 +55,35 @@ func (Pipe) Default(ctx *context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run the pipe
|
||||||
|
func (Pipe) Run(ctx *context.Context) error {
|
||||||
|
if len(ctx.Config.Dockers) == 0 || ctx.Config.Dockers[0].Image == "" {
|
||||||
|
return pipeline.Skip("docker section is not configured")
|
||||||
|
}
|
||||||
|
_, err := exec.LookPath("docker")
|
||||||
|
if err != nil {
|
||||||
|
return ErrNoDocker
|
||||||
|
}
|
||||||
|
return doRun(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func doRun(ctx *context.Context) error {
|
func doRun(ctx *context.Context) error {
|
||||||
for _, docker := range ctx.Config.Dockers {
|
for _, docker := range ctx.Config.Dockers {
|
||||||
var imagePlatform = docker.Goos + docker.Goarch + docker.Goarm
|
var binaries = ctx.Artifacts.Filter(
|
||||||
for platform, groups := range ctx.Binaries {
|
artifact.ByGoos(docker.Goos),
|
||||||
if platform != imagePlatform {
|
artifact.ByGoarch(docker.Goarch),
|
||||||
continue
|
artifact.ByGoarm(docker.Goarm),
|
||||||
}
|
func(a artifact.Artifact) bool {
|
||||||
for folder, binaries := range groups {
|
return a.Name == docker.Binary
|
||||||
|
},
|
||||||
|
).List()
|
||||||
for _, binary := range binaries {
|
for _, binary := range binaries {
|
||||||
if binary.Name != docker.Binary {
|
var err = process(ctx, docker, binary)
|
||||||
continue
|
|
||||||
}
|
|
||||||
var err = process(ctx, folder, docker, binary)
|
|
||||||
if err != nil && !pipeline.IsSkip(err) {
|
if err != nil && !pipeline.IsSkip(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,8 +105,8 @@ func tagName(ctx *context.Context, docker config.Docker) (string, error) {
|
|||||||
return out.String(), err
|
return out.String(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func process(ctx *context.Context, folder string, docker config.Docker, binary context.Binary) error {
|
func process(ctx *context.Context, docker config.Docker, artifact artifact.Artifact) error {
|
||||||
var root = filepath.Join(ctx.Config.Dist, folder)
|
var root = filepath.Dir(artifact.Path)
|
||||||
var dockerfile = filepath.Join(root, filepath.Base(docker.Dockerfile))
|
var dockerfile = filepath.Join(root, filepath.Base(docker.Dockerfile))
|
||||||
tag, err := tagName(ctx, docker)
|
tag, err := tagName(ctx, docker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -143,17 +143,16 @@ func publish(ctx *context.Context, docker config.Docker, image, latest string) e
|
|||||||
if ctx.Config.Release.Draft {
|
if ctx.Config.Release.Draft {
|
||||||
return pipeline.Skip("release is marked as draft")
|
return pipeline.Skip("release is marked as draft")
|
||||||
}
|
}
|
||||||
if err := dockerPush(image); err != nil {
|
if err := dockerPush(ctx, image); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ctx.AddDocker(image)
|
|
||||||
if !docker.Latest {
|
if !docker.Latest {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := dockerTag(image, latest); err != nil {
|
if err := dockerTag(image, latest); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return dockerPush(latest)
|
return dockerPush(ctx, latest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func dockerBuild(root, dockerfile, image string) error {
|
func dockerBuild(root, dockerfile, image string) error {
|
||||||
@ -182,7 +181,7 @@ func dockerTag(image, tag string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dockerPush(image string) error {
|
func dockerPush(ctx *context.Context, image string) error {
|
||||||
log.WithField("image", image).Info("pushing docker image")
|
log.WithField("image", image).Info("pushing docker image")
|
||||||
/* #nosec */
|
/* #nosec */
|
||||||
var cmd = exec.Command("docker", "push", image)
|
var cmd = exec.Command("docker", "push", image)
|
||||||
@ -192,5 +191,10 @@ func dockerPush(image string) error {
|
|||||||
return errors.Wrapf(err, "failed to push docker image: \n%s", string(out))
|
return errors.Wrapf(err, "failed to push docker image: \n%s", string(out))
|
||||||
}
|
}
|
||||||
log.Debugf("docker push output: \n%s", string(out))
|
log.Debugf("docker push output: \n%s", string(out))
|
||||||
|
ctx.Artifacts.Add(artifact.Artifact{
|
||||||
|
Type: artifact.DockerImage,
|
||||||
|
Name: image,
|
||||||
|
// TODO: are the rest of the params relevant here?
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user