ProcessHooks executes Tasks defined in Hooks
(hookName string)
| 1384 | |
| 1385 | // ProcessHooks executes Tasks defined in Hooks |
| 1386 | func (app *DdevApp) ProcessHooks(hookName string) error { |
| 1387 | if SkipHooks { |
| 1388 | output.UserOut.Debugf("Skipping the execution of %s hook...", hookName) |
| 1389 | return nil |
| 1390 | } |
| 1391 | if cmds := app.Hooks[hookName]; len(cmds) > 0 { |
| 1392 | output.UserOut.Debugf("Executing %s hook...", hookName) |
| 1393 | } |
| 1394 | |
| 1395 | for _, c := range app.Hooks[hookName] { |
| 1396 | a := NewTask(app, c) |
| 1397 | if a == nil { |
| 1398 | return fmt.Errorf("unable to create task from %v", c) |
| 1399 | } |
| 1400 | |
| 1401 | if hookName == "pre-start" { |
| 1402 | for k := range c { |
| 1403 | if k == "exec" || k == "composer" { |
| 1404 | return fmt.Errorf("pre-start hooks cannot contain %v", k) |
| 1405 | } |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | output.UserOut.Debugf("=== Running task: %s, output below", a.GetDescription()) |
| 1410 | |
| 1411 | err := a.Execute() |
| 1412 | |
| 1413 | if err != nil { |
| 1414 | if app.FailOnHookFail || app.FailOnHookFailGlobal { |
| 1415 | output.UserOut.Errorf("Task failed: %v: %v", a.GetDescription(), err) |
| 1416 | return fmt.Errorf("task failed: %v", err) |
| 1417 | } |
| 1418 | output.UserOut.Errorf("Task failed: %v: %v", a.GetDescription(), err) |
| 1419 | output.UserOut.Warn("A task failure does not mean that DDEV failed, but your hook configuration has a command that failed.") |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | return nil |
| 1424 | } |
| 1425 | |
| 1426 | // GetDBImage uses the available version info |
| 1427 | func (app *DdevApp) GetDBImage() string { |