Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
e8889e56
Commit
e8889e56
authored
Sep 02, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1381 from pas256/chroot-hvm
builder/amazonchroot: can build both PV and HVM images
parents
02091537
ab9f0bc3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
107 additions
and
14 deletions
+107
-14
builder/amazon/chroot/device.go
builder/amazon/chroot/device.go
+6
-5
builder/amazon/chroot/step_mount_device.go
builder/amazon/chroot/step_mount_device.go
+10
-1
builder/amazon/chroot/step_register_ami.go
builder/amazon/chroot/step_register_ami.go
+18
-8
builder/amazon/chroot/step_register_ami_test.go
builder/amazon/chroot/step_register_ami_test.go
+73
-0
No files found.
builder/amazon/chroot/device.go
View file @
e8889e56
...
@@ -27,11 +27,12 @@ func AvailableDevice() (string, error) {
...
@@ -27,11 +27,12 @@ func AvailableDevice() (string, error) {
continue
continue
}
}
for
i
:=
1
;
i
<
16
;
i
++
{
// To be able to build both Paravirtual and HVM images, the unnumbered
device
:=
fmt
.
Sprintf
(
"/dev/%s%c%d"
,
prefix
,
letter
,
i
)
// device and the first numbered one must be available.
if
_
,
err
:=
os
.
Stat
(
device
);
err
!=
nil
{
// E.g. /dev/xvdf and /dev/xvdf1
return
device
,
nil
numbered_device
:=
fmt
.
Sprintf
(
"%s%d"
,
device
,
1
)
}
if
_
,
err
:=
os
.
Stat
(
numbered_device
);
err
!=
nil
{
return
device
,
nil
}
}
}
}
...
...
builder/amazon/chroot/step_mount_device.go
View file @
e8889e56
...
@@ -3,6 +3,7 @@ package chroot
...
@@ -3,6 +3,7 @@ package chroot
import
(
import
(
"bytes"
"bytes"
"fmt"
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"log"
"log"
...
@@ -26,6 +27,7 @@ type StepMountDevice struct {
...
@@ -26,6 +27,7 @@ type StepMountDevice struct {
func
(
s
*
StepMountDevice
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
func
(
s
*
StepMountDevice
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
image
:=
state
.
Get
(
"source_image"
)
.
(
*
ec2
.
Image
)
device
:=
state
.
Get
(
"device"
)
.
(
string
)
device
:=
state
.
Get
(
"device"
)
.
(
string
)
wrappedCommand
:=
state
.
Get
(
"wrappedCommand"
)
.
(
CommandWrapper
)
wrappedCommand
:=
state
.
Get
(
"wrappedCommand"
)
.
(
CommandWrapper
)
...
@@ -57,10 +59,17 @@ func (s *StepMountDevice) Run(state multistep.StateBag) multistep.StepAction {
...
@@ -57,10 +59,17 @@ func (s *StepMountDevice) Run(state multistep.StateBag) multistep.StepAction {
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
log
.
Printf
(
"Source image virtualization type is: %s"
,
image
.
VirtualizationType
)
deviceMount
:=
device
if
image
.
VirtualizationType
==
"hvm"
{
deviceMount
=
fmt
.
Sprintf
(
"%s%d"
,
device
,
1
)
}
state
.
Put
(
"deviceMount"
,
deviceMount
)
ui
.
Say
(
"Mounting the root device..."
)
ui
.
Say
(
"Mounting the root device..."
)
stderr
:=
new
(
bytes
.
Buffer
)
stderr
:=
new
(
bytes
.
Buffer
)
mountCommand
,
err
:=
wrappedCommand
(
mountCommand
,
err
:=
wrappedCommand
(
fmt
.
Sprintf
(
"mount %s %s"
,
device
,
mountPath
))
fmt
.
Sprintf
(
"mount %s %s"
,
device
Mount
,
mountPath
))
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating mount command: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error creating mount command: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
state
.
Put
(
"error"
,
err
)
...
...
builder/amazon/chroot/step_register_ami.go
View file @
e8889e56
...
@@ -30,14 +30,7 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction {
...
@@ -30,14 +30,7 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction {
blockDevices
[
i
]
=
newDevice
blockDevices
[
i
]
=
newDevice
}
}
registerOpts
:=
&
ec2
.
RegisterImage
{
registerOpts
:=
buildRegisterOpts
(
config
,
image
,
blockDevices
)
Name
:
config
.
AMIName
,
Architecture
:
image
.
Architecture
,
KernelId
:
image
.
KernelId
,
RamdiskId
:
image
.
RamdiskId
,
RootDeviceName
:
image
.
RootDeviceName
,
BlockDevices
:
blockDevices
,
}
// Set SriovNetSupport to "simple". See http://goo.gl/icuXh5
// Set SriovNetSupport to "simple". See http://goo.gl/icuXh5
if
config
.
AMIEnhancedNetworking
{
if
config
.
AMIEnhancedNetworking
{
...
@@ -77,3 +70,20 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction {
...
@@ -77,3 +70,20 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction {
}
}
func
(
s
*
StepRegisterAMI
)
Cleanup
(
state
multistep
.
StateBag
)
{}
func
(
s
*
StepRegisterAMI
)
Cleanup
(
state
multistep
.
StateBag
)
{}
func
buildRegisterOpts
(
config
*
Config
,
image
*
ec2
.
Image
,
blockDevices
[]
ec2
.
BlockDeviceMapping
)
*
ec2
.
RegisterImage
{
registerOpts
:=
&
ec2
.
RegisterImage
{
Name
:
config
.
AMIName
,
Architecture
:
image
.
Architecture
,
RootDeviceName
:
image
.
RootDeviceName
,
BlockDevices
:
blockDevices
,
VirtType
:
config
.
AMIVirtType
,
}
if
config
.
AMIVirtType
!=
"hvm"
{
registerOpts
.
KernelId
=
image
.
KernelId
registerOpts
.
RamdiskId
=
image
.
RamdiskId
}
return
registerOpts
}
builder/amazon/chroot/step_register_ami_test.go
0 → 100644
View file @
e8889e56
package
chroot
import
(
"testing"
"github.com/mitchellh/goamz/ec2"
)
func
testImage
()
ec2
.
Image
{
return
ec2
.
Image
{
Id
:
"ami-abcd1234"
,
Name
:
"ami_test_name"
,
Architecture
:
"x86_64"
,
KernelId
:
"aki-abcd1234"
,
}
}
func
TestStepRegisterAmi_buildRegisterOpts_pv
(
t
*
testing
.
T
)
{
config
:=
Config
{}
config
.
AMIName
=
"test_ami_name"
config
.
AMIDescription
=
"test_ami_description"
config
.
AMIVirtType
=
"paravirtual"
image
:=
testImage
()
blockDevices
:=
[]
ec2
.
BlockDeviceMapping
{}
opts
:=
buildRegisterOpts
(
&
config
,
&
image
,
blockDevices
)
expected
:=
config
.
AMIVirtType
if
opts
.
VirtType
!=
expected
{
t
.
Fatalf
(
"Unexpected VirtType value: expected %s got %s
\n
"
,
expected
,
opts
.
VirtType
)
}
expected
=
config
.
AMIName
if
opts
.
Name
!=
expected
{
t
.
Fatalf
(
"Unexpected Name value: expected %s got %s
\n
"
,
expected
,
opts
.
Name
)
}
expected
=
image
.
KernelId
if
opts
.
KernelId
!=
expected
{
t
.
Fatalf
(
"Unexpected KernelId value: expected %s got %s
\n
"
,
expected
,
opts
.
KernelId
)
}
}
func
TestStepRegisterAmi_buildRegisterOpts_hvm
(
t
*
testing
.
T
)
{
config
:=
Config
{}
config
.
AMIName
=
"test_ami_name"
config
.
AMIDescription
=
"test_ami_description"
config
.
AMIVirtType
=
"hvm"
image
:=
testImage
()
blockDevices
:=
[]
ec2
.
BlockDeviceMapping
{}
opts
:=
buildRegisterOpts
(
&
config
,
&
image
,
blockDevices
)
expected
:=
config
.
AMIVirtType
if
opts
.
VirtType
!=
expected
{
t
.
Fatalf
(
"Unexpected VirtType value: expected %s got %s
\n
"
,
expected
,
opts
.
VirtType
)
}
expected
=
config
.
AMIName
if
opts
.
Name
!=
expected
{
t
.
Fatalf
(
"Unexpected Name value: expected %s got %s
\n
"
,
expected
,
opts
.
Name
)
}
expected
=
""
if
opts
.
KernelId
!=
expected
{
t
.
Fatalf
(
"Unexpected KernelId value: expected %s got %s
\n
"
,
expected
,
opts
.
KernelId
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment