From 0c47ee55e6820e55346303e75c5f9a35148c1654 Mon Sep 17 00:00:00 2001 From: Marin Salinas Date: Fri, 15 Feb 2019 11:41:36 -0600 Subject: [PATCH] feature: add chroot builder structure --- builder/osc/chroot/builder.go | 53 +++++++++++++++++++++++++++++++++++ command/plugin.go | 2 ++ 2 files changed, 55 insertions(+) create mode 100644 builder/osc/chroot/builder.go diff --git a/builder/osc/chroot/builder.go b/builder/osc/chroot/builder.go new file mode 100644 index 000000000..532a7d6a5 --- /dev/null +++ b/builder/osc/chroot/builder.go @@ -0,0 +1,53 @@ +// The chroot package is able to create an Outscale OMI without requiring +// the launch of a new instance for every build. It does this by attaching +// and mounting the root volume of another OMI and chrooting into that +// directory. It then creates an OMI from that attached drive. +package chroot + +import ( + "errors" + "runtime" + + osccommon "github.com/hashicorp/packer/builder/osc/common" + "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/helper/multistep" + "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/template/interpolate" +) + +// The unique ID for this builder +const BuilderId = "oapi.outscale.chroot" + +// Config is the configuration that is chained through the steps and +// settable from the template. +type Config struct { + common.PackerConfig `mapstructure:",squash"` + osccommon.OMIBlockDevices `mapstructure:",squash"` + osccommon.OMIConfig `mapstructure:",squash"` + osccommon.AccessConfig `mapstructure:",squash"` + + ctx interpolate.Context +} + +type wrappedCommandTemplate struct { + Command string +} + +type Builder struct { + config Config + runner multistep.Runner +} + +func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { + return nil, nil +} + +func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { + if runtime.GOOS != "linux" { + return nil, errors.New("The outscale-chroot builder only works on Linux environments.") + } + return nil, nil +} + +func (b *Builder) Cancel() { +} diff --git a/command/plugin.go b/command/plugin.go index e44708122..cfe9c417d 100644 --- a/command/plugin.go +++ b/command/plugin.go @@ -40,6 +40,7 @@ import ( oracleocibuilder "github.com/hashicorp/packer/builder/oracle/oci" oscbsubuilder "github.com/hashicorp/packer/builder/osc/bsu" oscbsusurrogatebuilder "github.com/hashicorp/packer/builder/osc/bsusurrogate" + oscchrootbuilder "github.com/hashicorp/packer/builder/osc/chroot" parallelsisobuilder "github.com/hashicorp/packer/builder/parallels/iso" parallelspvmbuilder "github.com/hashicorp/packer/builder/parallels/pvm" profitbricksbuilder "github.com/hashicorp/packer/builder/profitbricks" @@ -125,6 +126,7 @@ var Builders = map[string]packer.Builder{ "oracle-oci": new(oracleocibuilder.Builder), "osc-bsu": new(oscbsubuilder.Builder), "osc-bsusurrogate": new(oscbsusurrogatebuilder.Builder), + "osc-chroot": new(oscchrootbuilder.Builder), "parallels-iso": new(parallelsisobuilder.Builder), "parallels-pvm": new(parallelspvmbuilder.Builder), "profitbricks": new(profitbricksbuilder.Builder),