( ctx context.Context, options options.Options, scripts devcontainer.LifecycleScripts, firstStart bool, userInfo userInfo, )
| 1434 | } |
| 1435 | |
| 1436 | func execLifecycleScripts( |
| 1437 | ctx context.Context, |
| 1438 | options options.Options, |
| 1439 | scripts devcontainer.LifecycleScripts, |
| 1440 | firstStart bool, |
| 1441 | userInfo userInfo, |
| 1442 | ) error { |
| 1443 | if options.PostStartScriptPath != "" { |
| 1444 | options.Logger(log.LevelDebug, "Removing postStartScriptPath %s", options.PostStartScriptPath) |
| 1445 | _ = os.Remove(options.PostStartScriptPath) |
| 1446 | } |
| 1447 | |
| 1448 | if firstStart { |
| 1449 | if err := execOneLifecycleScript(ctx, options.Logger, scripts.OnCreateCommand, "onCreateCommand", userInfo); err != nil { |
| 1450 | // skip remaining lifecycle commands |
| 1451 | return nil |
| 1452 | } |
| 1453 | } else { |
| 1454 | options.Logger(log.LevelDebug, "Skipping onCreateCommand for subsequent starts...") |
| 1455 | } |
| 1456 | if err := execOneLifecycleScript(ctx, options.Logger, scripts.UpdateContentCommand, "updateContentCommand", userInfo); err != nil { |
| 1457 | // skip remaining lifecycle commands |
| 1458 | return nil |
| 1459 | } |
| 1460 | if err := execOneLifecycleScript(ctx, options.Logger, scripts.PostCreateCommand, "postCreateCommand", userInfo); err != nil { |
| 1461 | // skip remaining lifecycle commands |
| 1462 | return nil |
| 1463 | } |
| 1464 | if !scripts.PostStartCommand.IsEmpty() { |
| 1465 | // If PostStartCommandPath is set, the init command is responsible |
| 1466 | // for running the postStartCommand. Otherwise, we execute it now. |
| 1467 | if options.PostStartScriptPath != "" { |
| 1468 | if err := createPostStartScript(options.PostStartScriptPath, scripts.PostStartCommand); err != nil { |
| 1469 | return fmt.Errorf("failed to create post-start script: %w", err) |
| 1470 | } |
| 1471 | } else { |
| 1472 | _ = execOneLifecycleScript(ctx, options.Logger, scripts.PostStartCommand, "postStartCommand", userInfo) |
| 1473 | } |
| 1474 | } |
| 1475 | return nil |
| 1476 | } |
| 1477 | |
| 1478 | func createPostStartScript(path string, postStartCommand devcontainer.LifecycleScript) error { |
| 1479 | postStartScript, err := os.Create(path) |
no test coverage detected