github.com/ahmet2mir/goreleaser@v0.180.3-0.20210927151101-8e5ee5a9b8c5/internal/pipe/docker/api_docker.go (about) 1 package docker 2 3 import ( 4 "context" 5 "fmt" 6 ) 7 8 func init() { 9 registerManifester(useDocker, dockerManifester{}) 10 11 registerImager(useDocker, dockerImager{}) 12 registerImager(useBuildx, dockerImager{ 13 buildx: true, 14 }) 15 registerImager(useBuildPacks, buildPackImager{}) 16 } 17 18 type dockerManifester struct{} 19 20 func (m dockerManifester) Create(ctx context.Context, manifest string, images, flags []string) error { 21 _ = runCommand(ctx, ".", "docker", "manifest", "rm", manifest) 22 23 args := []string{"manifest", "create", manifest} 24 args = append(args, images...) 25 args = append(args, flags...) 26 27 if err := runCommand(ctx, ".", "docker", args...); err != nil { 28 return fmt.Errorf("failed to create %s: %w", manifest, err) 29 } 30 return nil 31 } 32 33 func (m dockerManifester) Push(ctx context.Context, manifest string, flags []string) error { 34 args := []string{"manifest", "push", manifest} 35 args = append(args, flags...) 36 if err := runCommand(ctx, ".", "docker", args...); err != nil { 37 return fmt.Errorf("failed to push %s: %w", manifest, err) 38 } 39 return nil 40 } 41 42 type dockerImager struct { 43 buildx bool 44 } 45 46 func (i dockerImager) Push(ctx context.Context, image string, flags []string) error { 47 if err := runCommand(ctx, ".", "docker", "push", image); err != nil { 48 return fmt.Errorf("failed to push %s: %w", image, err) 49 } 50 return nil 51 } 52 53 func (i dockerImager) Build(ctx context.Context, root string, images, flags []string) error { 54 if err := runCommand(ctx, root, "docker", i.buildCommand(images, flags)...); err != nil { 55 return fmt.Errorf("failed to build %s: %w", images[0], err) 56 } 57 return nil 58 } 59 60 func (i dockerImager) buildCommand(images, flags []string) []string { 61 base := []string{"build", "."} 62 if i.buildx { 63 base = []string{"buildx", "build", ".", "--load"} 64 } 65 for _, image := range images { 66 base = append(base, "-t", image) 67 } 68 base = append(base, flags...) 69 return base 70 }