post-processor/atlas: support sending compile ids

Requires https://github.com/hashicorp/atlas-go/pull/44
This commit is contained in:
Jack Pearkes 2015-09-25 11:52:21 -07:00
parent 23c4c015a6
commit 6bf790a975
2 changed files with 32 additions and 2 deletions

View File

@ -15,7 +15,10 @@ import (
"github.com/mitchellh/packer/template/interpolate"
)
const BuildEnvKey = "ATLAS_BUILD_ID"
const (
BuildEnvKey = "ATLAS_BUILD_ID"
CompileEnvKey = "ATLAS_COMPILE_ID"
)
// Artifacts can return a string for this state key and the post-processor
// will use automatically use this as the type. The user's value overrides
@ -44,6 +47,7 @@ type Config struct {
ctx interpolate.Context
user, name string
buildId int
compileId int
}
type PostProcessor struct {
@ -96,6 +100,17 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
p.config.buildId = int(raw)
}
// If we have a compile ID, save it
if v := os.Getenv(CompileEnvKey); v != "" {
raw, err := strconv.ParseInt(v, 0, 0)
if err != nil {
return fmt.Errorf(
"Error parsing compile ID: %s", err)
}
p.config.compileId = int(raw)
}
// Build the client
p.client = atlas.DefaultClient()
if p.config.ServerAddr != "" {
@ -150,6 +165,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
ID: artifact.Id(),
Metadata: p.metadata(artifact),
BuildID: p.config.buildId,
CompileID: p.config.compileId,
}
if fs := artifact.Files(); len(fs) > 0 {

View File

@ -40,6 +40,20 @@ func TestPostProcessorConfigure_buildId(t *testing.T) {
}
}
func TestPostProcessorConfigure_compileId(t *testing.T) {
defer os.Setenv(CompileEnvKey, os.Getenv(CompileEnvKey))
os.Setenv(CompileEnvKey, "5")
var p PostProcessor
if err := p.Configure(validDefaults()); err != nil {
t.Fatalf("err: %s", err)
}
if p.config.compileId != 5 {
t.Fatalf("bad: %#v", p.config.compileId)
}
}
func TestPostProcessorMetadata(t *testing.T) {
var p PostProcessor
if err := p.Configure(validDefaults()); err != nil {