Skip to content

Commit

Permalink
Merge pull request #162 from BrandonRomano/master
Browse files Browse the repository at this point in the history
Register plug-in as Packer integration
  • Loading branch information
NorseGaud authored Mar 22, 2024
2 parents d86c784 + f4f478a commit aa95523
Show file tree
Hide file tree
Showing 14 changed files with 676 additions and 34 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ensure-docs-compiled.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Ensure Docs are Compiled
on:
push:
jobs:
ensure-docs-compiled:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎
uses: actions/checkout@v2
- uses: actions/setup-go@v4
- shell: bash
run: make generate-docs
- shell: bash
run: |
if [[ -z "$(git status -s)" ]]; then
echo "OK"
else
echo "Docs have been updated, but the compiled docs have not been committed."
echo "Run 'make generate-docs', and commit the result to resolve this error."
exit 1
fi
50 changes: 50 additions & 0 deletions .github/workflows/notify-integration-release-via-manual.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Manual release workflow is used for deploying documentation updates
# on the specified branch without making an official plugin release.
name: Notify Integration Release (Manual)
on:
workflow_dispatch:
inputs:
version:
description: "The release version (semver)"
default: 1.0.0
required: false
branch:
description: "A branch or SHA"
default: 'main'
required: false
jobs:
notify-release:
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
ref: ${{ github.event.inputs.branch }}
# Ensure that Docs are Compiled
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
- shell: bash
run: make generate
- shell: bash
run: |
if [[ -z "$(git status -s)" ]]; then
echo "OK"
else
echo "Docs have been updated, but the compiled docs have not been committed."
echo "Run 'make generate', and commit the result to resolve this error."
exit 1
fi
# Perform the Release
- name: Checkout integration-release-action
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
repository: hashicorp/integration-release-action
path: ./integration-release-action
- name: Notify Release
uses: ./integration-release-action
with:
# The integration identifier will be used by the Packer team to register the integration
# the expected format is packer/<GitHub Org Name>/<plugin-name>
integration_identifier: "packer/veertuinc/veertu-anka"
release_version: ${{ github.event.inputs.version }}
release_sha: ${{ github.event.inputs.branch }}
github_token: ${{ secrets.GITHUB_TOKEN }}
54 changes: 54 additions & 0 deletions .github/workflows/notify-integration-release-via-tag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Notify Integration Release (Tag)
on:
push:
tags:
- '*.*.*' # Proper releases
jobs:
strip-version:
runs-on: ubuntu-latest
outputs:
packer-version: ${{ steps.strip.outputs.packer-version }}
steps:
- name: Strip leading v from version tag
id: strip
env:
REF: ${{ github.ref_name }}
run: |
echo "packer-version=$(echo "$REF" | sed -E 's/v?([0-9]+\.[0-9]+\.[0-9]+)/\1/')" >> "$GITHUB_OUTPUT"
notify-release:
needs:
- strip-version
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
ref: ${{ github.ref }}
# Ensure that Docs are Compiled
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
- shell: bash
run: make generate
- shell: bash
run: |
if [[ -z "$(git status -s)" ]]; then
echo "OK"
else
echo "Docs have been updated, but the compiled docs have not been committed."
echo "Run 'make generate', and commit the result to resolve this error."
exit 1
fi
# Perform the Release
- name: Checkout integration-release-action
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
repository: hashicorp/integration-release-action
path: ./integration-release-action
- name: Notify Release
uses: ./integration-release-action
with:
# The integration identifier will be used by the Packer team to register the integration
# the expected format is packer/<GitHub Org Name>/<plugin-name>
integration_identifier: "packer/veertuinc/veertu-anka"
release_version: ${{ needs.strip-version.outputs.packer-version }}
release_sha: ${{ github.ref }}
github_token: ${{ secrets.GITHUB_TOKEN }}
35 changes: 35 additions & 0 deletions .web-docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
This is a [Packer](https://www.packer.io/) Plugin for building images that work with [Veertu's Anka macOS Virtualization tool](https://veertu.com/).

### Installation

To install this plugin, copy and paste this code into your Packer configuration, then run [`packer init`](https://www.packer.io/docs/commands/init).

```hcl
packer {
required_plugins {
veertu-anka = {
version = "= 3.2.0"
source = "github.com/veertuinc/veertu-anka"
}
}
}
```

Alternatively, you can use `packer plugins install` to manage installation of this plugin.

```sh
$ packer plugins install github.com/veertuinc/veertu-anka
```

### Components
~> For use with the post-processor, it's important to use `anka registry add` to [set your default registry on the machine building your templates/tags](https://docs.veertu.com/anka/apple/command-line-reference/#registry-add).

#### Builders
- [veertu-anka-vm-clone](/packer/integrations/veertuinc/veertu-anka/latest/components/builder/clone) - Packer builder is able to clone existing Anka VM Templates for use with the [Anka Virtualization](https://veertu.com/technology/) package and the [Anka Build Cloud](https://veertu.com/anka-build/). The builder takes a source VM name, clones it, and then runs any provisioning necessary on the new VM Template before stopping or suspending it.
- [veertu-anka-vm-create- ](/packer/integrations/veertuinc/veertu-anka/latest/components/builder/create) Packer builder is able to create new Anka VM Templates for use with the
[Anka Virtualization](https://veertu.com/technology/) package and the [Anka Build Cloud](https://veertu.com/anka-build/). The builder takes the path to macOS installer .app
and installs that macOS version inside of an Anka VM Template.

#### Post-Processors
- [veertu-anka-registry-push](/packer/integrations/veertuinc/veertu-anka/latest/components/post-processor/veertu-anka-registry-push) Packer Post Processor is able to push your created Anka VM templates to
the [Anka Build Cloud Registry](https://veertu.com/anka-build/) through the [Anka Virtualization](https://veertu.com/technology/) package.
122 changes: 122 additions & 0 deletions .web-docs/components/builder/vm-clone/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
Type: `veertu-anka-vm-clone`

The `veertu-anka-vm-clone` Packer builder is able to clone existing Anka VM Templates for use with the [Anka Virtualization](https://veertu.com/technology/) package and the [Anka Build Cloud](https://veertu.com/anka-build/). The builder takes a source VM name, clones it, and then runs any provisioning necessary on the new VM Template before stopping or suspending it.

The builder does _not_ manage templates. Once a template is created, it is up
to you to use it or delete it.

## Important Notes

**In Anka 3.0** we now require a tagged source VM before cloning in order to share the underlying .ank image and optimize disk space. If your source VM is not tagged yet, we will assign one . **We highly recommend pushing this VM Template/Tag to your registry so [disk usage is optimized](https://docs.veertu.com/anka/apple/getting-started/creating-your-first-vm/#disk-optimization).**

## Configuration Reference

There are many configuration options available for the builder. They are segmented below into two categories: required and optional parameters.

### _**Required Configuration**_

* `source_vm_name` (String) The VM to clone for provisioning, either stopped or suspended.

* `type` (String) Must be `veertu-anka-vm-clone`.

### _**Optional Configuration**_

* `vm_name` (String) The name for the VM that is created.

> Generated using the source_vm_name if not provided: (`{{ source_vm_name }}-{10RandomChars}`).
* `vcpu_count` (String) The number of vCPU cores, defaults to `2`.

* `ram_size` (String) The size in "[0-9]+G" format, defaults to `2G`.

* `disk_size` (String) The size in "[0-9]+G" format, defaults to `25G`.

> We will automatically resize the internal disk for you by executing `diskutil apfs resizeContainer disk0s2 0` inside of the VM.
* `stop_vm` (Boolean) Whether or not to stop the vm after it has been created, defaults to false.

* `display_controller` (string) The display controller to set (run `anka modify VMNAME set display --help` to see available options).

* `always_fetch` (Boolean) Always pull the source VM from the registry. Defaults to false.

* `boot_delay` (String) The time to wait before running packer provisioner commands, defaults to `7s`.

* `cacert` (String) Path to a CA Root certificate.

* `cert` (String) Path to your node's client certificate to use for registry communication (if certificate authorization is enabled).

* `insecure` (Boolean) Skip TLS verification.

* `key` (String) Path to your node's client certificate key, if the `cert` certificate doesn't contain one, to use for registry communication (if certificate authorization is enabled).

* `hw_uuid` (String) (Anka 2 only) The Hardware UUID you wish to set (usually generated with `uuidgen`).

* `port_forwarding_rules` (Struct)

> If port forwarding rules are already set and you want to not have them fail the packer build, use `packer build --force`.
* `port_forwarding_guest_port` (Int)
* `port_forwarding_host_port` (Int)
* `port_forwarding_rule_name` (String)

* `registry-path` (String) The registry URL (will use your default configuration if not set).

* `remote` (String) The registry name (will use your default configuration if not set).

> This takes priority in Anka 3 and `registry-path` will be ignored.
* `source_vm_tag` (String) Specify the tag of the VM we want to clone instead of using the default. Also the tag to target when pulling from the registry (defaults to latest tag).

* `update_addons` (Boolean) (Anka 2 only) Update the vm addons. Defaults to false.

* `use_anka_cp` (Boolean) Use built in anka cp command. Defaults to false.

## Example

Here is an example that uses the file and shell provisioners.

```hcl
variable "source_vm_name" {
type = string
default = "anka-packer-base-macos"
}
variable "vm_name" {
type = string
default = "anka-packer-from-source"
}
source "veertu-anka-vm-clone" "clone" {
vm_name = "${var.vm_name}"
source_vm_name = "${var.source_vm_name}"
}
build {
sources = [
"source.veertu-anka-vm-clone.clone",
]
provisioner "file" {
destination = "/private/tmp/"
source = "./examples/ansible"
}
provisioner "shell" {
inline = [
"[[ ! -d /tmp/ansible ]] && exit 100",
"touch /tmp/ansible/test1"
]
}
provisioner "file" {
destination = "./"
direction = "download"
source = "/private/tmp/ansible/test1"
}
provisioner "shell-local" {
inline = [
"[[ ! -f ./test1 ]] && exit 200",
"rm -f ./test1"
]
}
}
```
102 changes: 102 additions & 0 deletions .web-docs/components/builder/vm-create/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
Type: `veertu-anka-vm-create`

**Packer 3.x will no longer support Anka 2.x. You can still however use the Packer 2.x release for support.**

The `veertu-anka-vm-create` Packer builder is able to create new Anka VM Templates for use with the
[Anka Virtualization](https://veertu.com/technology/) package and the [Anka Build Cloud](https://veertu.com/anka-build/). The builder takes the path to macOS installer .app
and installs that macOS version inside of an Anka VM Template.

The builder does _not_ manage templates. Once a template is created, it is up
to you to use it or delete it.

## Configuration Reference

There are many configuration options available for the builder. They are
segmented below into two categories: required and optional parameters.

### Required Configuration

* `installer` (String) The path to a macOS installer. This process takes about 20 minutes.
- Starting in 3.1.2: This can also be set to 'latest' or a specific macOS version in order to have Anka attempt downloading the installer for you (`vm_name` will be set to `anka-packer-base-${installer}`).

* `type` (String) Must be `veertu-anka-vm-create`.

### Optional Configuration

* `vm_name` (String) The name for the VM that is created. One is generated with installer data if not provided (`anka-packer-base-{{ installer.OSVersion }}-{{ installer.BundlerVersion }}`).

* `vcpu_count` (String) The number of vCPU cores, defaults to `2`.

> This change gears us up for Anka 3.0 release when cpu_count will be vcpu_count. For now this is still CPU and not vCPU.
* `ram_size` (String) The size in "[0-9]+G" format, defaults to `4G`.

* `disk_size` (String) The size in "[0-9]+G" format, defaults to `40G`.

> We will automatically resize the internal disk for you by executing `diskutil apfs resizeContainer disk0s2 0` inside of the VM
* `stop_vm` (Boolean) Whether or not to stop the vm after it has been created, defaults to false.

* `use_anka_cp` (Boolean) Use built in anka cp command. You shouldn't need this option. Defaults to false.

* `anka_password` (String) Sets the password for the vm. Can also be set with `ANKA_DEFAULT_PASSWD` env var. Defaults to `admin`.

* `anka_user` (String) Sets the username for the vm. Can also be set with `ANKA_DEFAULT_USER` env var. Defaults to `anka`.

* `boot_delay` (String) The time to wait before running packer provisioner commands, defaults to `7s`.

* `log_level` (String) The log level for Anka. This currently only supports `debug` and is only useful for VM creation failures.

* `hw_uuid` (String) (Anka 2 only) The Hardware UUID you wish to set (usually generated with `uuidgen`).

* `port_forwarding_rules` (Struct)

> If port forwarding rules are already set and you want to not have them fail the packer build, use `packer build --force`.
* `port_forwarding_guest_port` (Int)
* `port_forwarding_host_port` (Int)
* `port_forwarding_rule_name` (String)

* `display_controller` (string) The display controller to set (run `anka modify VMNAME set display --help` to see available options).

## Example

Here is an example:

```hcl
variable "vm_name" {
type = string
default = "anka-packer-base-macos"
}
variable "installer" {
type = string
default = "/Applications/Install macOS Big Sur.app/"
}
variable "vcpu_count" {
type = string
default = ""
}
source "veertu-anka-vm-create" "base" {
installer = "${var.installer}"
vm_name = "${var.vm_name}"
vcpu_count = "${var.vcpu_count}"
}
build {
sources = [
"source.veertu-anka-vm-create.base"
]
provisioner "shell" {
inline = [
"echo hello world",
"echo llamas rock"
]
}
}
```
Loading

0 comments on commit aa95523

Please sign in to comment.