AWS

Build macOS VM Images with Packer and Tart, Then Push to ECR

The Packer Tart plugin turns the stock Cirrus Labs macOS image into your own golden image in about 30 seconds. Amazon ECR then stores it like any other OCI image, so every Mac gets the same VM with one tart pull and nobody copies disk images around.

Original content from computingforgeeks.com - post 181418

You will write a tart-cli template, provision the guest over SSH, push it to ECR without touching the keychain and pull it back from an empty cache. Built and run in October 2026 on an AWS EC2 Mac mini (Apple M4, macOS 26.7) with Packer 1.16.2, the Tart plugin v1.21.0 and Tart 2.41.1.

Check what the build needs

Packer only drives Tart here, so the Mac has to run Tart VMs on its own before any template will work. If you haven’t set that up yet, the Tart VM guide for Apple Silicon on this site covers the install, the base images and the keychain fix. Have these ready:

  1. Install Tart on an Apple Silicon Mac with room for two macOS images (brew trust openai/tools, then brew install openai/tools/tart on macOS 26).
  2. Warm the cache with tart clone ghcr.io/cirruslabs/macos-tahoe-base:latest tahoe-base, as the lab did.
  3. Unlock login.keychain if you work over SSH.
  4. Set up the AWS CLI v2 with credentials that can push to ECR.
  5. Create the repository with aws ecr create-repository --region eu-west-1 --repository-name cfg-lab-1332/tart-macos, using your own region and name.

Disk space is the first thing to check, because the macos-tahoe-base image alone shows 32 GB in tart list and the build adds a second VM next to it. The base pull matters for speed too, since the 31 second build below started from a warm cache rather than a fresh download of the base. The template reads the registry copy in Tart’s OCI cache, not the local tahoe-base VM, so tart pull of the same name is enough if you’d rather not keep the extra VM. The keychain is not optional over SSH: on the test host a missing keychain, and the original locked one, stopped macOS guests at boot, while Linux guests did not care.

Only one macOS guest runs during the build, so the two-guest limit Apple puts on each Mac is not a problem on a quiet machine. It does matter on a CI runner that already holds two running macOS VMs, where Tart refuses a third with “The number of VMs exceeds the system limit”. Stop one of them first, or schedule image builds on a Mac that runs no jobs.

Install Packer from the HashiCorp tap

HashiCorp ships current Packer releases through its own Homebrew tap, so install from there. Giving the full hashicorp/tap/packer name matters on Homebrew 7, because it marks that one formula as trusted for you:

brew install hashicorp/tap/packer

Look for the Trusted formula line, because without it Homebrew 7 refuses to load a formula from a third-party tap. The tap, the bottle and the install took 3.5 seconds together.

==> Tapping hashicorp/tap
Cloning into '/opt/homebrew/Library/Taps/hashicorp/homebrew-tap'...
Tapped 2 casks and 34 formulae (102 files, 1.9MB).
==> Trusted formula hashicorp/tap/packer
==> Fetching downloads for: packer
✔︎ Formula packer (1.16.2)
==> Installing packer from hashicorp/tap
🍺  /opt/homebrew/Cellar/packer/1.16.2: 8 files, 100MB, built in 1 second
==> Caveats
zsh completions have been installed to:
  /opt/homebrew/share/zsh/site-functions

Running brew trust --tap hashicorp/tap afterwards printed Trusted tap: hashicorp/tap and changed nothing for this install, so you only need it before installing other formulae from the tap, including formulae pulled in as dependencies. Confirm the binary is on your path:

packer --version

Packer reports the release you just installed.

Packer v1.16.2

Homebrew also runs its own auto-update before an install once the last one is a day old, which adds seconds to scripted runs. The lab exported HOMEBREW_NO_AUTO_UPDATE=1 to skip that, and the Homebrew auto-update guide shows how to make it permanent. For Packer on other platforms, see the Packer install guide for Linux, macOS and Windows.

Write the Packer Tart template

One HCL file holds the plugin pin, the source VM and the provisioner, so the whole image definition fits in version control next to your CI config. Create it in an empty working directory.

vim tahoe.pkr.hcl

Paste this template, which is the exact file the build below ran.

packer {
  required_plugins {
    tart = {
      version = ">= 1.12.0"
      source  = "github.com/cirruslabs/tart"
    }
  }
}

source "tart-cli" "tahoe" {
  vm_base_name = "ghcr.io/cirruslabs/macos-tahoe-base:latest"
  vm_name      = "tahoe-packer"
  cpu_count    = 4
  memory_gb    = 8
  headless     = true
  ssh_username = "admin"
  ssh_password = "admin"
  ssh_timeout  = "180s"
}

