Skip to content

Commit

Permalink
cmd/debos: Add backend argument to choose fakemachine backend
Browse files Browse the repository at this point in the history
Fakemachine now allows the virtualisation backend to be chosen when
creating the machine, so allow the backend to be chosen by the user.

Signed-off-by: Christopher Obbard <[email protected]>
  • Loading branch information
obbardc authored and sjoerdsimons committed Dec 3, 2020
1 parent 458b7b3 commit ffb75b9
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions cmd/debos/debos.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func warnLocalhost(variable string, value string) {
func main() {
context := debos.DebosContext { &debos.CommonContext{}, "", "" }
var options struct {
Backend string `short:"b" long:"fakemachine-backend" description:"Fakemachine backend to use" default:"auto"`
ArtifactDir string `long:"artifactdir" description:"Directory for packed archives and ostree repositories (default: current directory)"`
InternalImage string `long:"internal-image" hidden:"true"`
TemplateVars map[string]string `short:"t" long:"template-var" description:"Template variables (use -t VARIABLE:VALUE syntax)"`
Expand Down Expand Up @@ -94,8 +95,10 @@ func main() {
}()

parser := flags.NewParser(&options, flags.Default)
args, err := parser.Parse()
fakemachineBackends := parser.FindOptionByLongName("fakemachine-backend")
fakemachineBackends.Choices = fakemachine.BackendNames()

args, err := parser.Parse()
if err != nil {
flagsErr, ok := err.(*flags.Error)
if ok && flagsErr.Type == flags.ErrHelp {
Expand All @@ -112,6 +115,12 @@ func main() {
return
}

if options.DisableFakeMachine && options.Backend != "auto" {
log.Println("--disable-fakemachine and --fakemachine-backend are mutually exclusive")
exitcode = 1
return
}

// Set interactive shell binary only if '--debug-shell' options passed
if options.DebugShell {
context.DebugShell = options.Shell
Expand Down Expand Up @@ -140,12 +149,34 @@ func main() {
return
}

/* If fakemachine is supported the outer fake machine will never use the
/* If fakemachine is used the outer fake machine will never use the
* scratchdir, so just set it to /scratch as a dummy to prevent the
* outer debos creating a temporary direction */
if !options.DisableFakeMachine && (fakemachine.InMachine() || fakemachine.Supported()) {
context.Scratchdir = "/scratch"
* outer debos creating a temporary directory */
context.Scratchdir = "/scratch"

var runInFakeMachine = true
var m *fakemachine.Machine
if options.DisableFakeMachine || fakemachine.InMachine() {
runInFakeMachine = false
} else {
// attempt to create a fakemachine
m, err = fakemachine.NewMachineWithBackend(options.Backend)
if err != nil {
log.Printf("error creating fakemachine: %v", err)

/* fallback to running on the host unless the user has chosen
* a specific backend */
if options.Backend == "auto" {
runInFakeMachine = false
} else {
exitcode = 1
return
}
}
}

// if running on the host create a scratchdir
if !runInFakeMachine && !fakemachine.InMachine() {
log.Printf("fakemachine not supported, running on the host!")
cwd, _ := os.Getwd()
context.Scratchdir, err = ioutil.TempDir(cwd, ".debos-")
Expand Down Expand Up @@ -212,8 +243,7 @@ func main() {
return
}

if !options.DisableFakeMachine && !fakemachine.InMachine() && fakemachine.Supported() {
m := fakemachine.NewMachine()
if runInFakeMachine {
var args []string

if options.Memory == "" {
Expand Down

0 comments on commit ffb75b9

Please sign in to comment.