Documentation
¶
Index ¶
Constants ¶
View Source
const BuilderId = "packer.post-processor.googlecompute-export"
Variables ¶
View Source
var StartupScript string = fmt.Sprintf(`#!/bin/bash GetMetadata () { 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) NAME=$(GetMetadata name) DISKNAME=${NAME}-toexport PATHS=($(GetMetadata paths)) Exit () { for i in ${PATHS[@]}; do LOGDEST="${i}.exporter.log" echo "Uploading exporter log to ${LOGDEST}..." gsutil -h "Content-Type:text/plain" cp /var/log/daemon.log ${LOGDEST} done exit $1 } echo "####### Export configuration #######" echo "Image name - ${IMAGENAME}" echo "Instance name - ${NAME}" echo "Instance zone - ${ZONE}" echo "Disk name - ${DISKNAME}" echo "Export paths - ${PATHS}" echo "####################################" echo "Creating disk from image to be exported..." if ! gcloud compute disks create ${DISKNAME} --image ${IMAGENAME} --zone ${ZONE}; then echo "Failed to create disk." Exit 1 fi echo "Attaching disk..." if ! gcloud compute instances attach-disk ${NAME} --disk ${DISKNAME} --device-name toexport --zone ${ZONE}; then echo "Failed to attach disk." Exit 1 fi echo "GCEExport: Running export tool." gce_export -gcs_path "${PATHS[0]}" -disk /dev/disk/by-id/google-toexport -y if [ $? -ne 0 ]; then echo "ExportFailed: Failed to export disk source to ${PATHS[0]}." Exit 1 fi echo "ExportSuccess" sync echo "Detaching disk..." if ! gcloud compute instances detach-disk ${NAME} --disk ${DISKNAME} --zone ${ZONE}; then echo "Failed to detach disk." fi FAIL=0 echo "Deleting disk..." if ! gcloud compute disks delete ${DISKNAME} --zone ${ZONE}; then echo "Failed to delete disk." FAIL=1 fi for i in ${PATHS[@]:1}; do echo "Copying archive image to ${i}..." if ! gsutil -o GSUtil:parallel_composite_upload_threshold=100M cp ${PATHS[0]} ${i}; then echo "Failed to copy image to ${i}." FAIL=1 fi done SetMetadata %s %s Exit ${FAIL} `, googlecompute.StartupWrappedScriptKey, googlecompute.StartupScriptStatusKey, googlecompute.StartupScriptStatusDone)
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { common.PackerConfig `mapstructure:",squash"` //The JSON file containing your account credentials. //If specified, the account file will take precedence over any `googlecompute` builder authentication method. AccountFile string `mapstructure:"account_file"` // This allows service account impersonation as per the [docs](https://cloud.google.com/iam/docs/impersonating-service-accounts). ImpersonateServiceAccount string `mapstructure:"impersonate_service_account" required:"false"` //The size of the export instances disk. //The disk is unused for the export but a larger size will increase `pd-ssd` read speed. //This defaults to `200`, which is 200GB. DiskSizeGb int64 `mapstructure:"disk_size"` //Type of disk used to back the export instance, like //`pd-ssd` or `pd-standard`. Defaults to `pd-ssd`. DiskType string `mapstructure:"disk_type"` //The export instance machine type. Defaults to `"n1-highcpu-4"`. MachineType string `mapstructure:"machine_type"` //The Google Compute network id or URL to use for the export instance. //Defaults to `"default"`. If the value is not a URL, it //will be interpolated to `projects/((builder_project_id))/global/networks/((network))`. //This value is not required if a `subnet` is specified. Network string `mapstructure:"network"` //A list of GCS paths where the image will be exported. //For example `'gs://mybucket/path/to/file.tar.gz'` Paths []string `mapstructure:"paths" required:"true"` //The Google Compute subnetwork id or URL to use for //the export instance. Only required if the `network` has been created with //custom subnetting. Note, the region of the subnetwork must match the //`zone` in which the VM is launched. If the value is not a URL, //it will be interpolated to //`projects/((builder_project_id))/regions/((region))/subnetworks/((subnetwork))` Subnetwork string `mapstructure:"subnetwork"` //The zone in which to launch the export instance. Defaults //to `googlecompute` builder zone. Example: `"us-central1-a"` Zone string `mapstructure:"zone"` IAP bool `mapstructure-to-hcl2:",skip"` VaultGCPOauthEngine string `mapstructure:"vault_gcp_oauth_engine"` ServiceAccountEmail string `mapstructure:"service_account_email"` // contains filtered or unexported fields }
func (*Config) FlatMapstructure ¶ added in v1.4.5
FlatMapstructure returns a new FlatConfig. FlatConfig is an auto-generated flat version of Config. Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
type FlatConfig ¶ added in v1.4.5
type FlatConfig struct { PackerBuildName *string `mapstructure:"packer_build_name" cty:"packer_build_name" hcl:"packer_build_name"` PackerBuilderType *string `mapstructure:"packer_builder_type" cty:"packer_builder_type" hcl:"packer_builder_type"` PackerCoreVersion *string `mapstructure:"packer_core_version" cty:"packer_core_version" hcl:"packer_core_version"` PackerDebug *bool `mapstructure:"packer_debug" cty:"packer_debug" hcl:"packer_debug"` PackerForce *bool `mapstructure:"packer_force" cty:"packer_force" hcl:"packer_force"` PackerOnError *string `mapstructure:"packer_on_error" cty:"packer_on_error" hcl:"packer_on_error"` PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` AccountFile *string `mapstructure:"account_file" cty:"account_file" hcl:"account_file"` ImpersonateServiceAccount *string `` /* 127-byte string literal not displayed */ DiskSizeGb *int64 `mapstructure:"disk_size" cty:"disk_size" hcl:"disk_size"` DiskType *string `mapstructure:"disk_type" cty:"disk_type" hcl:"disk_type"` MachineType *string `mapstructure:"machine_type" cty:"machine_type" hcl:"machine_type"` Network *string `mapstructure:"network" cty:"network" hcl:"network"` Paths []string `mapstructure:"paths" required:"true" cty:"paths" hcl:"paths"` Subnetwork *string `mapstructure:"subnetwork" cty:"subnetwork" hcl:"subnetwork"` Zone *string `mapstructure:"zone" cty:"zone" hcl:"zone"` VaultGCPOauthEngine *string `mapstructure:"vault_gcp_oauth_engine" cty:"vault_gcp_oauth_engine" hcl:"vault_gcp_oauth_engine"` ServiceAccountEmail *string `mapstructure:"service_account_email" cty:"service_account_email" hcl:"service_account_email"` }
FlatConfig is an auto-generated flat version of Config. Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
type PostProcessor ¶
type PostProcessor struct {
// contains filtered or unexported fields
}
func (*PostProcessor) ConfigSpec ¶ added in v1.5.0
func (p *PostProcessor) ConfigSpec() hcldec.ObjectSpec
func (*PostProcessor) Configure ¶
func (p *PostProcessor) Configure(raws ...interface{}) error
Source Files
¶
Click to show internal directories.
Click to hide internal directories.