macos.json

{
  "variables": {
    "macos_version": "catalina",
    "images_directory": "appveyor-images",
    "output_directory": "",
    "build_agent_mode": "Parallels",
    "datemark": "{{timestamp}}",
    "install_user": "appveyor",
    "install_password": "appveyor",
    "appVeyorUrl": "https://ci.appveyor.com"
  },
  "sensitive-variables": ["install_password", "appleIdUser", "appleIdPasswd", "fastlaneSession"],
  "provisioners": [
    {
      "type": "shell",
      "inline": [
        "/usr/bin/dscl -u \"{{user `install_user`}}\" -P \"{{user `install_password`}}\" . -passwd \"/Users/{{user `install_user`}}\" \"{{user `install_password`}}\"",
        "security set-keychain-password -o \"{{user `install_password`}}\" -p \"{{user `install_password`}}\" \"/Users/{{user `install_user`}}/Library/Keychains/login.keychain\""
      ]
    },
    {
      "type": "shell",
      "inline": [
        "echo 'export PATH=\"$PATH:/usr/local/bin\"' >> $HOME/.bashrc",
        "echo '{{ user `install_password` }}' | sudo systemsetup -setcomputersleep Never",
        "echo '{{ user `install_password` }}' | CI=1 /bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)\"",
        "/usr/local/bin/brew install --cask powershell",
        "/usr/local/bin/brew install coreutils zlib p7zip"
      ]
    },
    {
      "type": "shell",
      "environment_vars": [
        "HOMEBREW_BUILD_AGENT_MODE={{ user `build_agent_mode` }}"
      ],
      "inline": [
        "brew install appveyor/brew/appveyor-build-agent",
        "brew services restart appveyor/brew/appveyor-build-agent"
      ]
    },
    {
      "type": "file",
      "source": "{{ template_dir }}/scripts/macos/custom-scripts",
      "destination": "./custom-scripts"
    },
    {
      "type": "file",
      "source": "{{ template_dir }}/scripts/macos/",
      "destination": "./"
    },
    {
      "type": "shell",
      "inline": [
        "mkdir windows-scripts"
      ]
    },
    {
      "type": "file",
      "source": "{{ template_dir }}/scripts/Windows/",
      "destination": "./windows-scripts/"
    },
    {
      "type": "shell",
      "environment_vars": [
        "APPLEID_USER={{user `appleIdUser`}}",
        "APPLEID_PWD={{user `appleIdPasswd`}}",
        "APPLEID_SESSION={{user `fastlaneSession`}}",
        "INSTALL_PASSWORD={{user `install_password`}}"
      ],
      "execute_command": "echo '{{ user `install_password` }}' | {{.Vars}} sudo -S -E bash -ex '{{.Path}}'",
      "scripts": [
        "scripts/macos/basicconfig.sh"
      ]
    },
    {
        "type": "shell",
        "scripts":[
            "{{ template_dir }}/scripts/macos/run_custom_scripts.sh"
        ]
    },
    {
      "type": "shell",
      "inline": [
        "if [ -f .ssh/authorized_keys ]; then rm .ssh/authorized_keys; fi",
        "find . -maxdepth 1 -name 'script_*.sh-*.log' -delete"
       ]
    }
  ],
  "builders": [
    {
      "type": "parallels-pvm",
      "parallels_tools_flavor": "mac",
      "source_path": "{{ user `images_directory` }}/{{ user `macos_version` }}_template.pvm",
      "ssh_username": "{{ user `install_user` }}",
      "ssh_password": "{{ user `install_password` }}",
      "ssh_timeout": "120s",
      "shutdown_command": "echo '{{ user `install_password` }}' | sudo -S shutdown -h now",
      "vm_name": "packer-{{user `macos_version`}}-{{user `datemark`}}",
      "skip_compaction": "false"
    },
    {
      "type": "vmware-vmx",
      "source_path": "{{ user `images_directory` }}/macos-{{ user `macos_version` }}-base/macos-{{ user `macos_version` }}-base.vmx",
      "ssh_username": "{{ user `install_user` }}",
      "ssh_password": "{{ user `install_password` }}",
      "ssh_timeout": "120s",
      "shutdown_command": "echo '{{ user `install_password` }}' | sudo -S shutdown -h now",
      "vm_name": "macos-{{user `macos_version`}}-{{user `datemark`}}",
      "headless": "true",
      "output_directory": "{{user `output_directory`}}",
      "snapshot_name": "master",
      "skip_compaction": "true"
    },
    {
      "type": "parallels-iso",
      "guest_os_type": "win-8",
      "parallels_tools_flavor": "mac",
      "boot_wait": "10s",
      "cpus": 2,
      "disk_size": 40960,
      "http_directory": "http",
      "iso_urls": [
        "iso/Mojave.iso"
      ],
      "iso_checksum_type": "none",
      "ssh_username": "{{ user `install_user` }}",
      "ssh_password": "{{ user `install_password` }}",
      "ssh_port": 22,
      "ssh_wait_timeout": "10000s",
      "shutdown_command": "echo '{{ user `install_password` }}'|sudo -S shutdown -h now",
      "vm_name": "packer-{{user `macos_version`}}-{{user `datemark`}}",
      "prlctl": [
        ["set", "{{.Name}}", "--memsize", "2048"],
        ["set", "{{.Name}}", "--memquota", "512:2048"],
        ["set", "{{.Name}}", "--cpus", "2"],
        ["set", "{{.Name}}", "--distribution", "macosx"],
        ["set", "{{.Name}}", "--3d-accelerate", "highest"],
        ["set", "{{.Name}}", "--high-resolution", "off"],
        ["set", "{{.Name}}", "--auto-share-camera", "off"],
        ["set", "{{.Name}}", "--auto-share-bluetooth", "off"],
        ["set", "{{.Name}}", "--on-window-close", "keep-running"],
        ["set", "{{.Name}}", "--shf-host", "off"]
      ]
    }
  ],
  "post-processors": [
    {
      "type": "manifest",
      "output": "{{user `packer_manifest`}}",
      "strip_path": true
    }
  ]
}