Skip to content

Commit

Permalink
feat: fix apps deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
raulb committed Feb 19, 2022
1 parent b806beb commit 2464f3b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
40 changes: 23 additions & 17 deletions cmd/meroxa/root/apps/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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, "./...")
}
Expand All @@ -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("MEROXA_ACCESS_TOKEN=%s", accessToken))
cmd.Env = append(cmd.Env, fmt.Sprintf("MEROXA_REFRESH_TOKEN=%s", refreshToken))

stdout, err := cmd.CombinedOutput()
if err != nil {
l.Errorf(ctx, string(stdout))
return err
}

Expand All @@ -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}}

Expand Down
3 changes: 2 additions & 1 deletion cmd/meroxa/root/apps/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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))
Expand Down
2 changes: 0 additions & 2 deletions vendor/github.com/meroxa/turbine/deploy/deploy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/github.com/meroxa/turbine/deploy/template/Dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2464f3b

Please sign in to comment.