-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package commands | ||
|
||
// PackOpts holds all flags that are specific to the pack command | ||
type PackOpts struct { | ||
ArtifactType string `long:"artifact-type" description:"Type of the resulting disk image file." required:"true" hidden:"true" default:"img"` | ||
GadgetDir string `long:"gadget-dir" description:"Directory containing the gadget.yaml and the gadget tree." required:"true" hidden:"true"` | ||
RootfsDir string `long:"rootfs-dir" description:"Directory containing the rootfs" required:"true" hidden:"true"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package statemachine | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/canonical/ubuntu-image/internal/commands" | ||
) | ||
|
||
var packStates = []stateFunc{ | ||
{"prepare_pack", (*StateMachine).preparePack}, | ||
{"load_gadget_yaml", (*StateMachine).loadGadgetYaml}, | ||
{"calculate_rootfs_size", (*StateMachine).calculateRootfsSize}, | ||
{"populate_bootfs_contents", (*StateMachine).populateBootfsContents}, | ||
{"populate_prepare_partitions", (*StateMachine).populatePreparePartitions}, | ||
{"make_disk", (*StateMachine).makeDisk}, | ||
{"update_bootloader", (*StateMachine).updateBootloader}, | ||
} | ||
|
||
// PackStateMachine embeds StateMachine and adds the command line flags specific to pack images | ||
type PackStateMachine struct { | ||
StateMachine | ||
Opts commands.PackOpts | ||
} | ||
|
||
// Setup assigns variables and calls other functions that must be executed before Run() | ||
func (packStateMachine *PackStateMachine) Setup() error { | ||
fmt.Printf("WARNING: this is an experimental feature.") | ||
|
||
// set the parent pointer of the embedded struct | ||
packStateMachine.parent = packStateMachine | ||
|
||
// set the beginning states that will be used by all pack image builds | ||
packStateMachine.states = packStates | ||
|
||
// do the validation common to all image types | ||
if err := packStateMachine.validateInput(); err != nil { | ||
return err | ||
} | ||
|
||
// if --resume was passed, figure out where to start | ||
if err := packStateMachine.readMetadata(metadataStateFile); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package statemachine | ||
|
||
import "path/filepath" | ||
|
||
func (stateMachine *StateMachine) preparePack() error { | ||
packStateMachine := stateMachine.parent.(*PackStateMachine) | ||
|
||
packStateMachine.YamlFilePath = filepath.Join(packStateMachine.Opts.GadgetDir, "meta", "gadget.yaml") | ||
|
||
|
||
return nil | ||
} |