Skip to content

Commit

Permalink
feat: Add common option to export machine image artifacts (#226)
Browse files Browse the repository at this point in the history
Adds a common option to export machine image artifacts (`.ovf`,`.vmdk`, and `.mf`) to an output path.

Resolves #217

Signed-off-by: Ryan Johnson <[email protected]>
  • Loading branch information
tenthirtyam committed Jul 19, 2022
1 parent e12af01 commit af1c7e0
Show file tree
Hide file tree
Showing 41 changed files with 630 additions and 17 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* Adds CentOS 9 Stream.
* Adds Rocky Linux 9.
* Adds AlmaLinux OS 9.
* Adds options for setting the number of video displays and the size for the video memory for both Windows 11 and 10, which is useful for virtual desktop use cases (_e.g._, Horizon). The ability to set the number of displays was added in `v1.0.6` of `packer-plugin-vsphere`.
* Adds option for setting the number of video displays and the size for the video memory for both Windows 11 and 10, which is useful for virtual desktop use cases (_e.g._, Horizon). The ability to set the number of displays was added in `v1.0.6` of `packer-plugin-vsphere`.
* Adds a common option to export machine image artifacts (`.ovf`,`.vmdk`, and `.mf`) to an output path.
* Removes the default requirement for a trusted root authority certificate to be imported and trusted by each machine image build. This will allow project users to get started more quickly without a pre-requisite.

🛠️ **Refactor**:
Expand Down
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ The directory structure of the repository.
│ │ └── main.yml
│ ├── ansible.cfg
│ └── main.yml
├── artifacts
├── builds
│ ├── ansible.pkvars.hcl.example
│ ├── build.pkvars.hcl.example
Expand Down Expand Up @@ -392,11 +393,12 @@ The directory structure of the repository.

The files are distributed in the following directories.

* **`ansible`** - contains the Ansible roles to prepare a Linux machine image build.
* **`builds`** - contains the templates, variables, and configuration files for the machine image build.
* **`scripts`** - contains the scripts to initialize and prepare a Windows machine image build.
* **`manifests`** - manifests created after the completion of the machine image build.
* **`terraform`** - contains example Terraform plans to test machine image builds.
* **`ansible`** - contains the Ansible roles to prepare Linux machine image builds.
* **`artifacts`** - contains the OVF artifacts created by the builds, if enabled.
* **`builds`** - contains the templates, variables, and configuration files for the machine image builds.
* **`scripts`** - contains the scripts to initialize and prepare Windows machine image builds.
* **`manifests`** - manifests created after the completion of the machine image builds.
* **`terraform`** - contains example Terraform plans to create a custom role and test machine image builds.

> **Warning**
>
Expand Down Expand Up @@ -608,7 +610,7 @@ Generate a SHA-512 encrypted password for the `build_password_encrypted` using t

```console
rainpole@photon> sudo systemctl start docker
rainpole@photon> sudo docker run -it --rm alpine:latest
rainpole@photon> sudo docker run -it --rm alpine:latest
mkpasswd -m sha512
Password: ***************
[password hash]
Expand All @@ -618,7 +620,7 @@ rainpole@photon> sudo systemctl stop docker
**Example**: mkpasswd using Docker on macOS:

```console
rainpole@macos> docker run -it --rm alpine:latest
rainpole@macos> docker run -it --rm alpine:latest
mkpasswd -m sha512
Password: ***************
[password hash]
Expand All @@ -627,7 +629,7 @@ Password: ***************
**Example**: mkpasswd on Ubuntu:

```console
rainpole@ubuntu> mkpasswd -m sha-512
rainpole@ubuntu> mkpasswd -m sha-512
Password: ***************
[password hash]
```
Expand Down Expand Up @@ -685,6 +687,7 @@ Edit the `config/common.pkvars.hcl` file to configure the following common varia

* Virtual Machine Settings
* Template and Content Library Settings
* OVF Export Settings
* Removable Media Settings
* Boot and Provisioning Settings

Expand All @@ -702,6 +705,10 @@ common_content_library_name = "sfo-w01-lib01"
common_content_library_ovf = true
common_content_library_destroy = true
// OVF Export Settings
common_ovf_export_enabled = false
common_ovf_export_overwrite = true
// Removable Media Settings
common_iso_datastore = "sfo-w01-cl01-ds-nfs01"
Expand Down
1 change: 1 addition & 0 deletions artifacts/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 5 additions & 1 deletion builds/common.pkrvars.hcl.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ common_content_library_ovf = true
common_content_library_destroy = true
common_content_library_skip_export = false

// OVF Export Settings
common_ovf_export_enabled = false
common_ovf_export_overwrite = true

// Removable Media Settings
common_iso_datastore = "sfo-w01-cl01-ds-nfs01"

Expand All @@ -25,4 +29,4 @@ common_http_ip = null
common_http_port_min = 8000
common_http_port_max = 8099
common_ip_wait_timeout = "20m"
common_shutdown_timeout = "15m"
common_shutdown_timeout = "15m"
14 changes: 14 additions & 0 deletions builds/linux/almalinux/8/linux-almalinux.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ locals {
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
manifest_path = "${path.cwd}/manifests/"
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
data_source_content = {
"/ks.cfg" = templatefile("${abspath(path.root)}/data/ks.pkrtpl.hcl", {
build_username = var.build_username
Expand Down Expand Up @@ -131,6 +132,19 @@ source "vsphere-iso" "linux-almalinux" {
}
}

// OVF Export Settings
dynamic "export" {
for_each = var.common_ovf_export_enabled == true ? [1] : []
content {
name = local.vm_name
force = var.common_ovf_export_overwrite
options = [
"extraconfig"
]
output_directory = local.ovf_export_path
}
}

}

// BLOCK: build
Expand Down
14 changes: 14 additions & 0 deletions builds/linux/almalinux/8/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ variable "common_content_library_skip_export" {
default = false
}

// OVF Export Settings

variable "common_ovf_export_enabled" {
type = bool
description = "Enable OVF artifact export."
default = false
}

variable "common_ovf_export_overwrite" {
type = bool
description = "Overwrite existing OVF artifact."
default = true
}

// Removable Media Settings

variable "common_iso_datastore" {
Expand Down
14 changes: 14 additions & 0 deletions builds/linux/almalinux/9/linux-almalinux.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ locals {
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
manifest_path = "${path.cwd}/manifests/"
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
data_source_content = {
"/ks.cfg" = templatefile("${abspath(path.root)}/data/ks.pkrtpl.hcl", {
build_username = var.build_username
Expand Down Expand Up @@ -130,6 +131,19 @@ source "vsphere-iso" "linux-almalinux" {
skip_import = var.common_content_library_skip_export
}
}

// OVF Export Settings
dynamic "export" {
for_each = var.common_ovf_export_enabled == true ? [1] : []
content {
name = local.vm_name
force = var.common_ovf_export_overwrite
options = [
"extraconfig"
]
output_directory = local.ovf_export_path
}
}
}

// BLOCK: build
Expand Down
14 changes: 14 additions & 0 deletions builds/linux/almalinux/9/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ variable "common_content_library_skip_export" {
default = false
}

// OVF Export Settings

variable "common_ovf_export_enabled" {
type = bool
description = "Enable OVF artifact export."
default = false
}

variable "common_ovf_export_overwrite" {
type = bool
description = "Overwrite existing OVF artifact."
default = true
}

// Removable Media Settings

variable "common_iso_datastore" {
Expand Down
14 changes: 14 additions & 0 deletions builds/linux/centos/7/linux-centos.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ locals {
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
manifest_path = "${path.cwd}/manifests/"
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
data_source_content = {
"/ks.cfg" = templatefile("${abspath(path.root)}/data/ks.pkrtpl.hcl", {
build_username = var.build_username
Expand Down Expand Up @@ -130,6 +131,19 @@ source "vsphere-iso" "linux-centos" {
skip_import = var.common_content_library_skip_export
}
}

// OVF Export Settings
dynamic "export" {
for_each = var.common_ovf_export_enabled == true ? [1] : []
content {
name = local.vm_name
force = var.common_ovf_export_overwrite
options = [
"extraconfig"
]
output_directory = local.ovf_export_path
}
}
}

// BLOCK: build
Expand Down
14 changes: 14 additions & 0 deletions builds/linux/centos/7/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ variable "common_content_library_skip_export" {
default = false
}

// OVF Export Settings

variable "common_ovf_export_enabled" {
type = bool
description = "Enable OVF artifact export."
default = false
}

variable "common_ovf_export_overwrite" {
type = bool
description = "Overwrite existing OVF artifact."
default = true
}

// Removable Media Settings

variable "common_iso_datastore" {
Expand Down
14 changes: 14 additions & 0 deletions builds/linux/centos/8-stream/linux-centos-stream.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ locals {
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
manifest_path = "${path.cwd}/manifests/"
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
data_source_content = {
"/ks.cfg" = templatefile("${abspath(path.root)}/data/ks.pkrtpl.hcl", {
build_username = var.build_username
Expand Down Expand Up @@ -130,6 +131,19 @@ source "vsphere-iso" "linux-centos-stream" {
skip_import = var.common_content_library_skip_export
}
}

// OVF Export Settings
dynamic "export" {
for_each = var.common_ovf_export_enabled == true ? [1] : []
content {
name = local.vm_name
force = var.common_ovf_export_overwrite
options = [
"extraconfig"
]
output_directory = local.ovf_export_path
}
}
}

// BLOCK: build
Expand Down
14 changes: 14 additions & 0 deletions builds/linux/centos/8-stream/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ variable "common_content_library_skip_export" {
default = false
}

// OVF Export Settings

variable "common_ovf_export_enabled" {
type = bool
description = "Enable OVF artifact export."
default = false
}

variable "common_ovf_export_overwrite" {
type = bool
description = "Overwrite existing OVF artifact."
default = true
}

// Removable Media Settings

variable "common_iso_datastore" {
Expand Down
14 changes: 14 additions & 0 deletions builds/linux/centos/9-stream/linux-centos-stream.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ locals {
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
manifest_path = "${path.cwd}/manifests/"
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
data_source_content = {
"/ks.cfg" = templatefile("${abspath(path.root)}/data/ks.pkrtpl.hcl", {
build_username = var.build_username
Expand Down Expand Up @@ -130,6 +131,19 @@ source "vsphere-iso" "linux-centos-stream" {
skip_import = var.common_content_library_skip_export
}
}

// OVF Export Settings
dynamic "export" {
for_each = var.common_ovf_export_enabled == true ? [1] : []
content {
name = local.vm_name
force = var.common_ovf_export_overwrite
options = [
"extraconfig"
]
output_directory = local.ovf_export_path
}
}
}

// BLOCK: build
Expand Down
14 changes: 14 additions & 0 deletions builds/linux/centos/9-stream/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ variable "common_content_library_skip_export" {
default = false
}

// OVF Export Settings

variable "common_ovf_export_enabled" {
type = bool
description = "Enable OVF artifact export."
default = false
}

variable "common_ovf_export_overwrite" {
type = bool
description = "Overwrite existing OVF artifact."
default = true
}

// Removable Media Settings

variable "common_iso_datastore" {
Expand Down
14 changes: 14 additions & 0 deletions builds/linux/photon/4/linux-photon.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ locals {
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
manifest_path = "${path.cwd}/manifests/"
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
data_source_content = {
"/ks.json" = templatefile("${abspath(path.root)}/data/ks.pkrtpl.hcl", {
build_username = var.build_username
Expand Down Expand Up @@ -128,6 +129,19 @@ source "vsphere-iso" "linux-photon" {
skip_import = var.common_content_library_skip_export
}
}

// OVF Export Settings
dynamic "export" {
for_each = var.common_ovf_export_enabled == true ? [1] : []
content {
name = local.vm_name
force = var.common_ovf_export_overwrite
options = [
"extraconfig"
]
output_directory = local.ovf_export_path
}
}
}

// BLOCK: build
Expand Down

0 comments on commit af1c7e0

Please sign in to comment.