From 8041971ef211709579f919bdeb9a77fef0a29433 Mon Sep 17 00:00:00 2001 From: Anil Belur Date: Thu, 21 Jan 2021 18:32:12 +1000 Subject: [PATCH] Set packer builder type with env variable Using the -only CLI option for packer build does not work as expected. The #CR 90dd675df482a8 (global-jjb) submitted with common-packer v0.7.0 fails to build packer jobs because of a bug in the packer build CLI. The `-only` option packer build CLI does not set the cloud provider name/type as per the documentation. The alternative is to use an environment variable that is passed through the packer job and can be reference in the packer templates. The CR cc035619ac16 missed including the changes to the other templates. Issue: https://github.com/hashicorp/packer/issues/10495 Signed-off-by: Anil Belur Change-Id: I14976aa77312a3d887d30b7d6e2cc32ab8073b72 --- ...e-with-env-var-for-docker-win-b50a519f95603e2a.yaml | 18 ++++++++++++++++++ templates/docker.json | 7 ++++--- templates/windows-builder.json | 7 ++++--- 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/set-packer-builder-type-with-env-var-for-docker-win-b50a519f95603e2a.yaml diff --git a/releasenotes/notes/set-packer-builder-type-with-env-var-for-docker-win-b50a519f95603e2a.yaml b/releasenotes/notes/set-packer-builder-type-with-env-var-for-docker-win-b50a519f95603e2a.yaml new file mode 100644 index 0000000..433f4f1 --- /dev/null +++ b/releasenotes/notes/set-packer-builder-type-with-env-var-for-docker-win-b50a519f95603e2a.yaml @@ -0,0 +1,18 @@ +--- +fixes: + - | + Set packer builder type with environment variable + + Using the -only CLI option for packer build does not work as expected. + The #CR 90dd675df482a8 (global-jjb) submitted with common-packer v0.7.0 + fails to build packer jobs because of a bug in the packer build CLI. + + The `-only` option packer build CLI does not set the cloud provider + name/type as per the documentation. The alternative is to use an environment + variable that is passed through the packer job and can be reference in the + packer templates. + + The CR #66528 missed including the changes to additional templates. + + Ref: + https://github.com/hashicorp/packer/issues/10495 diff --git a/templates/docker.json b/templates/docker.json index 2254dd2..a6f78a7 100644 --- a/templates/docker.json +++ b/templates/docker.json @@ -12,15 +12,16 @@ "distro": null, "flavor": "v2-highcpu-1", "ssh_user": null, - "ssh_proxy_host": "" + "ssh_proxy_host": "", + "cloud_type": "{{env `PACKER_BUILDER`}}" }, "builders": [ { - "name": "openstack", + "name": "{{user `cloud_type`}}", "image_name": "ZZCI - {{user `distro`}} - docker - {{user `arch`}} - {{isotime \"20060102-150405.000\"}}", "instance_name": "{{user `distro`}}-docker-{{uuid}}", "source_image_name": "{{user `base_image`}}", - "type": "openstack", + "type": "{{user `cloud_type`}}", "region": "{{user `cloud_region`}}", "networks": ["{{user `cloud_network`}}"], "user_data_file": "{{user `cloud_user_data`}}", diff --git a/templates/windows-builder.json b/templates/windows-builder.json index f0e5758..022a879 100644 --- a/templates/windows-builder.json +++ b/templates/windows-builder.json @@ -10,15 +10,16 @@ "vm_volume_size": "20", "vm_image_disk_format": "", "distro": null, - "flavor": "v2-highcpu-4" + "flavor": "v2-highcpu-4", + "cloud_type": "{{env `PACKER_BUILDER`}}" }, "builders": [ { - "name": "openstack", + "name": "{{user `cloud_type`}}", "image_name": "ZZCI - {{user `distro`}} - win-builder - {{user `arch`}} - {{isotime \"20060102-150405.000\"}}", "instance_name": "{{user `distro`}}-win-builder-{{uuid}}", "source_image_name": "{{user `base_image`}}", - "type": "openstack", + "type": "{{user `cloud_type`}}", "region": "{{user `cloud_region`}}", "networks": ["{{user `cloud_network`}}"], "user_data_file": "{{user `cloud_user_data`}}", -- 2.16.6