Commit 9239b6a2 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: {{timestamp}} is the same for an entire build [GH-744]

parent 366d1693
......@@ -61,6 +61,8 @@ BUG FIXES:
* core: User variables can now be used for non-string fields. [GH-598]
* core: Fix bad download paths if the download URL contained a "."
before a "/" [GH-716]
* core: "{{timestamp}}" values will always be the same for the entire
duration of a build. [GH-744]
* builder/virtualbox: don't download guest additions if disabled. [GH-731]
* post-processor/vsphere: Uploads VM properly. [GH-694]
* post-processor/vsphere: Process user variables.
......
......@@ -9,6 +9,15 @@ import (
"time"
)
// InitTime is the UTC time when this package was initialized. It is
// used as the timestamp for all configuration templates so that they
// match for a single build.
var InitTime time.Time
func init() {
InitTime = time.Now().UTC()
}
// ConfigTemplate processes string data as a text/template with some common
// elements and functions available. Plugin creators should process as
// many fields as possible through this.
......@@ -89,7 +98,7 @@ func templateISOTime() string {
}
func templateTimestamp() string {
return strconv.FormatInt(time.Now().UTC().Unix(), 10)
return strconv.FormatInt(InitTime.Unix(), 10)
}
func templateUuid() string {
......
......@@ -49,6 +49,17 @@ func TestConfigTemplateProcess_timestamp(t *testing.T) {
if math.Abs(float64(currentTime-val)) > 10 {
t.Fatalf("val: %d (current: %d)", val, currentTime)
}
time.Sleep(2 * time.Second)
result2, err := tpl.Process(`{{timestamp}}`, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
if result != result2 {
t.Fatalf("bad: %#v %#v", result, result2)
}
}
func TestConfigTemplateProcess_user(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment