Skip to content

Commit

Permalink
[freebsd-*] Improve DRYness, correctness, & speed of FreeBSD templates.
Browse files Browse the repository at this point in the history
The following improvements are made in this commit:

* Ensure that all related provisioner shell scripts are written using
  more conservative bourne code idioms
* Call all provisioner scripts with `sh -eux` which will (e) exit
  immediately if a command exits with a non-zero exit status, (u) treats
  unset variables as an error, and (x) outputs the command and its
  expanded arguments or associated word list
* Use the `template` user variable to replace repetition of `"freebsd-*"`
  style strings throughout
* Support a `HOME_DIR` environment variable for provisioner scripts to
  use
* Remove now-unused user variable `arch`
* Extract the `iso_checksum` and `iso_checksum_type` values into user
  variables and reference them in the templates
* Construct the `iso_url` value from the `mirror`, `mirror_directory`,
  and `iso_name` user variables
* Add an `install_path` user variable and use it throughout the
  templates
* Add an `iso_name` user variable and use it throughout the templates
* Use the `http_proxy`, `https_proxy`, and `no_proxy` environment
  variables if set on the workstation and make them available to the
  provisioner shell scripts to speed up package installations, etc.
* Fix `shutdown_command` value to not output a file as a side effect
  • Loading branch information
fnichol committed Jul 12, 2015
1 parent 53ed757 commit 51b7643
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 256 deletions.
73 changes: 42 additions & 31 deletions freebsd-10.1-amd64.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
"mdmfs -s 100m md1 /tmp<enter><wait>",
"mdmfs -s 100m md2 /mnt<enter><wait>",
"dhclient -l /tmp/dhclient.lease.em0 em0<enter><wait>",
"fetch -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/freebsd-10.1/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh {{ .Name }}<enter><wait>"
"fetch -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `install_path`}} && chmod +x /tmp/install.sh && /tmp/install.sh {{ .Name }}<enter><wait>"
],
"boot_wait": "10s",
"disk_size": 10140,
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
"guest_os_type": "FreeBSD_64",
"headless": "{{ user `headless` }}",
"http_directory": "http",
"iso_checksum": "0c3d64ce48c3ef761761d0fea07e1935e296f8c045c249118bc91a7faf053a6b",
"iso_checksum_type": "sha256",
"iso_url": "{{user `mirror`}}/releases/amd64/amd64/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-amd64-disc1.iso",
"output_directory": "packer-freebsd-10.1-amd64-virtualbox",
"shutdown_command": "echo 'shutdown -p now' > shutdown.sh; cat 'shutdown.sh' | su -",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}",
"output_directory": "packer-{{user `template`}}-virtualbox",
"shutdown_command": "su -m root -c 'shutdown -p now'",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_username": "vagrant",
Expand Down Expand Up @@ -56,18 +56,18 @@
"mdmfs -s 100m md2 /mnt<enter><wait>",
"dhclient -l /tmp/dhclient.lease.em0 em0<enter><wait>",
"<wait5>",
"fetch -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/freebsd-10.1/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh {{ .Name }}<enter><wait>"
"fetch -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `install_path`}} && chmod +x /tmp/install.sh && /tmp/install.sh {{ .Name }}<enter><wait>"
],
"boot_wait": "10s",
"disk_size": 10140,
"guest_os_type": "freebsd-64",
"headless": "{{ user `headless` }}",
"http_directory": "http",
"iso_checksum": "0c3d64ce48c3ef761761d0fea07e1935e296f8c045c249118bc91a7faf053a6b",
"iso_checksum_type": "sha256",
"iso_url": "{{user `mirror`}}/releases/amd64/amd64/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-amd64-disc1.iso",
"output_directory": "packer-freebsd-10.1-amd64-vmware",
"shutdown_command": "echo 'shutdown -p now' > shutdown.sh; cat 'shutdown.sh' | su -",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}",
"output_directory": "packer-{{user `template`}}-vmare",
"shutdown_command": "su -m root -c 'shutdown -p now'",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_username": "vagrant",
Expand All @@ -91,17 +91,17 @@
"mdmfs -s 100m md1 /tmp<enter><wait>",
"mdmfs -s 100m md2 /mnt<enter><wait>",
"dhclient -l /tmp/dhclient.lease.em0 em0<enter><wait>",
"fetch -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/freebsd-10.1/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh {{ .Name }}<enter><wait>"
"fetch -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `install_path`}} && chmod +x /tmp/install.sh && /tmp/install.sh {{ .Name }}<enter><wait>"
],
"boot_wait": "10s",
"boot_wait": "8s",
"disk_size": 10140,
"guest_os_type": "freebsd",
"headless": "{{ user `headless` }}",
"http_directory": "http",
"iso_checksum": "0c3d64ce48c3ef761761d0fea07e1935e296f8c045c249118bc91a7faf053a6b",
"iso_checksum_type": "sha256",
"iso_url": "{{user `mirror`}}/releases/amd64/amd64/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-amd64-disc1.iso",
"output_directory": "packer-freebsd-10.1-amd64-parallels",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}",
"output_directory": "packer-{{user `template`}}-parallels",
"parallels_tools_mode": "disable",
"prlctl": [
[
Expand Down Expand Up @@ -138,7 +138,7 @@
]
],
"prlctl_version_file": ".prlctl_version",
"shutdown_command": "echo 'shutdown -p now' > shutdown.sh; cat 'shutdown.sh' | su -",
"shutdown_command": "su -m root -c 'shutdown -p now'",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_username": "vagrant",
Expand All @@ -150,12 +150,8 @@
"post-processors": [
{
"output": "builds/{{user `box_basename`}}.{{.Provider}}.box",
"override": {
"parallels": {
"vagrantfile_template": "vagrantfile_templates/parallels/freebsd.rb"
}
},
"type": "vagrant"
"type": "vagrant",
"vagrantfile_template": "vagrantfile_templates/freebsd.rb"
}
],
"provisioners": [
Expand All @@ -165,29 +161,44 @@
"type": "file"
},
{
"environment_vars": [],
"execute_command": "export {{.Vars}} && cat {{.Path}} | su -m",
"environment_vars": [
"HOME_DIR=/home/vagrant",
"http_proxy={{user `http_proxy`}}",
"https_proxy={{user `https_proxy`}}",
"no_proxy={{user `no_proxy`}}"
],
"execute_command": "{{.Vars}} su -m root -c 'sh -eux {{.Path}}'",
"scripts": [
"scripts/common/metadata.sh",
"scripts/freebsd/update.sh",
"scripts/freebsd/postinstall.sh",
"scripts/freebsd/cleanup.sh",
"scripts/freebsd/sudoers.sh",
"scripts/common/vagrant.sh",
"scripts/freebsd/vmtools.sh",
"scripts/freebsd/cleanup.sh",
"scripts/freebsd/minimize.sh"
],
"type": "shell"
}
],
"variables": {
"arch": "64",
"box_basename": "freebsd-10.1",
"box_basename": "__unset_box_basename__",
"build_timestamp": "{{isotime \"20060102150405\"}}",
"git_revision": "__unknown_git_revision__",
"headless": "",
"http_proxy": "{{env `http_proxy`}}",
"https_proxy": "{{env `https_proxy`}}",
"install_path": "freebsd-10.1/install.sh",
"iso_checksum": "0c3d64ce48c3ef761761d0fea07e1935e296f8c045c249118bc91a7faf053a6b",
"iso_checksum_type": "sha256",
"iso_name": "FreeBSD-10.1-RELEASE-amd64-disc1.iso",
"metadata": "floppy/dummy_metadata.json",
"mirror": "http://ftp.freebsd.org/pub/FreeBSD",
"mirror_directory": "releases/amd64/amd64/ISO-IMAGES/10.1",
"name": "freebsd-10.1",
"no_proxy": "{{env `no_proxy`}}",
"template": "freebsd-10.1-amd64",
"version": "2.0.TIMESTAMP"
"version": "2.1.TIMESTAMP"
}
}

