From 6a201211a9aaaba6ddabca1800714f882a73b897 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 26 Jul 2019 15:20:32 -0700 Subject: [PATCH 1/2] fix polling issues in azure adds a configurable timeout to the shared image gallery publisher --- builder/azure/arm/azure_client.go | 4 +++- builder/azure/arm/builder.go | 1 + builder/azure/arm/config.go | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/builder/azure/arm/azure_client.go b/builder/azure/arm/azure_client.go index 1b81ec2f5..ab4330e37 100644 --- a/builder/azure/arm/azure_client.go +++ b/builder/azure/arm/azure_client.go @@ -9,6 +9,7 @@ import ( "net/url" "os" "strconv" + "time" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute" newCompute "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-03-01/compute" @@ -126,7 +127,7 @@ func byConcatDecorators(decorators ...autorest.RespondDecorator) autorest.Respon } func NewAzureClient(subscriptionID, resourceGroupName, storageAccountName string, - cloud *azure.Environment, + cloud *azure.Environment, SharedGalleryTimeout time.Duration, servicePrincipalToken, servicePrincipalTokenVault *adal.ServicePrincipalToken) (*AzureClient, error) { var azureClient = &AzureClient{} @@ -210,6 +211,7 @@ func NewAzureClient(subscriptionID, resourceGroupName, storageAccountName string azureClient.GalleryImageVersionsClient.RequestInspector = withInspection(maxlen) azureClient.GalleryImageVersionsClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient)) azureClient.GalleryImageVersionsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.GalleryImageVersionsClient.UserAgent) + azureClient.GalleryImageVersionsClient.Client.PollingDuration = SharedGalleryTimeout azureClient.GalleryImagesClient = newCompute.NewGalleryImagesClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID) azureClient.GalleryImagesClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken) diff --git a/builder/azure/arm/builder.go b/builder/azure/arm/builder.go index 7b64e0b15..2be58819d 100644 --- a/builder/azure/arm/builder.go +++ b/builder/azure/arm/builder.go @@ -90,6 +90,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack b.config.ResourceGroupName, b.config.StorageAccount, b.config.cloudEnvironment, + b.config.SharedGalleryTimeout, spnCloud, spnKeyVault) diff --git a/builder/azure/arm/config.go b/builder/azure/arm/config.go index af34754dc..5e9b8905c 100644 --- a/builder/azure/arm/config.go +++ b/builder/azure/arm/config.go @@ -96,6 +96,7 @@ type Config struct { // Shared Gallery Destination SharedGalleryDestination SharedImageGalleryDestination `mapstructure:"shared_image_gallery_destination"` + SharedGalleryTimeout time.Duration `mapstructure:"shared_image_gallery_timeout"` // Compute ImagePublisher string `mapstructure:"image_publisher"` @@ -648,6 +649,10 @@ func assertRequiredParametersSet(c *Config, errs *packer.MultiError) { errs = packer.MultiErrorAppend(errs, fmt.Errorf("A list of replication_regions must be specified for shared_image_gallery_destination")) } } + if c.SharedGalleryTimeout == 0 { + // default to a one-hour timeout. In the sdk, the default is 15 m. + c.SharedGalleryTimeout = 60 * time.Minute + } if c.ManagedImageOSDiskSnapshotName != "" { if ok, err := assertManagedImageOSDiskSnapshotName(c.ManagedImageOSDiskSnapshotName, "managed_image_os_disk_snapshot_name"); !ok { From cb168730815a505a3b313f24c2888061be0a4eaa Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 1 Aug 2019 11:22:36 -0700 Subject: [PATCH 2/2] add docs for shared_image_gallery_timeout option --- website/source/docs/builders/azure.html.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/website/source/docs/builders/azure.html.md b/website/source/docs/builders/azure.html.md index 2a4c07f7c..aa741d675 100644 --- a/website/source/docs/builders/azure.html.md +++ b/website/source/docs/builders/azure.html.md @@ -122,16 +122,16 @@ When creating a managed image the following options are required. `managed_image_name` must also be set. See [documentation](https://docs.microsoft.com/en-us/azure/storage/storage-managed-disks-overview#images) to learn more about managed images. - - + + Managed images can optionally be published to [Shared Image Gallery](https://azure.microsoft.com/en-us/blog/announcing-the-public-preview-of-shared-image-gallery/) as Shared Gallery Image version. Shared Image Gallery **only** works with Managed Images. **A VHD cannot be published to a Shared Image Gallery**. When publishing to a Shared Image Gallery the following options are required. - + - `shared_image_gallery_destination` (object) The name of the Shared Image Gallery under which the managed image will be published as Shared Gallery Image version. - + Following is an example. - + "shared_image_gallery_destination": { @@ -303,6 +303,14 @@ Providing `temp_resource_group_name` or `location` in combination with "managed_image_name": "TargetImageName", "managed_image_resource_group_name": "TargetResourceGroup" +- `shared_image_gallery_timeout` (time.Duration) How long to wait for an image + to be published to the shared image gallery before timing out. If your + Packer build is failing on the Publishing to Shared Image Gallery step + with the error `Original Error: context deadline exceeded`, but the image + is present when you check your Azure dashboard, then you probably need to + increase this timeout from its default of "60m" (valid time units include + `s` for seconds, `m` for minutes, and `h` for hours.) + - `temp_compute_name` (string) temporary name assigned to the VM. If this value is not set, a random value will be assigned. Knowing the resource group and VM name allows one to execute commands to update the VM during a