1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/internal/pipe/docker/api_buildpack.go
Erkan Zileli 5ea003c6f6
feat(docker): add buildpacks support (#2461)
* feat(docker): add buildpacks support

Signed-off-by: Erkan Zileli <erkanzileli@gmail.com>

* fix: move buildpacker imager code into own go file

Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>

* fix: use docker imager push method for buildpack imager push

Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>

* fix: return statement

Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>

* move test into api_buildback_test

Signed-off-by: Furkan <furkan.turkal@trendyol.com>

* fix: use buildpacks instead of buildpack

Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>

* fix(lint): fix lint issue

* fix(buildpacks): use cwd instead of root directory

* doc: add how to use a custom buildpack document

Signed-off-by: Erkan Zileli <erkan.zileli@trendyol.com>

* fix(doc): update docs as suggested

Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

Co-authored-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>
Co-authored-by: Furkan <furkan.turkal@trendyol.com>
Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2021-09-11 02:21:33 +00:00

41 lines
980 B
Go

package docker
import (
"context"
"fmt"
"strings"
)
type buildPackImager struct{}
func (i buildPackImager) Push(ctx context.Context, image string, flags []string) error {
return dockerImager{}.Push(ctx, image, flags)
}
func (i buildPackImager) Build(ctx context.Context, root string, images, flags []string) error {
if err := runCommand(ctx, "", "pack", i.buildCommand(images, flags)...); err != nil {
return fmt.Errorf("failed to build %s: %w", images[0], err)
}
return nil
}
func (i buildPackImager) buildCommand(images, flags []string) []string {
base := []string{"build", images[0]}
for j := 1; j < len(images); j++ {
base = append(base, "-t", images[j])
}
builderConfigured := false
for _, flag := range flags {
if strings.HasPrefix(flag, "-B") || strings.HasPrefix(flag, "--builder") {
builderConfigured = true
}
}
if !builderConfigured {
flags = append(flags, "--builder=gcr.io/buildpacks/builder:v1")
}
return append(base, flags...)
}