Commit 38845550 authored by Clint's avatar Clint

Merge pull request #2289 from mitchellh/b-amazon-chroot-fixes

builder/amazon-chroot: various fixing and debugging of chroot builder
parents a8166d47 44dc977c
...@@ -34,6 +34,7 @@ type Config struct { ...@@ -34,6 +34,7 @@ type Config struct {
DevicePath string `mapstructure:"device_path"` DevicePath string `mapstructure:"device_path"`
MountPath string `mapstructure:"mount_path"` MountPath string `mapstructure:"mount_path"`
SourceAmi string `mapstructure:"source_ami"` SourceAmi string `mapstructure:"source_ami"`
RootVolumeSize int64 `mapstructure:"root_volume_size"`
ctx interpolate.Context ctx interpolate.Context
} }
...@@ -159,7 +160,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -159,7 +160,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&StepCheckRootDevice{}, &StepCheckRootDevice{},
&StepFlock{}, &StepFlock{},
&StepPrepareDevice{}, &StepPrepareDevice{},
&StepCreateVolume{}, &StepCreateVolume{
RootVolumeSize: b.config.RootVolumeSize,
},
&StepAttachVolume{}, &StepAttachVolume{},
&StepEarlyUnflock{}, &StepEarlyUnflock{},
&StepMountDevice{}, &StepMountDevice{},
...@@ -172,7 +175,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -172,7 +175,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
ForceDeregister: b.config.AMIForceDeregister, ForceDeregister: b.config.AMIForceDeregister,
AMIName: b.config.AMIName, AMIName: b.config.AMIName,
}, },
&StepRegisterAMI{}, &StepRegisterAMI{
RootVolumeSize: b.config.RootVolumeSize,
},
&awscommon.StepAMIRegionCopy{ &awscommon.StepAMIRegionCopy{
AccessConfig: &b.config.AccessConfig, AccessConfig: &b.config.AccessConfig,
Regions: b.config.AMIRegions, Regions: b.config.AMIRegions,
......
...@@ -4,6 +4,8 @@ import ( ...@@ -4,6 +4,8 @@ import (
"fmt" "fmt"
"log" "log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awsutil"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
awscommon "github.com/mitchellh/packer/builder/amazon/common" awscommon "github.com/mitchellh/packer/builder/amazon/common"
...@@ -16,7 +18,8 @@ import ( ...@@ -16,7 +18,8 @@ import (
// Produces: // Produces:
// volume_id string - The ID of the created volume // volume_id string - The ID of the created volume
type StepCreateVolume struct { type StepCreateVolume struct {
volumeId string volumeId string
RootVolumeSize int64
} }
func (s *StepCreateVolume) Run(state multistep.StateBag) multistep.StepAction { func (s *StepCreateVolume) Run(state multistep.StateBag) multistep.StepAction {
...@@ -29,7 +32,7 @@ func (s *StepCreateVolume) Run(state multistep.StateBag) multistep.StepAction { ...@@ -29,7 +32,7 @@ func (s *StepCreateVolume) Run(state multistep.StateBag) multistep.StepAction {
log.Printf("Searching for root device of the image (%s)", *image.RootDeviceName) log.Printf("Searching for root device of the image (%s)", *image.RootDeviceName)
var rootDevice *ec2.BlockDeviceMapping var rootDevice *ec2.BlockDeviceMapping
for _, device := range image.BlockDeviceMappings { for _, device := range image.BlockDeviceMappings {
if device.DeviceName == image.RootDeviceName { if *device.DeviceName == *image.RootDeviceName {
rootDevice = device rootDevice = device
break break
} }
...@@ -43,14 +46,18 @@ func (s *StepCreateVolume) Run(state multistep.StateBag) multistep.StepAction { ...@@ -43,14 +46,18 @@ func (s *StepCreateVolume) Run(state multistep.StateBag) multistep.StepAction {
} }
ui.Say("Creating the root volume...") ui.Say("Creating the root volume...")
vs := *rootDevice.EBS.VolumeSize
if s.RootVolumeSize > *rootDevice.EBS.VolumeSize {
vs = s.RootVolumeSize
}
createVolume := &ec2.CreateVolumeInput{ createVolume := &ec2.CreateVolumeInput{
AvailabilityZone: instance.Placement.AvailabilityZone, AvailabilityZone: instance.Placement.AvailabilityZone,
Size: rootDevice.EBS.VolumeSize, Size: aws.Long(vs),
SnapshotID: rootDevice.EBS.SnapshotID, SnapshotID: rootDevice.EBS.SnapshotID,
VolumeType: rootDevice.EBS.VolumeType, VolumeType: rootDevice.EBS.VolumeType,
IOPS: rootDevice.EBS.IOPS, IOPS: rootDevice.EBS.IOPS,
} }
log.Printf("Create args: %#v", createVolume) log.Printf("Create args: %s", awsutil.StringValue(createVolume))
createVolumeResp, err := ec2conn.CreateVolume(createVolume) createVolumeResp, err := ec2conn.CreateVolume(createVolume)
if err != nil { if err != nil {
......
...@@ -49,7 +49,7 @@ func (s *StepInstanceInfo) Run(state multistep.StateBag) multistep.StepAction { ...@@ -49,7 +49,7 @@ func (s *StepInstanceInfo) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt return multistep.ActionHalt
} }
instance := &instancesResp.Reservations[0].Instances[0] instance := instancesResp.Reservations[0].Instances[0]
state.Put("instance", instance) state.Put("instance", instance)
return multistep.ActionContinue return multistep.ActionContinue
......
...@@ -11,7 +11,9 @@ import ( ...@@ -11,7 +11,9 @@ import (
) )
// StepRegisterAMI creates the AMI. // StepRegisterAMI creates the AMI.
type StepRegisterAMI struct{} type StepRegisterAMI struct {
RootVolumeSize int64
}
func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction { func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
...@@ -24,14 +26,24 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction { ...@@ -24,14 +26,24 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction {
blockDevices := make([]*ec2.BlockDeviceMapping, len(image.BlockDeviceMappings)) blockDevices := make([]*ec2.BlockDeviceMapping, len(image.BlockDeviceMappings))
for i, device := range image.BlockDeviceMappings { for i, device := range image.BlockDeviceMappings {
newDevice := device newDevice := device
if newDevice.DeviceName == image.RootDeviceName { if *newDevice.DeviceName == *image.RootDeviceName {
if newDevice.EBS != nil { if newDevice.EBS != nil {
newDevice.EBS.SnapshotID = &snapshotId newDevice.EBS.SnapshotID = aws.String(snapshotId)
} else { } else {
newDevice.EBS = &ec2.EBSBlockDevice{SnapshotID: &snapshotId} newDevice.EBS = &ec2.EBSBlockDevice{SnapshotID: aws.String(snapshotId)}
}
if s.RootVolumeSize > *newDevice.EBS.VolumeSize {
newDevice.EBS.VolumeSize = aws.Long(s.RootVolumeSize)
} }
} }
// assume working from a snapshot, so we unset the Encrypted field if set,
// otherwise AWS API will return InvalidParameter
if newDevice.EBS != nil && newDevice.EBS.Encrypted != nil {
newDevice.EBS.Encrypted = nil
}
blockDevices[i] = newDevice blockDevices[i] = newDevice
} }
...@@ -82,7 +94,11 @@ func buildRegisterOpts(config *Config, image *ec2.Image, blockDevices []*ec2.Blo ...@@ -82,7 +94,11 @@ func buildRegisterOpts(config *Config, image *ec2.Image, blockDevices []*ec2.Blo
Architecture: image.Architecture, Architecture: image.Architecture,
RootDeviceName: image.RootDeviceName, RootDeviceName: image.RootDeviceName,
BlockDeviceMappings: blockDevices, BlockDeviceMappings: blockDevices,
VirtualizationType: &config.AMIVirtType, VirtualizationType: image.VirtualizationType,
}
if config.AMIVirtType != "" {
registerOpts.VirtualizationType = aws.String(config.AMIVirtType)
} }
if config.AMIVirtType != "hvm" { if config.AMIVirtType != "hvm" {
......
...@@ -133,6 +133,9 @@ AMI if one with the same name already exists. Default `false`. ...@@ -133,6 +133,9 @@ AMI if one with the same name already exists. Default `false`.
template where the `.Device` variable is replaced with the name of the template where the `.Device` variable is replaced with the name of the
device where the volume is attached. device where the volume is attached.
* `root_volume_size` (integer) – The size of the root volume for the chroot
environment, and the resulting AMI
* `tags` (object of key/value strings) - Tags applied to the AMI. * `tags` (object of key/value strings) - Tags applied to the AMI.
## Basic Example ## Basic Example
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment