Fix Google Compute Export Post-Processor (#9708)
* Fix Google Compute Export Post-Processor The current Post-Processor hangs on waiting for the Startup Script to finish. The startup script doesn't update the metadata (StartupScriptStatusKey) so this change aims to fix that but adding the `SetMetadata` functionality to this script. * Update startup.go
This commit is contained in:
parent
04d7a10aa0
commit
6d1a146143
|
@ -1,15 +1,36 @@
|
||||||
package googlecomputeexport
|
package googlecomputeexport
|
||||||
|
|
||||||
var StartupScript string = `#!/bin/bash
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/hashicorp/packer/builder/googlecompute"
|
||||||
|
)
|
||||||
|
|
||||||
|
var StartupScript string = fmt.Sprintf(`#!/bin/bash
|
||||||
|
|
||||||
GetMetadata () {
|
GetMetadata () {
|
||||||
echo "$(curl -f -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/attributes/$1 2> /dev/null)"
|
echo "$(curl -f -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/attributes/$1 2> /dev/null)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZONE=$(basename $(GetMetadata zone))
|
||||||
|
|
||||||
|
SetMetadata () {
|
||||||
|
gcloud compute instances add-metadata ${HOSTNAME} --metadata ${1}=${2} --zone ${ZONE}
|
||||||
|
}
|
||||||
|
|
||||||
|
STARTUPSCRIPT=$(GetMetadata attributes/%s)
|
||||||
|
STARTUPSCRIPTPATH=/packer-wrapped-startup-script
|
||||||
|
if [ -f "/var/log/startupscript.log" ]; then
|
||||||
|
STARTUPSCRIPTLOGPATH=/var/log/startupscript.log
|
||||||
|
else
|
||||||
|
STARTUPSCRIPTLOGPATH=/var/log/daemon.log
|
||||||
|
fi
|
||||||
|
STARTUPSCRIPTLOGDEST=$(GetMetadata attributes/startup-script-log-dest)
|
||||||
|
|
||||||
IMAGENAME=$(GetMetadata image_name)
|
IMAGENAME=$(GetMetadata image_name)
|
||||||
NAME=$(GetMetadata name)
|
NAME=$(GetMetadata name)
|
||||||
DISKNAME=${NAME}-toexport
|
DISKNAME=${NAME}-toexport
|
||||||
PATHS=($(GetMetadata paths))
|
PATHS=($(GetMetadata paths))
|
||||||
ZONE=$(GetMetadata zone)
|
|
||||||
|
|
||||||
Exit () {
|
Exit () {
|
||||||
for i in ${PATHS[@]}; do
|
for i in ${PATHS[@]}; do
|
||||||
|
@ -70,5 +91,7 @@ for i in ${PATHS[@]:1}; do
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
SetMetadata %s %s
|
||||||
|
|
||||||
Exit ${FAIL}
|
Exit ${FAIL}
|
||||||
`
|
`, googlecompute.StartupWrappedScriptKey, googlecompute.StartupScriptStatusKey, googlecompute.StartupScriptStatusDone)
|
||||||
|
|
Loading…
Reference in New Issue