---
version: '3'

tasks:
  kvm:
    deps:
      - :install:software:kvm
      - :install:software:packer
    desc: Build a Packer image for KVM
    summary: |
      # Build a Packer image for KVM

      This task will build a machine image intended to be used by KVM environments. KVM
      environments are generally only available on Linux (although, it is supposedly
      possible to run KVM on macOS as well). By default, this task assumes the template
      file is titled `template.json` and that the file is in the root of the project. If
      you would like to use another template file then you can do so by passing the file
      name as a parameter (see example below).

      **Example:**
      `task build:kvm`

      **Example using a template file named `another_template.json`:**
      `task build:kvm -- another_template.json`
    hide:
      sh: '[ "{{.REPOSITORY_TYPE}}" != "packer" ]'
    log:
      error: Error running `packer build -only=qemu {{.TEMPLATE_FILE}}`
      start: Running `packer build -only=qemu {{.TEMPLATE_FILE}}`
      success: Successfully ran `packer build -only=qemu {{.TEMPLATE_FILE}}`
    cmds:
      - task: :packer:prepare:template
      - rm -rf build
      - packer build -only=qemu {{.TEMPLATE_FILE}}

  parallels:
    deps:
      - :install:software:packer
      - :install:software:parallels
    desc: Build a Packer image for Parallels
    summary: |
      # Build a Packer image for Parallels

      This task will build a machine image intended to be used by Parallels. Parallels
      is only available for macOS. By default, this task assumes the template file is
      titled `template.json` and that the file is in the root of the project. If you
      would like to use another template file then you can do so by passing the file
      name as a parameter (see example below).

      **Example:**
      `task build:parallels`

      **Example using a template file named `another_template.json`:**
      `task build:parallels -- another_template.json`
    hide:
      sh: '[ "{{.REPOSITORY_TYPE}}" != "packer" ]'
    log:
      error: Error running `packer build -only=parallels-iso {{.TEMPLATE_FILE}}`
      start: Running `packer build -only=parallels-iso {{.TEMPLATE_FILE}}`
      success: Successfully ran `packer build -only=parallels-iso {{.TEMPLATE_FILE}}`
    cmds:
      - rm -rf build
      - packer build -only=parallels-iso {{.TEMPLATE_FILE}}

  virtualbox:
    deps:
      - :install:software:packer
      - :install:software:virtualbox
    desc: Build a Packer image for VirtualBox
    summary: |
      # Build a Packer image for VirtualBox

      This task will build a machine image intended to be used by VirtualBox. By
      default, this task assumes the template file is titled `template.json` and
      that the file is in the root of the project. If you would like to use another
      template file then you can do so by passing the file name as a parameter
      (see example below).

      **Example:**
      `task build:virtualbox`

      **Example using a template file named `another_template.json`:**
      `task build:virtualbox -- another_template.json`
    hide:
      sh: '[ "{{.REPOSITORY_TYPE}}" != "packer" ]'
    log:
      error: Error running `packer build -only=virtualbox-iso {{.TEMPLATE_FILE}}`
      start: Running `packer build -only=virtualbox-iso {{.TEMPLATE_FILE}}`
      success: Successfully ran `packer build -only=virtualbox-iso {{.TEMPLATE_FILE}}`
    cmds:
      - task: :app:virtualbox:clear
      - rm -rf build
      - packer build -only=virtualbox-iso {{.TEMPLATE_FILE}}

  vmware:
    deps:
      - :install:software:packer
      - :install:software:vmware
    desc: Build a Packer image for VMWare
    summary: |
      # Build a Packer image for VMWare

      This task will build a machine image intended to be used by VMWare. The image
      build can be used by either VMWare Workstation (i.e. Linux, Windows) or by
      VMWare Fusion (i.e. macOS). By default, this task assumes the template file is
      titled `template.json` and that the file is in the root of the project. If you
      would like to use another template file then you can do so by passing the file
      name as a parameter (see example below).

      **Example:**
      `task packer:vmware`

      **Example using a template file named `another_template.json`:**
      `task packer:vmware -- another_template.json`
    log:
      error: Error running `packer build -only=vmware-iso {{.TEMPLATE_FILE}}`
      start: Running `packer build -only=vmware-iso {{.TEMPLATE_FILE}}`
      success: Successfully ran `packer build -only=vmware-iso {{.TEMPLATE_FILE}}`
    hide:
      sh: '[ "{{.REPOSITORY_TYPE}}" != "packer" ]'
    cmds:
      - rm -rf build
      - packer build -only=vmware-iso {{.TEMPLATE_FILE}}
