diff --git a/cmd/meroxa/root/apps/common.go b/cmd/meroxa/root/apps/common.go index 14fc77015..82bd5e360 100644 --- a/cmd/meroxa/root/apps/common.go +++ b/cmd/meroxa/root/apps/common.go @@ -5,11 +5,11 @@ import ( "encoding/base64" "encoding/json" "fmt" + "github.com/meroxa/cli/cmd/meroxa/global" "io" "os" "os/exec" "path" - "path/filepath" "strings" "time" @@ -33,7 +33,7 @@ func buildGoApp(ctx context.Context, l log.Logger, appPath, appName string, plat } if platform { - cmd = exec.Command("go", "build", "--tags", "platform", "-o", "./"+appPath, "./"+appPath+"/...") //nolint:gosec + cmd = exec.Command("go", "build", "--tags", "platform", "-o", appName, "./...") //nolint:gosec } else { cmd = exec.Command("go", "build", "-o", appName, "./...") } @@ -48,11 +48,21 @@ func buildGoApp(ctx context.Context, l log.Logger, appPath, appName string, plat return nil } -func deployApp(ctx context.Context, l log.Logger, projPath, projName string, imageName string) error { +func deployApp(ctx context.Context, l log.Logger, appPath, appName string, imageName string) error { l.Info(ctx, "deploying app...\n") - cmd := exec.Command(projPath+"/"+projName, "--deploy", "--imagename", imageName) + + cmd := exec.Command(appPath+"/"+appName, "--deploy", "--imagename", imageName) + accessToken, refreshToken, err := global.GetUserToken() + if err != nil { + return err + } + cmd.Env = os.Environ() + cmd.Env = append(cmd.Env, fmt.Sprintf("ACCESS_TOKEN=%s", accessToken)) + cmd.Env = append(cmd.Env, fmt.Sprintf("REFRESH_TOKEN=%s", refreshToken)) + stdout, err := cmd.CombinedOutput() if err != nil { + l.Errorf(ctx, string(stdout)) return err } @@ -67,29 +77,25 @@ func buildImage(ctx context.Context, l log.Logger, path string, imageName string if err != nil { l.Errorf(ctx, "unable to init docker client; %s", err) } + + // Generate dockerfile + err = turbine.CreateDockerfile(path) + if err != nil { + return err + } + // Read local Dockerfile tar, err := archive.TarWithOptions(path, &archive.TarOptions{ Compression: archive.Uncompressed, - ExcludePatterns: []string{"simple", ".git", "fixtures"}, + ExcludePatterns: []string{".git", "fixtures"}, }) if err != nil { l.Errorf(ctx, "unable to create tar; %s", err) } - //err = os.Chdir(path) - //if err != nil { - // return err - //} - - // Generate dockerfile - err = turbine.CreateDockerfile(path) - if err != nil { - return err - } - buildOptions := types.ImageBuildOptions{ Context: tar, - Dockerfile: filepath.Join(path, "Dockerfile"), + Dockerfile: "Dockerfile", Remove: true, Tags: []string{imageName}} diff --git a/cmd/meroxa/root/apps/deploy.go b/cmd/meroxa/root/apps/deploy.go index 23a0243e3..ffe0297bd 100644 --- a/cmd/meroxa/root/apps/deploy.go +++ b/cmd/meroxa/root/apps/deploy.go @@ -100,7 +100,7 @@ func (d *Deploy) deployGoApp(ctx context.Context) error { d.logger.Errorf(ctx, "unable to push image; %q\n%s", fqImageName, err) } - err = buildGoApp(ctx, d.logger, appPath, "", true) + err = buildGoApp(ctx, d.logger, appPath, appName, true) if err != nil { return err } @@ -126,6 +126,7 @@ func (d *Deploy) deployJSApp(ctx context.Context) error { stdout, err := cmd.CombinedOutput() if err != nil { + d.logger.Error(ctx, string(stdout)) return err } d.logger.Info(ctx, string(stdout)) diff --git a/vendor/github.com/meroxa/turbine/deploy/deploy.go b/vendor/github.com/meroxa/turbine/deploy/deploy.go index 77bd16774..cbda971b9 100644 --- a/vendor/github.com/meroxa/turbine/deploy/deploy.go +++ b/vendor/github.com/meroxa/turbine/deploy/deploy.go @@ -36,7 +36,6 @@ var templateFS embed.FS // TurbineDockerfileTrait will be used to replace data evaluations to generate an according Dockerfile type TurbineDockerfileTrait struct { AppName string - AppPath string GoVersion string } @@ -51,7 +50,6 @@ func CreateDockerfile(pwd string) error { dockerfile := TurbineDockerfileTrait{ AppName: appName, - AppPath: pwd, GoVersion: goVersion, } diff --git a/vendor/github.com/meroxa/turbine/deploy/template/Dockerfile b/vendor/github.com/meroxa/turbine/deploy/template/Dockerfile index f17888b1f..c497b140b 100644 --- a/vendor/github.com/meroxa/turbine/deploy/template/Dockerfile +++ b/vendor/github.com/meroxa/turbine/deploy/template/Dockerfile @@ -1,14 +1,14 @@ FROM golang:{{.GoVersion}} as build-env WORKDIR /go/src/app -COPY .. . +COPY . . ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64 -RUN go install --tags=platform -mod=vendor {{.AppPath}}... +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/{{.AppPath}}/app.json /app +COPY --from=build-env /go/src/app/app.json /app ENTRYPOINT ["/app/{{.AppName}}", "--serve"] \ No newline at end of file