From 87b290ae67ada1360ea262b0bc74af1d86ce3528 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 12 Aug 2020 15:24:47 -0700 Subject: [PATCH] add hcl docs to pipeline build docs --- .../packer-on-cicd/pipelineing-builds.mdx | 99 ++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-) diff --git a/website/pages/guides/packer-on-cicd/pipelineing-builds.mdx b/website/pages/guides/packer-on-cicd/pipelineing-builds.mdx index a8cbe158f..012675847 100644 --- a/website/pages/guides/packer-on-cicd/pipelineing-builds.mdx +++ b/website/pages/guides/packer-on-cicd/pipelineing-builds.mdx @@ -30,6 +30,9 @@ this example can be applied to other builders as well. Here is an extremely basic virtualbox-iso template: + + + ```json { "builders": [ @@ -67,8 +70,7 @@ Here is an extremely basic virtualbox-iso template: "type": "shell", "inline": ["echo initial provisioning"] } - ] -}, + ], "post-processors": [ { "type": "manifest", @@ -78,6 +80,42 @@ Here is an extremely basic virtualbox-iso template: } ``` + + + +```hcl +source "virtualbox-iso" "step_1" { + boot_command = ["", "", "", + "/install/vmlinuz", " initrd=/install/initrd.gz", + " auto-install/enable=true", " debconf/priority=critical", + " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ubuntu_preseed.cfg", + " -- ", ""] + disk_size = "40960" + guest_os_type = "Ubuntu_64" + http_directory = "./http" + iso_checksum = "sha256:946a6077af6f5f95a51f82fdc44051c7aa19f9cfc5f737954845a6050543d7c2" + iso_url = "http://old-releases.ubuntu.com/releases/14.04.1/ubuntu-14.04-server-amd64.iso" + shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now" + ssh_password = "vagrant" + ssh_port = 22 + ssh_username = "vagrant" + vm_name = "vbox-example" +} +build { + sources = ["source.virtualbox-iso.step_2"] + + provisioner "shell" { + inline = ["echo initial provisioning"] + } + post-processor "manifest" { + output = "stage-1-manifest.json" + } +} +``` + + + + In order to build using this template, create a directory named "http" in your current working directory. Copy the minimal example from our [preseed guide](https://www.packer.io/guides/automatic-operating-system-installs/preseed_ubuntu#examples) @@ -101,6 +139,9 @@ That output filename generated in the first stage can be used as the [source_path](https://www.packer.io/docs/builders/virtualbox/ovf#source_path) for the virtualbox-ovf builder. + + + ```json { "builders": [ @@ -125,6 +166,32 @@ for the virtualbox-ovf builder. } ``` + + + +```hcl +source "virtualbox-ovf" "step_2" { + shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now" + source_path = "output-virtualbox-iso/vbox-example.ovf" + ssh_password = "vagrant" + ssh_port = 22 + ssh_username = "vagrant" + vm_name = "virtualbox-example-ovf" +} + +build { + sources = ["source.virtualbox-ovf.step_2"] + + provisioner "shell" { + inline = ["echo secondary provisioning"] + } +} + +``` + + + + ## More efficiencies You may find that you want to run time-consuming import post-processors like @@ -137,6 +204,9 @@ the behavior you want. The below example shows a "vagrant" post-processor being used with a null builder, and manually sets the artifact from our stage-2 ovf build: + + + ```json { "builders": [ @@ -163,6 +233,31 @@ stage-2 ovf build: } ``` + + + +```hcl +source "null" "step_3" { + communicator = "none" +} + +build { + sources = ["source.null.step_3"] + + post-processors { + post-processor "artifice" { + files = ["output-virtualbox-ovf/virtualbox-example-ovf.ovf", "output-virtualbox-ovf/virtualbox-example-ovf-disk001.vmdk"] + } + post-processor "vagrant" { + provider_override = "virtualbox" + } + } +} +``` + + + + By using the null builder instead of just running an ovf builder, we can spare ourselves all of the time Packer would normally spend launching and destroying VMs. ## Putting it all together