From a5b1ffcadfa25582fa8364b73524bfff3e2a274b Mon Sep 17 00:00:00 2001 From: Andrej Shadura Date: Tue, 26 Mar 2019 16:06:58 +0100 Subject: New upstream version 1.0.0+git20190326.5bd4aa9 --- actions/recipe_action.go | 23 ++++++++++++++--------- actions/recipe_test.go | 7 +------ 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'actions') diff --git a/actions/recipe_action.go b/actions/recipe_action.go index e48f650..d9500dd 100644 --- a/actions/recipe_action.go +++ b/actions/recipe_action.go @@ -35,6 +35,7 @@ type RecipeAction struct { Variables map[string]string Actions Recipe `yaml:"-"` templateVars map[string]string + context debos.DebosContext } func (recipe *RecipeAction) Verify(context *debos.DebosContext) error { @@ -42,10 +43,13 @@ func (recipe *RecipeAction) Verify(context *debos.DebosContext) error { return errors.New("'recipe' property can't be empty") } + recipe.context = *context + file := recipe.Recipe if !filepath.IsAbs(file) { file = filepath.Clean(context.RecipeDir + "/" + recipe.Recipe) } + recipe.context.RecipeDir = filepath.Dir(file) if _, err := os.Stat(file); os.IsNotExist(err) { return err @@ -53,7 +57,6 @@ func (recipe *RecipeAction) Verify(context *debos.DebosContext) error { // Initialise template vars recipe.templateVars = make(map[string]string) - recipe.templateVars["included_recipe"] = "true" recipe.templateVars["architecture"] = context.Architecture // Add Variables to template vars @@ -65,12 +68,12 @@ func (recipe *RecipeAction) Verify(context *debos.DebosContext) error { return err } - if context.Architecture != recipe.Actions.Architecture { + if recipe.context.Architecture != recipe.Actions.Architecture { return fmt.Errorf("Expect architecture '%s' but got '%s'", context.Architecture, recipe.Actions.Architecture) } for _, a := range recipe.Actions.Actions { - if err := a.Verify(context); err != nil { + if err := a.Verify(&recipe.context); err != nil { return err } } @@ -81,8 +84,10 @@ func (recipe *RecipeAction) Verify(context *debos.DebosContext) error { func (recipe *RecipeAction) PreMachine(context *debos.DebosContext, m *fakemachine.Machine, args *[]string) error { // TODO: check args? + m.AddVolume(recipe.context.RecipeDir) + for _, a := range recipe.Actions.Actions { - if err := a.PreMachine(context, m, args); err != nil { + if err := a.PreMachine(&recipe.context, m, args); err != nil { return err } } @@ -92,7 +97,7 @@ func (recipe *RecipeAction) PreMachine(context *debos.DebosContext, m *fakemachi func (recipe *RecipeAction) PreNoMachine(context *debos.DebosContext) error { for _, a := range recipe.Actions.Actions { - if err := a.PreNoMachine(context); err != nil { + if err := a.PreNoMachine(&recipe.context); err != nil { return err } } @@ -104,7 +109,7 @@ func (recipe *RecipeAction) Run(context *debos.DebosContext) error { recipe.LogStart() for _, a := range recipe.Actions.Actions { - if err := a.Run(context); err != nil { + if err := a.Run(&recipe.context); err != nil { return err } } @@ -114,7 +119,7 @@ func (recipe *RecipeAction) Run(context *debos.DebosContext) error { func (recipe *RecipeAction) Cleanup(context *debos.DebosContext) error { for _, a := range recipe.Actions.Actions { - if err := a.Cleanup(context); err != nil { + if err := a.Cleanup(&recipe.context); err != nil { return err } } @@ -124,7 +129,7 @@ func (recipe *RecipeAction) Cleanup(context *debos.DebosContext) error { func (recipe *RecipeAction) PostMachine(context *debos.DebosContext) error { for _, a := range recipe.Actions.Actions { - if err := a.PostMachine(context); err != nil { + if err := a.PostMachine(&recipe.context); err != nil { return err } } @@ -134,7 +139,7 @@ func (recipe *RecipeAction) PostMachine(context *debos.DebosContext) error { func (recipe *RecipeAction) PostMachineCleanup(context *debos.DebosContext) error { for _, a := range recipe.Actions.Actions { - if err := a.PostMachineCleanup(context); err != nil { + if err := a.PostMachineCleanup(&recipe.context); err != nil { return err } } diff --git a/actions/recipe_test.go b/actions/recipe_test.go index 972bf61..de9d6ea 100644 --- a/actions/recipe_test.go +++ b/actions/recipe_test.go @@ -231,16 +231,11 @@ actions: var recipeIncluded = subRecipe { "included.yaml", ` -{{- $included_recipe := or .included_recipe "false"}} architecture: amd64 actions: - action: run command: ok.sh - {{- if ne $included_recipe "true" }} - - action: recipe - recipe: armhf.yaml - {{- end }} `, } @@ -314,7 +309,7 @@ actions: } func runTestWithSubRecipes(t *testing.T, test testSubRecipe, templateVars ...map[string]string) actions.Recipe { - var context debos.DebosContext + context := debos.DebosContext { &debos.CommonContext{}, "", "" } dir, err := ioutil.TempDir("", "go-debos") assert.Empty(t, err) defer os.RemoveAll(dir) -- cgit v1.2.3