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
7d0f9483
Commit
7d0f9483
authored
May 27, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/digitalocean: interpolation change
parent
8d480d69
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
17 additions
and
44 deletions
+17
-44
builder/digitalocean/builder.go
builder/digitalocean/builder.go
+9
-36
builder/digitalocean/ssh.go
builder/digitalocean/ssh.go
+2
-2
builder/digitalocean/step_create_droplet.go
builder/digitalocean/step_create_droplet.go
+2
-2
builder/digitalocean/step_create_ssh_key.go
builder/digitalocean/step_create_ssh_key.go
+1
-1
builder/digitalocean/step_droplet_info.go
builder/digitalocean/step_droplet_info.go
+1
-1
builder/digitalocean/step_power_off.go
builder/digitalocean/step_power_off.go
+1
-1
builder/digitalocean/step_snapshot.go
builder/digitalocean/step_snapshot.go
+1
-1
No files found.
builder/digitalocean/builder.go
View file @
7d0f9483
...
...
@@ -13,7 +13,9 @@ import (
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/common/uuid"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
)
// see https://api.digitalocean.com/images/?client_id=[client_id]&api_key=[api_key]
...
...
@@ -34,7 +36,7 @@ const BuilderId = "pearkes.digitalocean"
// Configuration tells the builder the credentials
// to use while communicating with DO and describes the image
// you are creating
type
c
onfig
struct
{
type
C
onfig
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
ClientID
string
`mapstructure:"client_id"`
...
...
@@ -63,29 +65,23 @@ type config struct {
sshTimeout
time
.
Duration
stateTimeout
time
.
Duration
ctx
*
interpolate
.
Context
tpl
*
packer
.
ConfigTemplate
}
type
Builder
struct
{
config
c
onfig
config
C
onfig
runner
multistep
.
Runner
}
func
(
b
*
Builder
)
Prepare
(
raws
...
interface
{})
([]
string
,
error
)
{
md
,
err
:=
common
.
DecodeConfig
(
&
b
.
config
,
raws
...
)
err
:=
config
.
Decode
(
&
b
.
config
,
&
config
.
DecodeOpts
{
Interpolate
:
true
,
},
raws
...
)
if
err
!=
nil
{
return
nil
,
err
}
b
.
config
.
tpl
,
err
=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
return
nil
,
err
}
b
.
config
.
tpl
.
UserVars
=
b
.
config
.
PackerUserVars
// Accumulate any errors
errs
:=
common
.
CheckUnusedConfig
(
md
)
// Optional configuration with defaults
if
b
.
config
.
APIKey
==
""
{
// Default to environment variable for api_key, if it exists
...
...
@@ -163,30 +159,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b
.
config
.
RawStateTimeout
=
"6m"
}
templates
:=
map
[
string
]
*
string
{
"region"
:
&
b
.
config
.
Region
,
"size"
:
&
b
.
config
.
Size
,
"image"
:
&
b
.
config
.
Image
,
"client_id"
:
&
b
.
config
.
ClientID
,
"api_key"
:
&
b
.
config
.
APIKey
,
"api_url"
:
&
b
.
config
.
APIURL
,
"api_token"
:
&
b
.
config
.
APIToken
,
"snapshot_name"
:
&
b
.
config
.
SnapshotName
,
"droplet_name"
:
&
b
.
config
.
DropletName
,
"ssh_username"
:
&
b
.
config
.
SSHUsername
,
"ssh_timeout"
:
&
b
.
config
.
RawSSHTimeout
,
"state_timeout"
:
&
b
.
config
.
RawStateTimeout
,
}
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
b
.
config
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
var
errs
*
packer
.
MultiError
if
b
.
config
.
APIToken
==
""
{
// Required configurations that will display errors if not set
if
b
.
config
.
ClientID
==
""
{
...
...
builder/digitalocean/ssh.go
View file @
7d0f9483
...
...
@@ -7,13 +7,13 @@ import (
)
func
sshAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
config
:=
state
.
Get
(
"config"
)
.
(
c
onfig
)
config
:=
state
.
Get
(
"config"
)
.
(
C
onfig
)
ipAddress
:=
state
.
Get
(
"droplet_ip"
)
.
(
string
)
return
fmt
.
Sprintf
(
"%s:%d"
,
ipAddress
,
config
.
SSHPort
),
nil
}
func
sshConfig
(
state
multistep
.
StateBag
)
(
*
ssh
.
ClientConfig
,
error
)
{
config
:=
state
.
Get
(
"config"
)
.
(
c
onfig
)
config
:=
state
.
Get
(
"config"
)
.
(
C
onfig
)
privateKey
:=
state
.
Get
(
"privateKey"
)
.
(
string
)
signer
,
err
:=
ssh
.
ParsePrivateKey
([]
byte
(
privateKey
))
...
...
builder/digitalocean/step_create_droplet.go
View file @
7d0f9483
...
...
@@ -14,7 +14,7 @@ type stepCreateDroplet struct {
func
(
s
*
stepCreateDroplet
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
client
:=
state
.
Get
(
"client"
)
.
(
DigitalOceanClient
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
c
:=
state
.
Get
(
"config"
)
.
(
c
onfig
)
c
:=
state
.
Get
(
"config"
)
.
(
C
onfig
)
sshKeyId
:=
state
.
Get
(
"ssh_key_id"
)
.
(
uint
)
ui
.
Say
(
"Creating droplet..."
)
...
...
@@ -46,7 +46,7 @@ func (s *stepCreateDroplet) Cleanup(state multistep.StateBag) {
client
:=
state
.
Get
(
"client"
)
.
(
DigitalOceanClient
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
c
:=
state
.
Get
(
"config"
)
.
(
c
onfig
)
c
:=
state
.
Get
(
"config"
)
.
(
C
onfig
)
// Destroy the droplet we just created
ui
.
Say
(
"Destroying droplet..."
)
...
...
builder/digitalocean/step_create_ssh_key.go
View file @
7d0f9483
...
...
@@ -73,7 +73,7 @@ func (s *stepCreateSSHKey) Cleanup(state multistep.StateBag) {
client
:=
state
.
Get
(
"client"
)
.
(
DigitalOceanClient
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
c
:=
state
.
Get
(
"config"
)
.
(
c
onfig
)
c
:=
state
.
Get
(
"config"
)
.
(
C
onfig
)
ui
.
Say
(
"Deleting temporary ssh key..."
)
err
:=
client
.
DestroyKey
(
s
.
keyId
)
...
...
builder/digitalocean/step_droplet_info.go
View file @
7d0f9483
...
...
@@ -12,7 +12,7 @@ type stepDropletInfo struct{}
func
(
s
*
stepDropletInfo
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
client
:=
state
.
Get
(
"client"
)
.
(
DigitalOceanClient
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
c
:=
state
.
Get
(
"config"
)
.
(
c
onfig
)
c
:=
state
.
Get
(
"config"
)
.
(
C
onfig
)
dropletId
:=
state
.
Get
(
"droplet_id"
)
.
(
uint
)
ui
.
Say
(
"Waiting for droplet to become active..."
)
...
...
builder/digitalocean/step_power_off.go
View file @
7d0f9483
...
...
@@ -12,7 +12,7 @@ type stepPowerOff struct{}
func
(
s
*
stepPowerOff
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
client
:=
state
.
Get
(
"client"
)
.
(
DigitalOceanClient
)
c
:=
state
.
Get
(
"config"
)
.
(
c
onfig
)
c
:=
state
.
Get
(
"config"
)
.
(
C
onfig
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
dropletId
:=
state
.
Get
(
"droplet_id"
)
.
(
uint
)
...
...
builder/digitalocean/step_snapshot.go
View file @
7d0f9483
...
...
@@ -14,7 +14,7 @@ type stepSnapshot struct{}
func
(
s
*
stepSnapshot
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
client
:=
state
.
Get
(
"client"
)
.
(
DigitalOceanClient
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
c
:=
state
.
Get
(
"config"
)
.
(
c
onfig
)
c
:=
state
.
Get
(
"config"
)
.
(
C
onfig
)
dropletId
:=
state
.
Get
(
"droplet_id"
)
.
(
uint
)
ui
.
Say
(
fmt
.
Sprintf
(
"Creating snapshot: %v"
,
c
.
SnapshotName
))
...
...
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