(ctx context.Context, appBinPath string, appPath string, blockMeta waveobj.MetaMapType)
| 293 | } |
| 294 | |
| 295 | func runTsunamiAppBinary(ctx context.Context, appBinPath string, appPath string, blockMeta waveobj.MetaMapType) (*TsunamiAppProc, error) { |
| 296 | cmd := exec.Command(appBinPath) |
| 297 | cmd.Env = append(os.Environ(), "TSUNAMI_CLOSEONSTDIN=1") |
| 298 | |
| 299 | if wavebase.IsDevMode() { |
| 300 | cmd.Env = append(cmd.Env, "TSUNAMI_CORS="+tsunamiutil.DevModeCorsOrigins) |
| 301 | } |
| 302 | |
| 303 | // Add TsunamiEnv variables if configured |
| 304 | tsunamiEnv := blockMeta.GetMap(waveobj.MetaKey_TsunamiEnv) |
| 305 | for key, value := range tsunamiEnv { |
| 306 | if strValue, ok := value.(string); ok { |
| 307 | cmd.Env = append(cmd.Env, key+"="+strValue) |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | stdoutPipe, err := cmd.StdoutPipe() |
| 312 | if err != nil { |
| 313 | return nil, fmt.Errorf("failed to create stdout pipe: %w", err) |
| 314 | } |
| 315 | |
| 316 | stderrPipe, err := cmd.StderrPipe() |
| 317 | if err != nil { |
| 318 | return nil, fmt.Errorf("failed to create stderr pipe: %w", err) |
| 319 | } |
| 320 | |
| 321 | stdinPipe, err := cmd.StdinPipe() |
| 322 | if err != nil { |
| 323 | return nil, fmt.Errorf("failed to create stdin pipe: %w", err) |
| 324 | } |
| 325 | |
| 326 | appName := build.GetAppName(appPath) |
| 327 | |
| 328 | lineBuffer := utilds.MakeMultiReaderLineBuffer(1000) |
| 329 | portChan := make(chan int, 1) |
| 330 | portFound := false |
| 331 | |
| 332 | lineBuffer.SetLineCallback(func(line string) { |
| 333 | log.Printf("[tsunami:%s] %s\n", appName, line) |
| 334 | |
| 335 | if !portFound { |
| 336 | if port := build.ParseTsunamiPort(line); port > 0 { |
| 337 | portFound = true |
| 338 | portChan <- port |
| 339 | } |
| 340 | } |
| 341 | }) |
| 342 | |
| 343 | err = cmd.Start() |
| 344 | if err != nil { |
| 345 | return nil, fmt.Errorf("failed to start tsunami app: %w", err) |
| 346 | } |
| 347 | |
| 348 | // Create wait channel and tsunami proc first |
| 349 | waitCh := make(chan struct{}) |
| 350 | tsunamiProc := &TsunamiAppProc{ |
| 351 | Cmd: cmd, |
| 352 | LineBuffer: lineBuffer, |
no test coverage detected