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
c1361b0c
Commit
c1361b0c
authored
Jul 24, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/instance: ec2-bundle-vol is called
parent
fd43c27d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
3 deletions
+88
-3
builder/amazon/instance/builder.go
builder/amazon/instance/builder.go
+21
-3
builder/amazon/instance/builder_test.go
builder/amazon/instance/builder_test.go
+28
-0
builder/amazon/instance/step_bundle_volume.go
builder/amazon/instance/step_bundle_volume.go
+36
-0
builder/amazon/instance/step_upload_x509_cert.go
builder/amazon/instance/step_upload_x509_cert.go
+3
-0
No files found.
builder/amazon/instance/builder.go
View file @
c1361b0c
...
...
@@ -13,6 +13,7 @@ import (
"github.com/mitchellh/packer/packer"
"log"
"os"
"strings"
)
// The unique ID for this builder
...
...
@@ -25,9 +26,11 @@ type Config struct {
awscommon
.
AccessConfig
`mapstructure:",squash"`
awscommon
.
RunConfig
`mapstructure:",squash"`
X509CertPath
string
`mapstructure:"x509_cert_path"`
X509KeyPath
string
`mapstructure:"x509_key_path"`
X509UploadPath
string
`mapstructure:"x509_upload_path"`
AccountId
string
`mapstructure:"account_id"`
BundleVolCommand
string
`mapstructure:"bundle_vol_command"`
X509CertPath
string
`mapstructure:"x509_cert_path"`
X509KeyPath
string
`mapstructure:"x509_key_path"`
X509UploadPath
string
`mapstructure:"x509_upload_path"`
}
type
Builder
struct
{
...
...
@@ -46,6 +49,21 @@ func (b *Builder) Prepare(raws ...interface{}) error {
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
AccessConfig
.
Prepare
()
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
RunConfig
.
Prepare
()
...
)
if
b
.
config
.
AccountId
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errors
.
New
(
"account_id is required"
))
}
else
{
b
.
config
.
AccountId
=
strings
.
Replace
(
b
.
config
.
AccountId
,
"-"
,
""
,
-
1
)
}
if
b
.
config
.
BundleVolCommand
==
""
{
b
.
config
.
BundleVolCommand
=
"ec2-bundle-vol "
+
"-k {{.KeyPath}} "
+
"-u {{.AccountId}} "
+
"-c {{.CertPath}} "
+
"-r {{.Architecture}} "
+
"-e {{.PrivatePath}}"
}
if
b
.
config
.
X509CertPath
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errors
.
New
(
"x509_cert_path is required"
))
}
else
if
_
,
err
:=
os
.
Stat
(
b
.
config
.
X509CertPath
);
err
!=
nil
{
...
...
builder/amazon/instance/builder_test.go
View file @
c1361b0c
...
...
@@ -14,6 +14,7 @@ func testConfig() map[string]interface{} {
}
return
map
[
string
]
interface
{}{
"account_id"
:
"foo"
,
"instance_type"
:
"m1.small"
,
"region"
:
"us-east-1"
,
"source_ami"
:
"foo"
,
...
...
@@ -32,6 +33,33 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
}
}
func
TestBuilderPrepare_AccountId
(
t
*
testing
.
T
)
{
b
:=
&
Builder
{}
config
:=
testConfig
()
config
[
"account_id"
]
=
""
err
:=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
config
[
"account_id"
]
=
"foo"
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Errorf
(
"err: %s"
,
err
)
}
config
[
"account_id"
]
=
"0123-0456-7890"
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
b
.
config
.
AccountId
!=
"012304567890"
{
t
.
Errorf
(
"should strip hyphens: %s"
,
b
.
config
.
AccountId
)
}
}
func
TestBuilderPrepare_InvalidKey
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
...
...
builder/amazon/instance/step_bundle_volume.go
View file @
c1361b0c
package
instance
import
(
"bytes"
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"text/template"
)
type
bundleCmdData
struct
{
AccountId
string
Architecture
string
CertPath
string
KeyPath
string
PrivatePath
string
}
type
StepBundleVolume
struct
{}
func
(
s
*
StepBundleVolume
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
comm
:=
state
[
"communicator"
]
.
(
packer
.
Communicator
)
config
:=
state
[
"config"
]
.
(
*
Config
)
instance
:=
state
[
"instance"
]
.
(
*
ec2
.
Instance
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
x509RemoteCertPath
:=
state
[
"x509RemoteCertPath"
]
.
(
string
)
x509RemoteKeyPath
:=
state
[
"x509RemoteKeyPath"
]
.
(
string
)
// Verify the AMI tools are available
ui
.
Say
(
"Checking for EC2 AMI tools..."
)
...
...
@@ -31,6 +46,27 @@ func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepActio
return
multistep
.
ActionHalt
}
// Bundle the volume
var
bundleCmd
bytes
.
Buffer
tData
:=
bundleCmdData
{
AccountId
:
config
.
AccountId
,
Architecture
:
instance
.
Architecture
,
CertPath
:
x509RemoteCertPath
,
KeyPath
:
x509RemoteKeyPath
,
PrivatePath
:
config
.
X509UploadPath
,
}
t
:=
template
.
Must
(
template
.
New
(
"bundleCmd"
)
.
Parse
(
config
.
BundleVolCommand
))
t
.
Execute
(
&
bundleCmd
,
tData
)
ui
.
Say
(
"Bundling the volume..."
)
cmd
=
new
(
packer
.
RemoteCmd
)
cmd
.
Command
=
bundleCmd
.
String
()
if
err
:=
cmd
.
StartWithUi
(
comm
,
ui
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error bundling volume: %s"
,
err
)
ui
.
Error
(
state
[
"error"
]
.
(
error
)
.
Error
())
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
...
...
builder/amazon/instance/step_upload_x509_cert.go
View file @
c1361b0c
...
...
@@ -30,6 +30,9 @@ func (s *StepUploadX509Cert) Run(state map[string]interface{}) multistep.StepAct
return
multistep
.
ActionHalt
}
state
[
"x509RemoteCertPath"
]
=
x509RemoteCertPath
state
[
"x509RemoteKeyPath"
]
=
x509RemoteKeyPath
return
multistep
.
ActionContinue
}
...
...
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