Files
debos/action.go
Sjoerd Simons 07af4c497f Add helper to retrieve origin
The origins hash table is inside the commonContext structure which is
shared by all Contexts. This mostly works correctly as most origins are
not specific to the recipe that's executed but to either the run or the
progress of a run. Such as "filesystem" or "artifacts".

However this is not the case for the "recipe" origin. To resolve that
add a helper function which returns the current context RecipeDir and
otherwise simply the respective value in the common Origins table.

Signed-off-by: Sjoerd Simons <sjoerd@collabora.com>
2022-04-27 17:18:51 +02:00

99 lines
2.7 KiB
Go

package debos
import (
"bytes"
"github.com/go-debos/fakemachine"
"log"
)
type DebosState int
// Represent the current state of Debos
const (
Success DebosState = iota
Failed
)
// Mapping from partition name as configured in the image-partition action to
// device path for usage by other actions
type Partition struct {
Name string
DevicePath string
}
type CommonContext struct {
Scratchdir string
Rootdir string
Artifactdir string
Downloaddir string
Image string
ImagePartitions []Partition
ImageMntDir string
ImageFSTab bytes.Buffer // Fstab as per partitioning
ImageKernelRoot string // Kernel cmdline root= snippet for the / of the image
DebugShell string
Origins map[string]string
State DebosState
EnvironVars map[string]string
PrintRecipe bool
Verbose bool
}
type DebosContext struct {
*CommonContext
RecipeDir string
Architecture string
}
func (c *DebosContext) Origin(o string) (string, bool) {
if o == "recipe" {
return c.RecipeDir, true
} else {
path, found := c.Origins[o];
return path, found
}
}
type Action interface {
/* FIXME verify should probably be prepare or somesuch */
Verify(context *DebosContext) error
PreMachine(context *DebosContext, m *fakemachine.Machine, args *[]string) error
PreNoMachine(context *DebosContext) error
Run(context *DebosContext) error
// Cleanup() method gets called only if the Run for an action
// was started and in the same machine (host or fake) as Run has run
Cleanup(context *DebosContext) error
PostMachine(context *DebosContext) error
// PostMachineCleanup() gets called for all actions if Pre*Machine() method
// has run for Action. This method is always executed on the host with user's permissions.
PostMachineCleanup(context *DebosContext) error
String() string
}
type BaseAction struct {
Action string
Description string
}
func (b *BaseAction) LogStart() {
log.Printf("==== %s ====\n", b)
}
func (b *BaseAction) Verify(context *DebosContext) error { return nil }
func (b *BaseAction) PreMachine(context *DebosContext,
m *fakemachine.Machine,
args *[]string) error {
return nil
}
func (b *BaseAction) PreNoMachine(context *DebosContext) error { return nil }
func (b *BaseAction) Run(context *DebosContext) error { return nil }
func (b *BaseAction) Cleanup(context *DebosContext) error { return nil }
func (b *BaseAction) PostMachine(context *DebosContext) error { return nil }
func (b *BaseAction) PostMachineCleanup(context *DebosContext) error { return nil }
func (b *BaseAction) String() string {
if b.Description == "" {
return b.Action
}
return b.Description
}