diff options
author | Andrej Shadura <andrew.shadura@collabora.co.uk> | 2019-03-26 16:06:58 +0100 |
---|---|---|
committer | Andrej Shadura <andrew.shadura@collabora.co.uk> | 2019-03-26 16:06:58 +0100 |
commit | a5b1ffcadfa25582fa8364b73524bfff3e2a274b (patch) | |
tree | 45e7a0601bef560913d4b2672560d01eb96a51f3 | |
parent | 100044871faa0e1de2f62728c3d5b83e1ce41176 (diff) |
New upstream version 1.0.0+git20190326.5bd4aa9
-rw-r--r-- | action.go | 10 | ||||
-rw-r--r-- | actions/recipe_action.go | 23 | ||||
-rw-r--r-- | actions/recipe_test.go | 7 | ||||
-rw-r--r-- | cmd/debos/debos.go | 2 |
4 files changed, 23 insertions, 19 deletions
@@ -21,7 +21,7 @@ type Partition struct { DevicePath string } -type DebosContext struct { +type CommonContext struct { Scratchdir string Rootdir string Artifactdir string @@ -31,8 +31,6 @@ type DebosContext struct { ImageMntDir string ImageFSTab bytes.Buffer // Fstab as per partitioning ImageKernelRoot string // Kernel cmdline root= snippet for the / of the image - RecipeDir string - Architecture string DebugShell string Origins map[string]string State DebosState @@ -41,6 +39,12 @@ type DebosContext struct { Verbose bool } +type DebosContext struct { + *CommonContext + RecipeDir string + Architecture string +} + type Action interface { /* FIXME verify should probably be prepare or somesuch */ Verify(context *DebosContext) error 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) diff --git a/cmd/debos/debos.go b/cmd/debos/debos.go index 063dd0d..611162a 100644 --- a/cmd/debos/debos.go +++ b/cmd/debos/debos.go @@ -57,7 +57,7 @@ func warnLocalhost(variable string, value string) { func main() { - var context debos.DebosContext + context := debos.DebosContext { &debos.CommonContext{}, "", "" } var options struct { ArtifactDir string `long:"artifactdir" description:"Directory for packed archives and ostree repositories (default: current directory)"` InternalImage string `long:"internal-image" hidden:"true"` |