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
818a10e7
Commit
818a10e7
authored
Jul 30, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/chroot: use set AMI name
parent
743682d3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
1 deletion
+61
-1
builder/amazon/chroot/builder.go
builder/amazon/chroot/builder.go
+14
-0
builder/amazon/chroot/builder_test.go
builder/amazon/chroot/builder_test.go
+29
-0
builder/amazon/chroot/step_register_ami.go
builder/amazon/chroot/step_register_ami.go
+18
-1
No files found.
builder/amazon/chroot/builder.go
View file @
818a10e7
...
...
@@ -6,6 +6,7 @@ package chroot
import
(
"errors"
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
awscommon
"github.com/mitchellh/packer/builder/amazon/common"
...
...
@@ -13,6 +14,7 @@ import (
"github.com/mitchellh/packer/packer"
"log"
"runtime"
"text/template"
)
// The unique ID for this builder
...
...
@@ -24,6 +26,7 @@ type Config struct {
common
.
PackerConfig
`mapstructure:",squash"`
awscommon
.
AccessConfig
`mapstructure:",squash"`
AMIName
string
`mapstructure:"ami_name"`
ChrootMounts
[][]
string
`mapstructure:"chroot_mounts"`
CopyFiles
[]
string
`mapstructure:"copy_files"`
DevicePath
string
`mapstructure:"device_path"`
...
...
@@ -83,6 +86,17 @@ func (b *Builder) Prepare(raws ...interface{}) error {
errs
:=
common
.
CheckUnusedConfig
(
md
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
AccessConfig
.
Prepare
()
...
)
if
b
.
config
.
AMIName
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errors
.
New
(
"ami_name must be specified"
))
}
else
{
_
,
err
=
template
.
New
(
"ami"
)
.
Parse
(
b
.
config
.
AMIName
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Failed parsing ami_name: %s"
,
err
))
}
}
for
_
,
mounts
:=
range
b
.
config
.
ChrootMounts
{
if
len
(
mounts
)
!=
3
{
errs
=
packer
.
MultiErrorAppend
(
...
...
builder/amazon/chroot/builder_test.go
View file @
818a10e7
...
...
@@ -7,6 +7,7 @@ import (
func
testConfig
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
"ami_name"
:
"foo"
,
"source_ami"
:
"foo"
,
}
}
...
...
@@ -19,6 +20,34 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
}
}
func
TestBuilderPrepare_AMIName
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test good
config
[
"ami_name"
]
=
"foo"
err
:=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
// Test bad
config
[
"ami_name"
]
=
"foo {{"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
// Test bad
delete
(
config
,
"ami_name"
)
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
}
func
TestBuilderPrepare_ChrootMounts
(
t
*
testing
.
T
)
{
b
:=
&
Builder
{}
config
:=
testConfig
()
...
...
builder/amazon/chroot/step_register_ami.go
View file @
818a10e7
package
chroot
import
(
"bytes"
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
awscommon
"github.com/mitchellh/packer/builder/amazon/common"
"github.com/mitchellh/packer/packer"
"strconv"
"text/template"
"time"
)
type
amiNameData
struct
{
CreateTime
string
}
// StepRegisterAMI creates the AMI.
type
StepRegisterAMI
struct
{}
func
(
s
*
StepRegisterAMI
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
Config
)
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
image
:=
state
[
"source_image"
]
.
(
*
ec2
.
Image
)
snapshotId
:=
state
[
"snapshot_id"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
amiName
:=
"foo"
// Parse the name of the AMI
amiNameBuf
:=
new
(
bytes
.
Buffer
)
tData
:=
amiNameData
{
strconv
.
FormatInt
(
time
.
Now
()
.
UTC
()
.
Unix
(),
10
),
}
t
:=
template
.
Must
(
template
.
New
(
"ami"
)
.
Parse
(
config
.
AMIName
))
t
.
Execute
(
amiNameBuf
,
tData
)
amiName
:=
amiNameBuf
.
String
()
ui
.
Say
(
"Registering the AMI..."
)
blockDevices
:=
make
([]
ec2
.
BlockDeviceMapping
,
len
(
image
.
BlockDevices
))
...
...
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