build {
  sources = ["source.tart-cli.tahoe"]

  provisioner "shell" {
    inline = [
      "eval \"$(/opt/homebrew/bin/brew shellenv)\"",
      "brew --version",
      "sw_vers",
      "echo 'Built by Packer for the CFG lab' | sudo tee /etc/motd",
      "touch ~/packer-was-here",
    ]
  }
}

Four settings decide how the build behaves:

  • vm_base_name: a local VM or a registry image to clone from.
  • vm_name: the local VM Packer leaves behind, which you push later.
  • ssh_username and ssh_password: admin/admin, the default login on every Cirrus Labs image.
  • inline: shell lines Packer runs as admin over SSH.

A registry name in vm_base_name that is already in Tart’s cache clones straight away, so the plugin only pulls when the image is missing. Set always_pull = true if every build should start from the newest base instead, and accept the longer build that comes with it. The admin password ships inside your image too, so change it in a provisioner before the image leaves your network.

Inside the provisioner, the first line loads brew shellenv so brew resolves in Packer’s SSH session. The motd line is the proof of the build, because a clone pulled from ECR that prints that text shows the provisioned image made the round trip. Replace the last two lines with your real setup (Xcode, runners, agents) once the loop works.

Initialize and validate the template

Packer has no builders of its own for Tart, so packer init reads the required_plugins block and downloads the plugin from GitHub. Run it from the template’s directory, and run it again on every new runner because plugins live in each user’s home.

packer init tahoe.pkr.hcl

Packer picked v1.21.0, the newest release that satisfies >= 1.12.0, in 4.1 seconds.

Installed plugin github.com/cirruslabs/tart v1.21.0 in "/Users/ec2-user/.config/packer/plugins/github.com/cirruslabs/tart/packer-plugin-tart_v1.21.0_x5.0_darwin_arm64"

A loose >= pin means a fresh runner can pick up a newer plugin than your laptop did, so two Macs may build slightly different images from one file. Pin an exact version in required_plugins when builds have to be reproducible. Next, check the syntax and the plugin schema before you spend a VM boot on it.

packer validate tahoe.pkr.hcl

One line back means the template is good to build.

The configuration is valid.

Validation took under a second, which makes it cheap enough to run on every commit before a runner spends a VM boot on a typo.

Build the macOS image with Packer

Over SSH, unlock the login keychain first. A missing keychain makes the macOS guest fail at boot with a security error, a never-unlocked one stopped it on the test host too, and the headless keychain section of that Tart guide covers the details. This command assumes a keychain made with an empty password; a keychain created by a GUI login needs that account’s password after -p instead.

security unlock-keychain -p '' login.keychain

On a fresh EC2 Mac that nobody has logged in to, there’s no keychain to unlock, and security default-keychain reports that none could be found. Create one first with security create-keychain -p '' login.keychain, which is the fix the Tart guide ran on this same host, then run the unlock line.

Then start the build. The -color=false flag keeps the log readable when you redirect it to a file or a CI log.

PACKER_LOG=0 packer build -color=false tahoe.pkr.hcl

The whole build finished in 31.5 seconds. Read it from the top, because each line tells you which part of Tart did the work.

==> tart-cli.tahoe: Cloning virtual machine...
==> tart-cli.tahoe: Updating virtual machine resources...
==> tart-cli.tahoe: Inspecting machine disk image...
==> tart-cli.tahoe: Getting partition table...
==> tart-cli.tahoe: No recovery partition was found, assuming that it was already deleted.
==> tart-cli.tahoe: Starting the virtual machine...
==> tart-cli.tahoe: Successfully started the virtual machine...
==> tart-cli.tahoe: Creating temporary RSA SSH key for instance...
==> tart-cli.tahoe: Using SSH communicator to connect: 192.168.64.6
==> tart-cli.tahoe: Waiting for SSH to become available...
==> tart-cli.tahoe: Connected to SSH!
==> tart-cli.tahoe: Provisioning with shell script: /var/folders/m5/mhddkc2d6c5_3f_vljmqvq_40000gn/T/packer-shell3901085944
==> tart-cli.tahoe: Homebrew 7.0.9
==> tart-cli.tahoe: ProductName:		macOS
==> tart-cli.tahoe: ProductVersion:		26.6.2
==> tart-cli.tahoe: BuildVersion:		25G83
==> tart-cli.tahoe: Built by Packer for the CFG lab
==> tart-cli.tahoe: Gracefully shutting down the VM...
==> tart-cli.tahoe: Shutdown NOW!
==> tart-cli.tahoe:
==> tart-cli.tahoe: System shutdown time has arrived
==> tart-cli.tahoe: Waiting for the tart process to exit...
Build 'tart-cli.tahoe' finished after 31 seconds 506 milliseconds.