73 changes: 42 additions & 31 deletions freebsd-10.1-i386.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
"mdmfs -s 100m md1 /tmp<enter><wait>",
"mdmfs -s 100m md2 /mnt<enter><wait>",
"dhclient -l /tmp/dhclient.lease.em0 em0<enter><wait>",
"fetch -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/freebsd-10.1/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh {{ .Name }}<enter><wait>"
"fetch -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `install_path`}} && chmod +x /tmp/install.sh && /tmp/install.sh {{ .Name }}<enter><wait>"
],
"boot_wait": "10s",
"disk_size": 10140,
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
"guest_os_type": "FreeBSD",
"headless": "{{ user `headless` }}",
"http_directory": "http",
"iso_checksum": "fe31790b762b01c99791d33e7fd9ab97323654785ce21f588116c8b4eb381cd0",
"iso_checksum_type": "sha256",
"iso_url": "{{user `mirror`}}/releases/i386/i386/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-i386-disc1.iso",
"output_directory": "packer-freebsd-10.1-i386-virtualbox",
"shutdown_command": "echo 'shutdown -p now' > shutdown.sh; cat 'shutdown.sh' | su -",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}",
"output_directory": "packer-{{user `template`}}-virtualbox",
"shutdown_command": "su -m root -c 'shutdown -p now'",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_username": "vagrant",
Expand Down Expand Up @@ -56,18 +56,18 @@
"mdmfs -s 100m md2 /mnt<enter><wait>",
"dhclient -l /tmp/dhclient.lease.em0 em0<enter><wait>",
"<wait5>",
"fetch -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/freebsd-10.1/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh {{ .Name }}<enter><wait>"
"fetch -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `install_path`}} && chmod +x /tmp/install.sh && /tmp/install.sh {{ .Name }}<enter><wait>"
],
"boot_wait": "10s",
"disk_size": 10140,
"guest_os_type": "freebsd",
"headless": "{{ user `headless` }}",
"http_directory": "http",
"iso_checksum": "fe31790b762b01c99791d33e7fd9ab97323654785ce21f588116c8b4eb381cd0",
"iso_checksum_type": "sha256",
"iso_url": "{{user `mirror`}}/releases/i386/i386/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-i386-disc1.iso",
"output_directory": "packer-freebsd-10.1-i386-vmware",
"shutdown_command": "echo 'shutdown -p now' > shutdown.sh; cat 'shutdown.sh' | su -",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}",
"output_directory": "packer-{{user `template`}}-vmare",
"shutdown_command": "su -m root -c 'shutdown -p now'",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_username": "vagrant",
Expand All @@ -91,17 +91,17 @@
"mdmfs -s 100m md1 /tmp<enter><wait>",
"mdmfs -s 100m md2 /mnt<enter><wait>",
"dhclient -l /tmp/dhclient.lease.em0 em0<enter><wait>",
"fetch -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/freebsd-10.1/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh {{ .Name }}<enter><wait>"
"fetch -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `install_path`}} && chmod +x /tmp/install.sh && /tmp/install.sh {{ .Name }}<enter><wait>"
],
"boot_wait": "10s",
"boot_wait": "8s",
"disk_size": 10140,
"guest_os_type": "freebsd",
"headless": "{{ user `headless` }}",
"http_directory": "http",
"iso_checksum": "fe31790b762b01c99791d33e7fd9ab97323654785ce21f588116c8b4eb381cd0",
"iso_checksum_type": "sha256",
"iso_url": "{{user `mirror`}}/releases/i386/i386/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-i386-disc1.iso",
"output_directory": "packer-freebsd-10.1-i386-parallels",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}",
"output_directory": "packer-{{user `template`}}-parallels",
"parallels_tools_mode": "disable",
"prlctl": [
[
Expand Down Expand Up @@ -138,7 +138,7 @@
]
],
"prlctl_version_file": ".prlctl_version",
"shutdown_command": "echo 'shutdown -p now' > shutdown.sh; cat 'shutdown.sh' | su -",
"shutdown_command": "su -m root -c 'shutdown -p now'",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_username": "vagrant",
Expand All @@ -150,12 +150,8 @@
"post-processors": [
{
"output": "builds/{{user `box_basename`}}.{{.Provider}}.box",
"override": {
"parallels": {
"vagrantfile_template": "vagrantfile_templates/parallels/freebsd.rb"
}
},
"type": "vagrant"
"type": "vagrant",
"vagrantfile_template": "vagrantfile_templates/freebsd.rb"
}
],
"provisioners": [
Expand All @@ -165,29 +161,44 @@
"type": "file"
},
{
"environment_vars": [],
"execute_command": "export {{.Vars}} && cat {{.Path}} | su -m",
"environment_vars": [
"HOME_DIR=/home/vagrant",
"http_proxy={{user `http_proxy`}}",
"https_proxy={{user `https_proxy`}}",
"no_proxy={{user `no_proxy`}}"
],
"execute_command": "{{.Vars}} su -m root -c 'sh -eux {{.Path}}'",
"scripts": [
"scripts/common/metadata.sh",
"scripts/freebsd/update.sh",
"scripts/freebsd/postinstall.sh",
"scripts/freebsd/cleanup.sh",
"scripts/freebsd/sudoers.sh",
"scripts/common/vagrant.sh",
"scripts/freebsd/vmtools.sh",
"scripts/freebsd/cleanup.sh",
"scripts/freebsd/minimize.sh"
],
"type": "shell"
}
],
"variables": {
"arch": "32",
"box_basename": "freebsd-10.1-i386",
"box_basename": "__unset_box_basename__",
"build_timestamp": "{{isotime \"20060102150405\"}}",
"git_revision": "__unknown_git_revision__",
"headless": "",
"http_proxy": "{{env `http_proxy`}}",
"https_proxy": "{{env `https_proxy`}}",
"install_path": "freebsd-10.1/install.sh",
"iso_checksum": "fe31790b762b01c99791d33e7fd9ab97323654785ce21f588116c8b4eb381cd0",
"iso_checksum_type": "sha256",
"iso_name": "FreeBSD-10.1-RELEASE-i386-disc1.iso",
"metadata": "floppy/dummy_metadata.json",
"mirror": "http://ftp.freebsd.org/pub/FreeBSD",
"mirror_directory": "releases/i386/i386/ISO-IMAGES/10.1",
"name": "freebsd-10.1-i386",
"no_proxy": "{{env `no_proxy`}}",
"template": "freebsd-10.1-i386",
"version": "2.0.TIMESTAMP"
"version": "2.1.TIMESTAMP"
}
}

Loading

0 comments on commit 51b7643

Please sign in to comment.