Skip to content

Commit

Permalink
Parse logs gracefully when deploying a javascript app (#303)
Browse files Browse the repository at this point in the history
* Parse logs gracefully when deploying a javascript app
  • Loading branch information
janelletavares authored Apr 7, 2022
1 parent 90d9d08 commit f5ec6de
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
7 changes: 5 additions & 2 deletions cmd/meroxa/root/apps/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,18 @@ func (d *Deploy) Execute(ctx context.Context) error {
case GoLang:
deployOutput, err = d.deploy(ctx, d.path, d.logger)
case "js", JavaScript, NodeJs:
err = turbineJS.Deploy(ctx, d.path, d.logger)
deployOutput, err = turbineJS.Deploy(ctx, d.path, d.logger)
default:
return fmt.Errorf("language %q not supported. %s", d.lang, LanguageNotSupportedError)
}
if err != nil {
return err
}

pipelineUUID := turbineCLI.GetPipelineUUID(deployOutput)
pipelineUUID, err := turbineCLI.GetPipelineUUID(deployOutput)
if err != nil {
return err
}
gitSha, err := turbineCLI.GetGitSha(d.path)
if err != nil {
return err
Expand Down
7 changes: 3 additions & 4 deletions cmd/meroxa/turbine_cli/javascript/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ import (

// npx turbine whatever path => CLI could carry on with creating the tar.zip, post source, build...
// once that's complete, it's when we'd call `npx turbine deploy path`.
func Deploy(ctx context.Context, path string, l log.Logger) error {
func Deploy(ctx context.Context, path string, l log.Logger) (string, error) {
cmd := exec.Command("npx", "turbine", "deploy", path)

accessToken, _, err := global.GetUserToken()
if err != nil {
return err
return "", err
}
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("MEROXA_ACCESS_TOKEN=%s", accessToken))

_, err = turbinecli.RunCmdWithErrorDetection(ctx, cmd, l)
return err
return turbinecli.RunCmdWithErrorDetection(ctx, cmd, l)
}

// 1. we build binary (Go) // we set up the app structure (JS/Python) <- CLI could do this
Expand Down
10 changes: 6 additions & 4 deletions cmd/meroxa/turbine_cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,15 @@ func GitChecks(ctx context.Context, l log.Logger, appPath string) error {
}

// GetPipelineUUID parses the deploy output when it was successful to determine the pipeline UUID to create.
func GetPipelineUUID(output string) string {
func GetPipelineUUID(output string) (string, error) {
// Example output:
// 2022/03/16 13:21:36 pipeline created: "turbine-pipeline-simple" ("049760a8-a3d2-44d9-b326-0614c09a3f3e").
re := regexp.MustCompile(`pipeline:."turbine-pipeline-[a-z0-9-]+".(\([^)]*\))`)
res := re.FindStringSubmatch(output)[1]
res = strings.Trim(res, "()\"")
return res
matches := re.FindStringSubmatch(output)
if len(matches) < 2 { //nolint:gomnd
return "", fmt.Errorf("pipeline UUID not found")
}
return strings.Trim(matches[1], "()\""), nil
}

// ValidateBranch validates the deployment is being performed from one of the allowed branches.
Expand Down

0 comments on commit f5ec6de

Please sign in to comment.