==> Wait completed after 31 seconds 506 milliseconds

==> Builds finished. The artifacts of successful builds are:
--> tart-cli.tahoe: tahoe-packer

The recovery partition line is expected. The plugin’s recovery_partition setting defaults to deleting it, and the Cirrus Labs base image has none, so there was nothing to remove. The guest reports macOS 26.6.2 and Homebrew 7.0.9 even though the host runs 26.7, because the base image is only as current as its last Cirrus Labs rebuild. Add softwareupdate or brew upgrade to the provisioner if your image has to be newer than that. The address on the SSH line comes from Tart’s private NAT on the Mac, so expect a different one on yours.

Packer shuts the guest down cleanly before it finishes, which is what you want: the disk is consistent when you push it. The artifact is a plain local VM called tahoe-packer, so tart run tahoe-packer boots it if you want to look around first.

Here is the same validate and build run, rendered from the captured log on the M4 Mac mini.

Packer Tart plugin build of a macOS Tahoe image: packer validate, then packer build cloning tahoe-base, provisioning over SSH and finishing in 31 seconds

With tahoe-packer built and shut down, the image is ready to leave the Mac.

Push the image to Amazon ECR

Tart can log in to a registry with tart login, but that stores the password in the keychain, and with the keychain locked it failed with “User interaction is not allowed”. The TART_REGISTRY_USERNAME and TART_REGISTRY_PASSWORD variables skip the keychain completely, which suits CI. ECR’s username is always AWS, and the password is a token that stays valid for 12 hours. Set the image reference once, because you’ll use it four more times:

export REGISTRY=123456789012.dkr.ecr.eu-west-1.amazonaws.com
export REF=$REGISTRY/cfg-lab-1332/tart-macos:packer-2026-10
export TART_REGISTRY_USERNAME=AWS
export TART_REGISTRY_PASSWORD=$(aws ecr get-login-password --region eu-west-1)

Replace 123456789012 with your account ID and the repository path with yours. Refresh TART_REGISTRY_PASSWORD in any shell older than the 12 hour token. The Tart docs also say these two variables apply to every registry unless TART_REGISTRY_HOSTNAME names one, so set it to $REGISTRY or unset the pair after the push, otherwise a later pull from ghcr.io in the same shell sends it your ECR token. Now push the VM Packer built.

tart push tahoe-packer "$REF"

Tart uploads four parts in order: the VM config, the disk, the NVRAM and the manifest that ties them together. The disk counter redraws in place, so only its first and last values are shown here:

pushing tahoe-packer to 123456789012.dkr.ecr.eu-west-1.amazonaws.com/cfg-lab-1332/tart-macos:packer-2026-10...
pushing config...
pushing disk... this will take a while...
0%
100%
pushing NVRAM...
pushing manifest for packer-2026-10...

The push took 4 minutes 49 seconds from an EC2 Mac in the same region as the registry. From a Mac on a slower uplink, the upload speed sets the pace instead. Two flags in tart push --help are worth knowing for ECR, though neither was used in this run. The first, --chunk-size, switches from one monolithic blob upload to chunked uploads; the help text notes that ECR only accepts chunks larger than 5 MB. The second, --populate-cache, keeps a copy of the pushed image in the local cache, which costs disk but saves a pull later.

If you already push containers, nothing else changes on the AWS side: lifecycle rules, scanning and IAM policies work the same way as for the Docker images you upload to ECR. Any other OCI registry works too, including a self-hosted Harbor registry.

Pull the image from an empty cache

A pull on the same Mac proves nothing if a local copy is still around, so delete the build output and any cached copy of the ECR image before you pull. Start with the VM Packer left behind.

tart delete tahoe-packer

Then try to delete the cached registry copy.

tart delete "$REF"

Tart says there is nothing to delete.

the specified VM "123456789012.dkr.ecr.eu-west-1.amazonaws.com/cfg-lab-1332/tart-macos:packer-2026-10" does not exist

That error is good news. tart push does not add the image to the local cache unless you pass --populate-cache, so the pull below really comes from ECR rather than from disk.

tart pull "$REF"

Watch the third line, where Tart spots the Tahoe base image in its cache and skips the layers both images share.

pulling 123456789012.dkr.ecr.eu-west-1.amazonaws.com/cfg-lab-1332/tart-macos:packer-2026-10...
pulling manifest...
found an image ghcr.io/cirruslabs/macos-tahoe-base@sha256:4aaa751fa7538902d73c767f27a066fc87e83f183069da4e4b5022863abd4c77 that will allow us to avoid fetching 19.04 GB, will try use it...
pulling disk (26.3 GB compressed)...
0%
100%
pulling NVRAM...

The pull finished in 1 minute 23 seconds, against 4 minutes 49 seconds for the push. The 19.04 GB Tart skipped explains most of that gap: of the 26.3 GB compressed disk, about 7 GB still crossed the network, more than a motd file because booting and provisioning the guest rewrites disk blocks too. So if you pre-pull macos-tahoe-base on every runner, your custom images arrive in a fraction of the time. A Mac without the base in its cache downloads the whole 26.3 GB, and that case wasn’t timed here.

Verify the image in a clone

Clone the pulled image into a working VM and boot it headless:

tart clone "$REF" tahoe-verify
tart run --no-graphics tahoe-verify &

The guest agent needs a few seconds after boot, so tart exec fails until it answers. The lab wrapped the motd read in a loop that retries every 3 seconds for up to 3 minutes, which is the simplest way to wait in a script.

for i in $(seq 1 60); do tart exec tahoe-verify cat /etc/motd 2>/dev/null && break; sleep 3; done

The text from the template came back from a VM that started life in ECR.

Built by Packer for the CFG lab

The second check in the run went wrong, and it’s an easy trap. tart exec tahoe-verify ls ~/packer-was-here answered ls: /Users/ec2-user/packer-was-here: No such file or directory. The host shell expanded ~ to the host user’s home before tart exec sent the command, while the provisioner had created the file as admin in /Users/admin. So the error says nothing about the image. Quoting the tilde would not help either, because tart exec hands the command straight to the guest agent with no shell to expand it. Write the guest path out in full (/Users/admin/packer-was-here) when you check files inside a guest.

Stop and delete the test clone when you’re done, because it holds a full macOS disk:

tart stop tahoe-verify
tart delete tahoe-verify

The pulled image stays in the OCI cache, so the next tart clone "$REF" on this Mac is instant.

Rebuild and ship the next image

Each step’s time from the run gives you a baseline for a CI job. All of it ran on one M4 Mac mini with the base image cached:

StepCommandTime
Install Packerbrew install hashicorp/tap/packer3.5 s
Fetch the pluginpacker init4.1 s
Check the templatepacker validate0.9 s
Build from tahoe-basepacker build31.5 s
Push to ECR, same regiontart push4 min 49 s
Pull with the base cachedtart pull1 min 23 s

The push is the slow part, so spend your effort there: build on a Mac close to the registry, and tag every image instead of overwriting one tag. For the next image, the loop is short:

  1. Edit the provisioner in tahoe.pkr.hcl.
  2. Run packer validate, then packer build.
  3. Point REF at a new tag and refresh TART_REGISTRY_PASSWORD.
  4. Run tart push tahoe-packer "$REF".
  5. On each runner, tart pull "$REF" and clone from it.

For Linux or Windows images aimed at AWS rather than Apple Silicon, the same template ideas carry over to building EC2 AMIs with Packer and Ansible. Options beyond this template, such as disk_size_gb, run_extra_args and building from an IPSW, are in the Tart builder reference.

Keep reading

Install KVM and Virt-Manager on Arch Linux Virtualization Install KVM and Virt-Manager on Arch Linux Install VirtIO Drivers on Windows 11 and Server 2025: ISO and MSI KVM Install VirtIO Drivers on Windows 11 and Server 2025: ISO and MSI Install KVM on Debian 13 / Debian 12: Complete Guide KVM Install KVM on Debian 13 / Debian 12: Complete Guide AWS Bedrock vs Azure AI Foundry vs Vertex AI (2026) AI AWS Bedrock vs Azure AI Foundry vs Vertex AI (2026) Run macOS and Linux VMs with UTM on Apple Silicon macos Run macOS and Linux VMs with UTM on Apple Silicon Install Calico CNI plugin on AWS EKS Kubernetes Cluster Containers Install Calico CNI plugin on AWS EKS Kubernetes Cluster

Leave a Comment

Press ESC to close