Skip to content

Commit

Permalink
Clearer logs around building and deploying go apps (#302)
Browse files Browse the repository at this point in the history
* Clearer logs around building and deploying go apps
  • Loading branch information
janelletavares authored Apr 6, 2022
1 parent 4d9e8d9 commit 90d9d08
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cmd/meroxa/root/apps/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (d *Deploy) getPlatformImage(ctx context.Context, appPath string) (string,
return "", err
}

fmt.Print("Getting status for build: ", build.Uuid)
fmt.Printf("Getting status for build: %s ", build.Uuid)
for {
fmt.Printf(".")
b, err := d.client.GetBuild(ctx, build.Uuid)
Expand All @@ -340,7 +340,7 @@ func (d *Deploy) getPlatformImage(ctx context.Context, appPath string) (string,
case "error":
return "", fmt.Errorf("build with uuid %q errored ", b.Uuid)
case "complete":
fmt.Println("Image built! ")
fmt.Println("\nImage built! ")
return build.Image, nil
}
time.Sleep(pollDuration)
Expand Down
9 changes: 6 additions & 3 deletions cmd/meroxa/turbine_cli/golang/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package turbinego

import (
"context"
"fmt"
"os/exec"

turbinecli "github.com/meroxa/cli/cmd/meroxa/turbine_cli"

"github.com/meroxa/cli/log"
)

Expand All @@ -20,6 +19,10 @@ func BuildBinary(ctx context.Context, l log.Logger, appPath, appName string, pla
}
cmd.Dir = appPath

_, err := turbinecli.RunCmdWithErrorDetection(ctx, cmd, l)
stdout, err := cmd.CombinedOutput()
if err != nil {
l.Errorf(ctx, "%s", string(stdout))
return fmt.Errorf("build failed")
}
return err
}
17 changes: 10 additions & 7 deletions cmd/meroxa/turbine_cli/golang/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ func RunDeployApp(ctx context.Context, l log.Logger, appPath, appName, imageName
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("ACCESS_TOKEN=%s", accessToken), fmt.Sprintf("REFRESH_TOKEN=%s", refreshToken))

stdout, err := cmd.CombinedOutput()
if err == nil {
l.Infof(ctx, "%s\ndeploy complete!", string(stdout))
output, err := cmd.CombinedOutput()
if err != nil {
l.Errorf(ctx, "%s", string(output))
return "", fmt.Errorf("deploy failed")
}
return string(stdout), err
l.Infof(ctx, "%s\ndeploy complete!", string(output))
return string(output), nil
}

// NeedsToBuild reads from the Turbine application to determine whether it needs to be built or not
Expand All @@ -56,13 +58,14 @@ func NeedsToBuild(appPath, appName string) (bool, error) {

// TODO: Implement in Turbine something that returns a boolean rather than having to regex its output
re := regexp.MustCompile(`\[(.+?)]`)
stdout, err := cmd.CombinedOutput()
output, err := cmd.CombinedOutput()
if err != nil {
return false, err
fmt.Println(string(output))
return false, fmt.Errorf("build failed")
}

// stdout is expected as `"2022/03/14 17:33:06 available functions: []` where within [], there will be each function.
hasFunctions := len(re.FindAllString(string(stdout), -1)) > 0
hasFunctions := len(re.FindAllString(string(output), -1)) > 0

return hasFunctions, nil
}
3 changes: 2 additions & 1 deletion cmd/meroxa/turbine_cli/golang/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package turbinego

import (
"context"
"fmt"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -29,7 +30,7 @@ func Run(ctx context.Context, appPath string, l log.Logger) error {
output, err := cmd.CombinedOutput()
if err != nil {
l.Error(ctx, string(output))
return err
return fmt.Errorf("run failed")
}
l.Info(ctx, string(output))
return nil
Expand Down

0 comments on commit 90d9d08

Please sign in to comment.