vmware / photon-packer-templates

VMware Photon Packer Templates
Apache License 2.0
35 stars 19 forks source link

VMware Photon OS

Packer Templates for VMware Photon OS

VMware Fusion VMware Workstation Pro VirtualBox

Packer Vagrant

Introduction

This repository provides infrastructure-as-code examples to automate the creation of VMware Photon OS ( x86_64 ) machine images as Vagrant boxes using Packer. These Vagrant boxes can be run on VMware Fusion, VMware Workstation Pro, and VirtualBox.

This project is also used to generate the offical vmware/photon Vagrant boxes.

All examples are authored in the HashiCorp Configuration Language ("HCL2").

The following builds are available:

Requirements

The following software packages are recommened to be installed on the Packer host:

Get Started

Step 1 - Clone the Repository

Clone the project repository.

Example:

  git clone https://github.com/vmware/photon-packer-templates.git

The general directory structure of the repository.

  ├── scripts
  │   ├── system
  │   │   └── *.sh
  │   ├── vagrant
  │   │   ├── *.sh
  │   │   └── *.tpl
  │   ├── virtualbox
  │   │   └── *.sh
  │   ├── vmware
  │   │   └── *.sh*
  │   └── *.sh
  ├── output
  │   ├── photon-<version>-<release>-vagrant-<provider>.box
  │   └── manifest.json
  ├── LICENSE
  ├── Makefile
  ├── NOTICE
  ├── override.pkrvars.hcl
  ├── photon-<version>-<release>.pkrvars.hcl
  ├── photon.pkr.hcl
  ├── photon.pkrtpl.hcl
  ├── README.md
  └── variables.pkr.hcl

The files are distributed in the following directories.

Step 2 - Update Input Variables

  1. Obtain the URL, checksum type (e.g., sha1), and checksum value for the VMware Photon OS .iso image. This will be use in the build input variables.

  2. Obtain the sha256 checksum value for the VirtualBox Guest Additions .iso image. This will be use as input variables when building for VirtualBox.

  3. Update the contents of the photon-<version>-<release>.pkrvars.hcl file, as needed.

    // VMware Photon OS Settings
    
    os_version         = "4.0"
    os_release         = "R2"
    iso_checksum_type  = "sha1"
    iso_checksum_value = "eeb08738209bf77306268d63b834fd91f6cecdfb"
    iso_url            = "https://packages.vmware.com/photon/4.0/Rev2/iso/photon-4.0-c001795b8.iso"
    
    // VirtualBox Guest Additions
    
    guest_additions_url      = "https://download.virtualbox.org/virtualbox/6.1.40/VBoxGuestAdditions_6.1.40.iso"
    guest_additions_checksum = "d456c559926f1a8fdd7259056e0a50f12339fd494122cf30db7736e2032970c6"
  4. Modify the Overrides (Optional)

    The project sets input defaults in the variables.pkr.hcl. You can override the defaults by editing the override.pkr.hcl file and uncommenting the relevent overrides.

    # Override the default input variable values.
    
    # os_packagelist           = "minimal"
    # vm_name                  = "photon"
    # guest_additions_url      = "https://download.virtualbox.org/virtualbox/7.0.0/VBoxGuestAdditions_7.0.0.iso"
    # guest_additions_checksum = "f1e214507e4e845e18fdc4ce6ae9ab3aa3514f37d8a702201129c69ea2b3a675"
    # ssh_password             = "VMw@re123!"
    # ssh_timeout              = "15m"
    # boot_wait                = "3s"
    # boot_key_interval        = "10ms"
    # hardware_version_vmw     = 18
    # headless                 = false
    # cpu_count                = 2
    # memory_size              = 1024
    # disk_size                = 20480
    # network_vmw              = nat

Build

You can use the included Makefile to validate and build the all or specific machine images on macOS and Linux:

> make

Targets:
  validate
    validate-vmware-iso.vagrant-vmw
    validate-virtualbox-iso.vagrant-vbx

  build
    build-vmware-iso.vagrant-vmw
    build-virtualbox-iso.vagrant-vbx

  clean

All required Packer plugins are automatically initialized when using validate and build options. If the plugins are not present, they will be automatically downloaded and installed.

For dark sites, you may download the plugins and place these same directory as your Packer executable /usr/local/bin or $HOME/.packer.d/plugins.

Example: Build all targets.

make build 

Example: Build only the VMware Fusion / Workstation Pro target.

make build-vmware-iso.vagrant-vmw

Alternatively, you can manually initilize, validate, and build on macOS, Linux, and Windows.

Example: Initialize for all targets.

Example: Validate all targets.

Example: Build all targets.

Example: Build only the VMware Fusion / Workstation Pro target.

Example: Build only the VirtualBox target.

Example: Build only the VMware Fusion / Workstation Pro target with an input variable override for the VMware Photon OS Developer package list.

Run

After you have created the Vagrant boxes for VMware Photon OS, you can bring them up in your provider of choice.

Example: VMware Fusion or VMware Workstation Pro

cd output
vagrant init photon-4.0-R2-minimal-vagrant-vmw.box
vagrant up --provider vmware_desktop

Example: VirtualBox

cd output
vagrant init photon-4.0-R2-minimal-vagrant-vbx.box
vagrant up --provider virtualbox

Example: SSH to the VMware Photon OS box.

> vagrant ssh
vagrant@photon-minimal [ ~ ]$ 

By default, shared folders are disabled between the Vagrant box and the host.

Edit the Vagrantfile to manage the share folders.

Example: Enable Shared Folders

Vagrant.configure("2") do |config|
  config.vm.box = "photon-4.0-R2-minimal-vagrant-vmw.box"
  config.vm.synced_folder '.', '/vagrant', disabled: false
end

Edit the Vagrantfile to modify additional provider configurations, such as CPU and memory.

Example: Modify the CPU and Memory Resources

Vagrant.configure("2") do |config|
  config.vm.box = "photon-4.0-R2-minimal-vagrant-vmw.box"
  config.vm.provider "vmware_desktop" do |v|
    v.vmx["numvcpus"] = "2"
    v.vmx["memsize"] = "2048"
  end
end

Learn more about the Vagrant provider configurations: