|
|
|
|
@ -4,6 +4,7 @@
|
|
|
|
|
package digitalocean
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
|
@ -11,12 +12,18 @@ import (
|
|
|
|
|
"github.com/mitchellh/packer/builder/common"
|
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
|
"log"
|
|
|
|
|
"strconv"
|
|
|
|
|
"text/template"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// The unique id for the builder
|
|
|
|
|
const BuilderId = "pearkes.digitalocean"
|
|
|
|
|
|
|
|
|
|
type snapshotNameData struct {
|
|
|
|
|
CreateTime string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Configuration tells the builder the credentials
|
|
|
|
|
// to use while communicating with DO and describes the image
|
|
|
|
|
// you are creating
|
|
|
|
|
@ -27,7 +34,7 @@ type config struct {
|
|
|
|
|
SizeID uint `mapstructure:"size_id"`
|
|
|
|
|
ImageID uint `mapstructure:"image_id"`
|
|
|
|
|
|
|
|
|
|
SnapshotName string `mapstructure:"snapshot_name"`
|
|
|
|
|
SnapshotName string
|
|
|
|
|
SSHUsername string `mapstructure:"ssh_username"`
|
|
|
|
|
SSHPort uint `mapstructure:"ssh_port"`
|
|
|
|
|
SSHTimeout time.Duration
|
|
|
|
|
@ -35,8 +42,9 @@ type config struct {
|
|
|
|
|
|
|
|
|
|
PackerDebug bool `mapstructure:"packer_debug"`
|
|
|
|
|
|
|
|
|
|
RawSSHTimeout string `mapstructure:"ssh_timeout"`
|
|
|
|
|
RawEventDelay string `mapstructure:"event_delay"`
|
|
|
|
|
RawSnapshotName string `mapstructure:"snapshot_name"`
|
|
|
|
|
RawSSHTimeout string `mapstructure:"ssh_timeout"`
|
|
|
|
|
RawEventDelay string `mapstructure:"event_delay"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Builder struct {
|
|
|
|
|
@ -80,9 +88,9 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
|
|
|
|
b.config.SSHPort = 22
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if b.config.SnapshotName == "" {
|
|
|
|
|
if b.config.RawSnapshotName == "" {
|
|
|
|
|
// Default to packer-{{ unix timestamp (utc) }}
|
|
|
|
|
b.config.SnapshotName = "packer-{{.CreateTime}}"
|
|
|
|
|
b.config.RawSnapshotName = "packer-{{.CreateTime}}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if b.config.RawSSHTimeout == "" {
|
|
|
|
|
@ -121,6 +129,15 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
|
|
|
|
}
|
|
|
|
|
b.config.EventDelay = delay
|
|
|
|
|
|
|
|
|
|
// Parse the name of the snapshot
|
|
|
|
|
snapNameBuf := new(bytes.Buffer)
|
|
|
|
|
tData := snapshotNameData{
|
|
|
|
|
strconv.FormatInt(time.Now().UTC().Unix(), 10),
|
|
|
|
|
}
|
|
|
|
|
t := template.Must(template.New("snapshot").Parse(b.config.RawSnapshotName))
|
|
|
|
|
t.Execute(snapNameBuf, tData)
|
|
|
|
|
b.config.SnapshotName = snapNameBuf.String()
|
|
|
|
|
|
|
|
|
|
if len(errs) > 0 {
|
|
|
|
|
return &packer.MultiError{errs}
|
|
|
|
|
}
|
|
|
|
|
|