81 lines
2.0 KiB
Go
81 lines
2.0 KiB
Go
package iocage
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
"os"
|
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
|
"github.com/hashicorp/packer/packer"
|
|
)
|
|
|
|
type StepPackage struct {
|
|
SkipPackage bool
|
|
Include []string
|
|
Vagrantfile string
|
|
GlobalID string
|
|
}
|
|
|
|
func (s *StepPackage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
|
//driver := state.Get("driver").(VagrantDriver)
|
|
ui := state.Get("ui").(packer.Ui)
|
|
comm := state.Get("communicator").(packer.Communicator)
|
|
config := state.Get("config").(Config)
|
|
|
|
//if s.SkipPackage {
|
|
// ui.Say("skip_package flag set; not going to call Vagrant package on this box.")
|
|
// return multistep.ActionContinue
|
|
//}
|
|
ui.Say("Packaging jail...")
|
|
|
|
cmdStop := &packer.RemoteCmd {
|
|
Command: fmt.Sprintf("sudo iocage stop %s", config.JailName),
|
|
}
|
|
if err := cmdStop.RunWithUi(ctx, comm, ui); err != nil || cmdStop.ExitStatus() != 0 {
|
|
if err == nil {
|
|
err = fmt.Errorf("Bad exit status: %d", cmdStop.ExitStatus())
|
|
}
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
cmdExport := &packer.RemoteCmd {
|
|
Command: fmt.Sprintf("sudo iocage export %s", config.JailName),
|
|
}
|
|
if err := cmdExport.RunWithUi(ctx, comm, ui); err != nil || cmdExport.ExitStatus() != 0 {
|
|
if err == nil {
|
|
err = fmt.Errorf("Bad exit status: %d", cmdExport.ExitStatus())
|
|
}
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
ui.Say("Downloading packed jail...")
|
|
|
|
f, _ := os.Create(fmt.Sprintf("%s_%s.iocage", config.JailName, time.Now().Format("2019-12-20")))
|
|
|
|
defer f.Close()
|
|
|
|
_ = comm.Download(fmt.Sprintf("/iocage/images/%s_%s.zip", config.JailName, time.Now().Format("2019-12-20")),
|
|
f)
|
|
|
|
/* packageArgs = append(packageArgs, box)
|
|
|
|
if len(s.Include) > 0 {
|
|
packageArgs = append(packageArgs, "--include", strings.Join(s.Include, ","))
|
|
}
|
|
if s.Vagrantfile != "" {
|
|
packageArgs = append(packageArgs, "--vagrantfile", s.Vagrantfile)
|
|
}
|
|
|
|
err := driver.Package(packageArgs)
|
|
if err != nil {
|
|
state.Put("error", err)
|
|
return multistep.ActionHalt
|
|
} */
|
|
|
|
return multistep.ActionContinue
|
|
}
|
|
|
|
func (s *StepPackage) Cleanup(state multistep.StateBag) {
|
|
}
|