Merge pull request #4102 from crunk1/master

googlecompute: conditionally omit the wait for startup script.
This commit is contained in:
Matthew Hooker
2016-11-02 15:36:13 -07:00
committed by GitHub
5 changed files with 13 additions and 12 deletions
+4 -3
View File
@@ -72,10 +72,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
WinRMConfig: winrmConfig,
},
new(common.StepProvision),
new(StepWaitInstanceStartup),
new(StepTeardownInstance),
new(StepCreateImage),
}
if _, exists := b.config.Metadata[StartupScriptKey]; exists || b.config.StartupScriptFile != "" {
steps = append(steps, new(StepWaitStartupScript))
}
steps = append(steps, new(StepTeardownInstance), new(StepCreateImage))
// Run the steps.
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
+3 -3
View File
@@ -12,19 +12,19 @@ const StartupScriptStatusDone string = "done"
const StartupScriptStatusError string = "error"
const StartupScriptStatusNotDone string = "notdone"
var StartupScriptLinux string = fmt.Sprintf(`#!/bin/bash
var StartupScriptLinux string = fmt.Sprintf(`#!/usr/bin/env bash
echo "Packer startup script starting."
RETVAL=0
BASEMETADATAURL=http://metadata/computeMetadata/v1/instance/
GetMetadata () {
echo "$(curl -f -H "Metadata-Flavor: Google" ${BASEMETADATAURL}/${1} 2> /dev/null)"
echo "$(curl -f -H "Metadata-Flavor: Google" ${BASEMETADATAURL}/${1} 2> /dev/null)"
}
ZONE=$(GetMetadata zone | grep -oP "[^/]*$")
SetMetadata () {
gcloud compute instances add-metadata ${HOSTNAME} --metadata ${1}=${2} --zone ${ZONE}
gcloud compute instances add-metadata ${HOSTNAME} --metadata ${1}=${2} --zone ${ZONE}
}
STARTUPSCRIPT=$(GetMetadata attributes/%s)
@@ -9,11 +9,11 @@ import (
"github.com/mitchellh/packer/packer"
)
type StepWaitInstanceStartup int
type StepWaitStartupScript int
// Run reads the instance metadata and looks for the log entry
// indicating the startup script finished.
func (s *StepWaitInstanceStartup) Run(state multistep.StateBag) multistep.StepAction {
func (s *StepWaitStartupScript) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config)
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
@@ -55,4 +55,4 @@ func (s *StepWaitInstanceStartup) Run(state multistep.StateBag) multistep.StepAc
}
// Cleanup.
func (s *StepWaitInstanceStartup) Cleanup(state multistep.StateBag) {}
func (s *StepWaitStartupScript) Cleanup(state multistep.StateBag) {}
@@ -6,9 +6,9 @@ import (
"testing"
)
func TestStepWaitInstanceStartup(t *testing.T) {
func TestStepWaitStartupScript(t *testing.T) {
state := testState(t)
step := new(StepWaitInstanceStartup)
step := new(StepWaitStartupScript)
c := state.Get("config").(*Config)
d := state.Get("driver").(*DriverMock)
@@ -110,7 +110,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
&googlecompute.StepCreateInstance{
Debug: p.config.PackerDebug,
},
new(googlecompute.StepWaitInstanceStartup),
new(googlecompute.StepWaitStartupScript),
new(googlecompute.StepTeardownInstance),
}