github.com/canonical/ubuntu-image@v0.0.0-20240430122802-2202fe98b290/internal/statemachine/pack.go (about) 1 package statemachine 2 3 import ( 4 "fmt" 5 6 "github.com/canonical/ubuntu-image/internal/commands" 7 ) 8 9 var packStates = []stateFunc{ 10 preparePackState, 11 populateTemporaryDirectoriesState, 12 loadGadgetYamlState, 13 setArtifactNamesState, 14 calculateRootfsSizeState, 15 populateBootfsContentsState, 16 populatePreparePartitionsState, 17 makeDiskState, 18 updateBootloaderState, 19 } 20 21 // PackStateMachine embeds StateMachine and adds the command line flags specific to pack images 22 type PackStateMachine struct { 23 StateMachine 24 Opts commands.PackOpts 25 } 26 27 // Setup assigns variables and calls other functions that must be executed before Run() 28 func (packStateMachine *PackStateMachine) Setup() error { 29 fmt.Print("WARNING: this is an experimental feature.\n") 30 31 // set the parent pointer of the embedded struct 32 packStateMachine.parent = packStateMachine 33 34 // set the beginning states that will be used by all pack image builds 35 packStateMachine.states = packStates 36 37 // do the validation common to all image types 38 if err := packStateMachine.validateInput(); err != nil { 39 return err 40 } 41 42 // validate values of until and thru 43 if err := packStateMachine.validateUntilThru(); err != nil { 44 return err 45 } 46 47 // if --resume was passed, figure out where to start 48 if err := packStateMachine.readMetadata(metadataStateFile); err != nil { 49 return err 50 } 51 52 packStateMachine.displayStates() 53 54 if packStateMachine.commonFlags.DryRun { 55 return nil 56 } 57 58 return packStateMachine.makeTemporaryDirectories() 59 }