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
f2069c1c
Commit
f2069c1c
authored
Sep 05, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #388 from jmassara/ami_region_copy
builder/amazon/all: AMI region copy fixes
parents
b2ddb24c
985ce790
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
45 additions
and
60 deletions
+45
-60
builder/amazon/chroot/builder.go
builder/amazon/chroot/builder.go
+3
-4
builder/amazon/common/artifact.go
builder/amazon/common/artifact.go
+5
-3
builder/amazon/common/step_ami_region_copy.go
builder/amazon/common/step_ami_region_copy.go
+0
-20
builder/amazon/common/step_create_tags.go
builder/amazon/common/step_create_tags.go
+18
-15
builder/amazon/common/step_modify_ami_attributes.go
builder/amazon/common/step_modify_ami_attributes.go
+13
-10
builder/amazon/ebs/builder.go
builder/amazon/ebs/builder.go
+3
-4
builder/amazon/instance/builder.go
builder/amazon/instance/builder.go
+3
-4
No files found.
builder/amazon/chroot/builder.go
View file @
f2069c1c
...
...
@@ -189,15 +189,14 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
StepEarlyCleanup
{},
&
StepSnapshot
{},
&
StepRegisterAMI
{},
&
awscommon
.
StepAMIRegionCopy
{
Regions
:
b
.
config
.
AMIRegions
,
},
&
awscommon
.
StepModifyAMIAttributes
{
Description
:
b
.
config
.
AMIDescription
,
Users
:
b
.
config
.
AMIUsers
,
Groups
:
b
.
config
.
AMIGroups
,
},
&
awscommon
.
StepAMIRegionCopy
{
Regions
:
b
.
config
.
AMIRegions
,
Tags
:
b
.
config
.
AMITags
,
},
&
awscommon
.
StepCreateTags
{
Tags
:
b
.
config
.
AMITags
,
},
...
...
builder/amazon/common/artifact.go
View file @
f2069c1c
...
...
@@ -2,6 +2,7 @@ package common
import
(
"fmt"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/packer/packer"
"log"
...
...
@@ -51,9 +52,10 @@ func (a *Artifact) String() string {
func
(
a
*
Artifact
)
Destroy
()
error
{
errors
:=
make
([]
error
,
0
)
for
_
,
imageId
:=
range
a
.
Amis
{
log
.
Printf
(
"Deregistering image ID: %s"
,
imageId
)
if
_
,
err
:=
a
.
Conn
.
DeregisterImage
(
imageId
);
err
!=
nil
{
for
region
,
imageId
:=
range
a
.
Amis
{
log
.
Printf
(
"Deregistering image ID (%s) from region (%s)"
,
imageId
,
region
)
regionconn
:=
ec2
.
New
(
a
.
Conn
.
Auth
,
aws
.
Regions
[
region
])
if
_
,
err
:=
regionconn
.
DeregisterImage
(
imageId
);
err
!=
nil
{
errors
=
append
(
errors
,
err
)
}
...
...
builder/amazon/common/step_ami_region_copy.go
View file @
f2069c1c
...
...
@@ -10,7 +10,6 @@ import (
type
StepAMIRegionCopy
struct
{
Regions
[]
string
Tags
map
[
string
]
string
}
func
(
s
*
StepAMIRegionCopy
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
...
...
@@ -49,25 +48,6 @@ func (s *StepAMIRegionCopy) Run(state multistep.StateBag) multistep.StepAction {
return
multistep
.
ActionHalt
}
// Need to re-apply Tags since they are not copied with the AMI
if
len
(
s
.
Tags
)
>
0
{
ui
.
Say
(
fmt
.
Sprintf
(
"Adding tags to AMI (%s)..."
,
resp
.
ImageId
))
var
ec2Tags
[]
ec2
.
Tag
for
key
,
value
:=
range
s
.
Tags
{
ui
.
Message
(
fmt
.
Sprintf
(
"Adding tag:
\"
%s
\"
:
\"
%s
\"
"
,
key
,
value
))
ec2Tags
=
append
(
ec2Tags
,
ec2
.
Tag
{
key
,
value
})
}
_
,
err
:=
regionconn
.
CreateTags
([]
string
{
resp
.
ImageId
},
ec2Tags
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error adding tags to AMI (%s): %s"
,
resp
.
ImageId
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
}
amis
[
region
]
=
resp
.
ImageId
}
...
...
builder/amazon/common/step_create_tags.go
View file @
f2069c1c
...
...
@@ -2,6 +2,7 @@ package common
import
(
"fmt"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
...
...
@@ -15,23 +16,25 @@ func (s *StepCreateTags) Run(state multistep.StateBag) multistep.StepAction {
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
amis
:=
state
.
Get
(
"amis"
)
.
(
map
[
string
]
string
)
ami
:=
amis
[
ec2conn
.
Region
.
Name
]
if
len
(
s
.
Tags
)
>
0
{
ui
.
Say
(
fmt
.
Sprintf
(
"Adding tags to AMI (%s)..."
,
ami
))
var
ec2Tags
[]
ec2
.
Tag
for
key
,
value
:=
range
s
.
Tags
{
ui
.
Message
(
fmt
.
Sprintf
(
"Adding tag:
\"
%s
\"
:
\"
%s
\"
"
,
key
,
value
))
ec2Tags
=
append
(
ec2Tags
,
ec2
.
Tag
{
key
,
value
})
}
_
,
err
:=
ec2conn
.
CreateTags
([]
string
{
ami
},
ec2Tags
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error adding tags to AMI (%s): %s"
,
ami
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
for
region
,
ami
:=
range
amis
{
ui
.
Say
(
fmt
.
Sprintf
(
"Adding tags to AMI (%s)..."
,
ami
))
var
ec2Tags
[]
ec2
.
Tag
for
key
,
value
:=
range
s
.
Tags
{
ui
.
Message
(
fmt
.
Sprintf
(
"Adding tag:
\"
%s
\"
:
\"
%s
\"
"
,
key
,
value
))
ec2Tags
=
append
(
ec2Tags
,
ec2
.
Tag
{
key
,
value
})
}
regionconn
:=
ec2
.
New
(
ec2conn
.
Auth
,
aws
.
Regions
[
region
])
_
,
err
:=
regionconn
.
CreateTags
([]
string
{
ami
},
ec2Tags
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error adding tags to AMI (%s): %s"
,
ami
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
}
}
...
...
builder/amazon/common/step_modify_ami_attributes.go
View file @
f2069c1c
...
...
@@ -2,6 +2,7 @@ package common
import
(
"fmt"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
...
...
@@ -18,7 +19,6 @@ func (s *StepModifyAMIAttributes) Run(state multistep.StateBag) multistep.StepAc
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
amis
:=
state
.
Get
(
"amis"
)
.
(
map
[
string
]
string
)
ami
:=
amis
[
ec2conn
.
Region
.
Name
]
// Determine if there is any work to do.
valid
:=
false
...
...
@@ -59,15 +59,18 @@ func (s *StepModifyAMIAttributes) Run(state multistep.StateBag) multistep.StepAc
}
}
ui
.
Say
(
"Modifying AMI attributes..."
)
for
name
,
opts
:=
range
options
{
ui
.
Message
(
fmt
.
Sprintf
(
"Modifying: %s"
,
name
))
_
,
err
:=
ec2conn
.
ModifyImageAttribute
(
ami
,
opts
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error modify AMI attributes: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
for
region
,
ami
:=
range
amis
{
ui
.
Say
(
fmt
.
Sprintf
(
"Modifying attributes on AMI (%s)..."
,
ami
))
regionconn
:=
ec2
.
New
(
ec2conn
.
Auth
,
aws
.
Regions
[
region
])
for
name
,
opts
:=
range
options
{
ui
.
Message
(
fmt
.
Sprintf
(
"Modifying: %s"
,
name
))
_
,
err
:=
regionconn
.
ModifyImageAttribute
(
ami
,
opts
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error modify AMI attributes: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
}
}
...
...
builder/amazon/ebs/builder.go
View file @
f2069c1c
...
...
@@ -110,15 +110,14 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
common
.
StepProvision
{},
&
stepStopInstance
{},
&
stepCreateAMI
{},
&
awscommon
.
StepAMIRegionCopy
{
Regions
:
b
.
config
.
AMIRegions
,
},
&
awscommon
.
StepModifyAMIAttributes
{
Description
:
b
.
config
.
AMIDescription
,
Users
:
b
.
config
.
AMIUsers
,
Groups
:
b
.
config
.
AMIGroups
,
},
&
awscommon
.
StepAMIRegionCopy
{
Regions
:
b
.
config
.
AMIRegions
,
Tags
:
b
.
config
.
AMITags
,
},
&
awscommon
.
StepCreateTags
{
Tags
:
b
.
config
.
AMITags
,
},
...
...
builder/amazon/instance/builder.go
View file @
f2069c1c
...
...
@@ -215,16 +215,15 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
StepBundleVolume
{},
&
StepUploadBundle
{},
&
StepRegisterAMI
{},
&
awscommon
.
StepAMIRegionCopy
{
Regions
:
b
.
config
.
AMIRegions
,
},
&
awscommon
.
StepModifyAMIAttributes
{
Description
:
b
.
config
.
AMIDescription
,
Users
:
b
.
config
.
AMIUsers
,
Groups
:
b
.
config
.
AMIGroups
,
ProductCodes
:
b
.
config
.
AMIProductCodes
,
},
&
awscommon
.
StepAMIRegionCopy
{
Regions
:
b
.
config
.
AMIRegions
,
Tags
:
b
.
config
.
AMITags
,
},
&
awscommon
.
StepCreateTags
{
Tags
:
b
.
config
.
AMITags
,
},
...
...
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