From bb837f78cb312fd7c028a4b88d574460482aa51b Mon Sep 17 00:00:00 2001 From: Janelle Tavares Date: Mon, 18 Apr 2022 07:16:30 -0700 Subject: [PATCH] Dockerfile and binary changes to accommodate vendor or no vendor (#320) Dockerfile and binary changes to accommodate vendor or no vendor --- cmd/meroxa/turbine_cli/golang/build.go | 17 ++++++++++++++++- cmd/meroxa/turbine_cli/local_deployment.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- .../turbine-go/deploy/template/Dockerfile | 12 ++---------- .../meroxa/turbine-go/init/template/app.go | 2 +- vendor/modules.txt | 2 +- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/cmd/meroxa/turbine_cli/golang/build.go b/cmd/meroxa/turbine_cli/golang/build.go index 56fc7253b..f9b79e5ec 100644 --- a/cmd/meroxa/turbine_cli/golang/build.go +++ b/cmd/meroxa/turbine_cli/golang/build.go @@ -3,6 +3,7 @@ package turbinego import ( "context" "fmt" + "os" "os/exec" "github.com/meroxa/cli/log" @@ -24,5 +25,19 @@ func BuildBinary(ctx context.Context, l log.Logger, appPath, appName string, pla l.Errorf(ctx, "%s", string(stdout)) return fmt.Errorf("build failed") } - return err + return buildForCrossCompile(ctx, l, appPath, appName) +} + +func buildForCrossCompile(ctx context.Context, l log.Logger, appPath, appName string) error { + cmd := exec.Command("go", "build", "--tags", "platform", "-o", appName+".cross", "./...") //nolint:gosec + cmd.Env = os.Environ() + cmd.Env = append(cmd.Env, "CGO_ENABLED=0", "GOOS=linux", "GOARCH=amd64") + cmd.Dir = appPath + + stdout, err := cmd.CombinedOutput() + if err != nil { + l.Errorf(ctx, "%s", string(stdout)) + return fmt.Errorf("cross compile failed") + } + return nil } diff --git a/cmd/meroxa/turbine_cli/local_deployment.go b/cmd/meroxa/turbine_cli/local_deployment.go index 6aba22e9d..490bd9cbb 100644 --- a/cmd/meroxa/turbine_cli/local_deployment.go +++ b/cmd/meroxa/turbine_cli/local_deployment.go @@ -121,7 +121,7 @@ func (ld *LocalDeploy) buildImage(ctx context.Context, l log.Logger, pwd, imageN } dockerBuildOutput := buf.String() - re := regexp.MustCompile(`{"errorDetail":{"message":"([^"]+)"}`) + re := regexp.MustCompile(`{"errorDetail":{[^}]*"message":"([^"]+)"}`) matches := re.FindAllStringSubmatch(dockerBuildOutput, -1) if len(matches) != 0 { const subMatchArraySize = 2 diff --git a/go.mod b/go.mod index 15ad28daf..109204c6b 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/briandowns/spinner v1.18.1 github.com/docker/docker v20.10.12+incompatible github.com/mattn/go-shellwords v1.0.12 - github.com/meroxa/turbine-go v0.0.0-20220415203703-5ab9fcaf547d + github.com/meroxa/turbine-go v0.0.0-20220418141359-a37ec2862d9a github.com/volatiletech/null/v8 v8.1.2 ) diff --git a/go.sum b/go.sum index 546e7643e..1f644083c 100644 --- a/go.sum +++ b/go.sum @@ -576,8 +576,8 @@ github.com/meroxa/funtime v0.0.0-20220113012133-85e6e898fc73/go.mod h1:K2y2GvcA4 github.com/meroxa/meroxa-go v0.0.0-20220208195203-71ddc3133fab/go.mod h1:HDFszURCM1cOpKE699o5Hs0T2tEIXqY+vFcsur3RiwY= github.com/meroxa/meroxa-go v0.0.0-20220415221139-f31436f83dca h1:HTg9REXt9NqbX2syACtpUEwF/unzwWRjG9AkSaqcnLc= github.com/meroxa/meroxa-go v0.0.0-20220415221139-f31436f83dca/go.mod h1:BsqYa9jqfyGOAgfkggfK567b2Ahkb+RCH3lXDQGgrh8= -github.com/meroxa/turbine-go v0.0.0-20220415203703-5ab9fcaf547d h1:JWJ0rrFmm9zV3WMMm3hIXS0Ebegm129SVs3zPcFi2Kk= -github.com/meroxa/turbine-go v0.0.0-20220415203703-5ab9fcaf547d/go.mod h1:F4ODyjX+tn5dYFRc1bQlHLUnTtlJIxs09AKHqfCD5Cg= +github.com/meroxa/turbine-go v0.0.0-20220418141359-a37ec2862d9a h1:wcfOhNkl719CrPe8OmgiZInm448enMDrOwr/pBy5/7w= +github.com/meroxa/turbine-go v0.0.0-20220418141359-a37ec2862d9a/go.mod h1:F4ODyjX+tn5dYFRc1bQlHLUnTtlJIxs09AKHqfCD5Cg= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/pkcs11 v1.0.3/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible/go.mod h1:8AuVvqP/mXw1px98n46wfvcGfQ4ci2FwoAjKYxuo3Z4= diff --git a/vendor/github.com/meroxa/turbine-go/deploy/template/Dockerfile b/vendor/github.com/meroxa/turbine-go/deploy/template/Dockerfile index c497b140b..8181e0bad 100644 --- a/vendor/github.com/meroxa/turbine-go/deploy/template/Dockerfile +++ b/vendor/github.com/meroxa/turbine-go/deploy/template/Dockerfile @@ -1,14 +1,6 @@ -FROM golang:{{.GoVersion}} as build-env - -WORKDIR /go/src/app -COPY . . - -ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64 -RUN go install --tags=platform -mod=vendor ./... - FROM gcr.io/distroless/static USER nonroot:nonroot WORKDIR /app -COPY --from=build-env /go/bin/* /app -COPY --from=build-env /go/src/app/app.json /app +COPY app.json /app +COPY {{.AppName}}.cross {{.AppName}} ENTRYPOINT ["/app/{{.AppName}}", "--serve"] \ No newline at end of file diff --git a/vendor/github.com/meroxa/turbine-go/init/template/app.go b/vendor/github.com/meroxa/turbine-go/init/template/app.go index 9ede99b8c..ea3da0046 100644 --- a/vendor/github.com/meroxa/turbine-go/init/template/app.go +++ b/vendor/github.com/meroxa/turbine-go/init/template/app.go @@ -75,7 +75,7 @@ func (f Anonymize) Process(stream []turbine.Record) ([]turbine.Record, []turbine for i, r := range stream { e := fmt.Sprintf("%s", r.Payload.Get("customer_email")) if e == "" { - log.Println("unable to find customer_email value in %d record", i) + log.Printf("unable to find customer_email value in %d record\n", i) break } hashedEmail := consistentHash(e) diff --git a/vendor/modules.txt b/vendor/modules.txt index 53b420cc0..066d1b8d3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -190,7 +190,7 @@ github.com/mattn/go-shellwords ## explicit; go 1.17 github.com/meroxa/meroxa-go/pkg/meroxa github.com/meroxa/meroxa-go/pkg/mock -# github.com/meroxa/turbine-go v0.0.0-20220415203703-5ab9fcaf547d +# github.com/meroxa/turbine-go v0.0.0-20220418141359-a37ec2862d9a ## explicit; go 1.17 github.com/meroxa/turbine-go/deploy github.com/meroxa/turbine-go/init