diff --git a/docs/create-image-and-azure-resources.md b/docs/create-image-and-azure-resources.md index 877f5f0e7d71..14336728ffec 100644 --- a/docs/create-image-and-azure-resources.md +++ b/docs/create-image-and-azure-resources.md @@ -2,7 +2,7 @@ The runner-images project uses [Packer](https://www.packer.io/) to generate disk images for Windows 2019/2022 and Ubuntu 20.04/22.04. -Each image is configured by a JSON or HCL2 Packer template that specifies where to build the image (Azure, in this case), +Each image is configured by a HCL2 Packer template that specifies where to build the image (Azure, in this case), and what steps to run to install software and prepare the disk. The Packer process initializes a connection to the Azure subscription using Azure CLI and creates temporary resources diff --git a/docs/debugging-failed-builds.md b/docs/debugging-failed-builds.md index d8a4c2ed8910..4e301e83f771 100644 --- a/docs/debugging-failed-builds.md +++ b/docs/debugging-failed-builds.md @@ -21,7 +21,6 @@ Log into the Azure Portal. Find that resource group under `Resource groups`. Y ## Step 3: Connect to the VM Select the VM in the resource group. Click `Connect:` -This will download an RDP file. Open that and enter the credentials found in the JSON file you pass to `packer build`: +This will download an RDP file. Open that and enter the credentials found in the HCL2 file you pass to `packer build`: ![VM credentials screenshot](/docs/resources/vmCredentials.png "VM credentials screenshot") - diff --git a/images.CI/macos/azure-pipelines/image-generation.yml b/images.CI/macos/azure-pipelines/image-generation.yml index bda268b9f442..19bfdde3cc6b 100644 --- a/images.CI/macos/azure-pipelines/image-generation.yml +++ b/images.CI/macos/azure-pipelines/image-generation.yml @@ -63,6 +63,7 @@ jobs: 'Using ssh communicator to connect:' ) + packer init ${{ parameters.template_path }} packer build -on-error=abort ` -var="vcenter_server=$(vcenter-server-v2)" ` -var="vcenter_username=$(vcenter-username-v2)" ` diff --git a/images.CI/macos/azure-pipelines/macos11.yml b/images.CI/macos/azure-pipelines/macos11.yml index bbf019fdece3..012b3e61d0b9 100644 --- a/images.CI/macos/azure-pipelines/macos11.yml +++ b/images.CI/macos/azure-pipelines/macos11.yml @@ -19,5 +19,5 @@ jobs: parameters: image_label: 'macOS Big Sur' base_image_name: 'clean-macOS-11-380Gb-runner' - template_path: 'templates/macOS-11.json' + template_path: 'templates/macOS-11.pkr.hcl' target_datastore: 'ds-image' diff --git a/images.CI/macos/azure-pipelines/macos12.yml b/images.CI/macos/azure-pipelines/macos12.yml index 4baf7e30ed8e..afa2190c2baa 100644 --- a/images.CI/macos/azure-pipelines/macos12.yml +++ b/images.CI/macos/azure-pipelines/macos12.yml @@ -19,5 +19,5 @@ jobs: parameters: image_label: 'macOS Monterey' base_image_name: 'clean-macOS-12-380Gb-runner' - template_path: 'templates/macOS-12.json' + template_path: 'templates/macOS-12.pkr.hcl' target_datastore: 'ds-image' diff --git a/images/macos/templates/macOS-11.json b/images/macos/templates/macOS-11.json deleted file mode 100644 index ded01dd95121..000000000000 --- a/images/macos/templates/macOS-11.json +++ /dev/null @@ -1,262 +0,0 @@ -{ - "variables": { - "vcenter_server": null, - "vcenter_username": null, - "vcenter_password": null, - "vcenter_datacenter": null, - "cluster_or_esxi_host": null, - "esxi_datastore": null, - "build_id": null, - "baseimage_name": null, - "output_folder": null, - "vm_username": null, - "vm_password": null, - "github_api_pat": null, - "xcode_install_storage_url": null, - "xcode_install_sas": null, - "image_os": "macos11" - }, - "builders": [ - { - "type": "vsphere-clone", - "vcenter_server": "{{user `vcenter_server`}}", - "username": "{{user `vcenter_username`}}", - "password": "{{user `vcenter_password`}}", - "insecure_connection": true, - "datacenter": "{{ user `vcenter_datacenter` }}", - "template": "{{ user `baseimage_name` }}", - "folder": "{{user `output_folder` }}", - "host": "{{user `cluster_or_esxi_host`}}", - "datastore": "{{user `esxi_datastore`}}", - "vm_name": "{{user `build_id`}}", - "ssh_username": "{{user `vm_username`}}", - "ssh_password": "{{user `vm_password`}}", - "CPUs": "5", - "cpu_cores": "5", - "RAM": "24576", - "NestedHV": "true", - "shutdown_timeout": "15m" - } - ], - "provisioners": [ - { - "type": "shell", - "inline": "mkdir ~/image-generation" - }, - { - "type": "file", - "sources": [ - "./assets/xamarin-selector", - "./scripts/tests", - "./scripts/docs-gen", - "./scripts/helpers" - ], - "destination": "~/image-generation/" - }, - { - "type": "file", - "source": "../../helpers/software-report-base", - "destination": "~/image-generation/docs-gen/" - }, - { - "type": "file", - "source": "./assets/add-certificate.swift", - "destination": "~/image-generation/add-certificate.swift" - }, - { - "type": "file", - "source": "./assets/bashrc", - "destination": "~/.bashrc" - }, - { - "type": "file", - "source": "./assets/bashprofile", - "destination": "~/.bash_profile" - }, - { - "type": "file", - "source": "./assets/bootstrap-provisioner", - "destination": "~/bootstrap" - }, - { - "type": "file", - "source": "./toolsets/toolset-11.json", - "destination": "~/image-generation/toolset.json" - }, - { - "type": "shell", - "inline": [ - "mv ~/image-generation/docs-gen ~/image-generation/software-report", - "mv ~/image-generation/xamarin-selector ~/image-generation/assets", - "mkdir ~/utils", - "mv ~/image-generation/helpers/confirm-identified-developers.scpt ~/utils", - "mv ~/image-generation/helpers/invoke-tests.sh ~/utils", - "mv ~/image-generation/helpers/utils.sh ~/utils", - "mv ~/image-generation/helpers/xamarin-utils.sh ~/utils" - ], - "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", - "scripts": [ - "./scripts/build/install-xcode-clt.sh", - "./scripts/build/install-homebrew.sh" - ] - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}", - "scripts": [ - "./scripts/build/install-xcode-clt.sh", - "./scripts/build/configure-network-interface-detection.sh", - "./scripts/build/configure-autologin.sh", - "./scripts/build/configure-auto-updates.sh", - "./scripts/build/configure-screensaver.sh", - "./scripts/build/configure-ntpconf.sh", - "./scripts/build/configure-max-files-limitation.sh", - "./scripts/build/configure-shell.sh" - ], - "environment_vars": [ - "PASSWORD={{user `vm_password`}}", - "USERNAME={{user `vm_username`}}" - ] - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", - "scripts": [ - "./scripts/build/configure-preimagedata.sh", - "./scripts/build/configure-ssh.sh", - "./scripts/build/configure-machine.sh" - ], - "environment_vars": [ - "IMAGE_VERSION={{user `build_id`}}", - "IMAGE_OS={{user `image_os`}}" - ] - }, - { - "type": "shell", - "execute_command": "sudo {{ .Vars }} {{ .Path }}", - "inline": [ - "echo 'Reboot VM'", - "shutdown -r now" - ], - "expect_disconnect": true - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", - "pause_before": "30s", - "scripts": [ - "./scripts/build/configure-windows.sh", - "./scripts/build/install-powershell.sh", - "./scripts/build/install-dotnet.sh", - "./scripts/build/install-python.sh", - "./scripts/build/install-azcopy.sh", - "./scripts/build/install-openssl.sh", - "./scripts/build/install-ruby.sh", - "./scripts/build/install-rubygems.sh", - "./scripts/build/install-git.sh", - "./scripts/build/install-mongodb.sh", - "./scripts/build/install-node.sh" - ], - "environment_vars": [ - "API_PAT={{user `github_api_pat`}}" - ] - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}", - "script": "./scripts/build/Install-Xcode.ps1", - "environment_vars": [ - "XCODE_INSTALL_STORAGE_URL={{user `xcode_install_storage_url`}}", - "XCODE_INSTALL_SAS={{user `xcode_install_sas`}}" - ] - }, - { - "type": "shell", - "execute_command": "sudo {{ .Vars }} {{ .Path }}", - "inline": [ - "echo 'Reboot VM'", - "shutdown -r now" - ], - "expect_disconnect": true - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", - "scripts": [ - "./scripts/build/install-actions-cache.sh", - "./scripts/build/install-common-utils.sh", - "./scripts/build/install-llvm.sh", - "./scripts/build/install-golang.sh", - "./scripts/build/install-swiftlint.sh", - "./scripts/build/install-openjdk.sh", - "./scripts/build/install-php.sh", - "./scripts/build/install-aws-tools.sh", - "./scripts/build/install-rust.sh", - "./scripts/build/install-gcc.sh", - "./scripts/build/install-haskell.sh", - "./scripts/build/install-cocoapods.sh", - "./scripts/build/install-android-sdk.sh", - "./scripts/build/install-xamarin.sh", - "./scripts/build/install-visualstudio.sh", - "./scripts/build/install-nvm.sh", - "./scripts/build/install-apache.sh", - "./scripts/build/install-nginx.sh", - "./scripts/build/install-postgresql.sh", - "./scripts/build/install-audiodevice.sh", - "./scripts/build/install-vcpkg.sh", - "./scripts/build/install-miniconda.sh", - "./scripts/build/install-safari.sh", - "./scripts/build/install-chrome.sh", - "./scripts/build/install-edge.sh", - "./scripts/build/install-firefox.sh", - "./scripts/build/install-pypy.sh", - "./scripts/build/install-pipx-packages.sh", - "./scripts/build/install-bicep.sh", - "./scripts/build/install-codeql-bundle.sh" - ], - "environment_vars": [ - "API_PAT={{user `github_api_pat`}}" - ] - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}", - "scripts": [ - "./scripts/build/Install-Toolset.ps1", - "./scripts/build/Configure-Toolset.ps1" - ] - }, - { - "type": "shell", - "execute_command": "ruby {{ .Path }}", - "scripts": [ - "./scripts/build/configure-xcode-simulators.rb" - ] - }, - { - "type": "shell", - "inline": [ - "pwsh -File \"$HOME/image-generation/software-report/Generate-SoftwareReport.ps1\" -OutputDirectory \"$HOME/image-generation/output/software-report\" -ImageName {{user `build_id`}}", - "pwsh -File \"$HOME/image-generation/tests/RunAll-Tests.ps1\"" - ] - }, - { - "type": "file", - "direction": "download", - "source": "~/image-generation/output/*", - "destination": "../image-output/" - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", - "scripts": [ - "./scripts/build/configure-hostname.sh", - "./scripts/build/configure-system.sh" - ] - } - ] -} diff --git a/images/macos/templates/macOS-11.pkr.hcl b/images/macos/templates/macOS-11.pkr.hcl new file mode 100644 index 000000000000..7635ad3af99f --- /dev/null +++ b/images/macos/templates/macOS-11.pkr.hcl @@ -0,0 +1,303 @@ +packer { + required_plugins { + vsphere = { + source = "github.com/hashicorp/vsphere" + version = "~> 1" + } + } +} + +variable "baseimage_name" { + type = string +} + +variable "build_id" { + type = string +} + +variable "cluster_or_esxi_host" { + type = string +} + +variable "esxi_datastore" { + type = string +} + +variable "github_api_pat" { + type = string + default = "" + sensitive = true +} + +variable "image_os" { + type = string + default = "macos11" +} + +variable "output_folder" { + type = string +} + +variable "vcenter_datacenter" { + type = string +} + +variable "vcenter_password" { + type = string + sensitive = true +} + +variable "vcenter_server" { + type = string +} + +variable "vcenter_username" { + type = string + sensitive = true +} + +variable "vm_password" { + type = string + sensitive = true +} + +variable "vm_username" { + type = string + sensitive = true +} + +variable "xcode_install_sas" { + type = string + sensitive = true +} + +variable "xcode_install_storage_url" { + type = string + sensitive = true +} + +source "vsphere-clone" "template" { + CPUs = "5" + NestedHV = "true" + RAM = "24576" + cpu_cores = "5" + datacenter = "${var.vcenter_datacenter}" + datastore = "${var.esxi_datastore}" + folder = "${var.output_folder}" + host = "${var.cluster_or_esxi_host}" + insecure_connection = true + password = "${var.vcenter_password}" + shutdown_timeout = "15m" + ssh_password = "${var.vm_password}" + ssh_username = "${var.vm_username}" + template = "${var.baseimage_name}" + username = "${var.vcenter_username}" + vcenter_server = "${var.vcenter_server}" + vm_name = "${var.build_id}" +} + +build { + sources = ["source.vsphere-clone.template"] + + provisioner "shell" { + inline = ["mkdir ~/image-generation"] + } + + provisioner "file" { + destination = "~/image-generation/" + sources = [ + "./assets/xamarin-selector", + "./scripts/tests", + "./scripts/docs-gen", + "./scripts/helpers" + ] + } + + provisioner "file" { + destination = "~/image-generation/docs-gen/" + source = "../../helpers/software-report-base" + } + + provisioner "file" { + destination = "~/image-generation/add-certificate.swift" + source = "./assets/add-certificate.swift" + } + + provisioner "file" { + destination = "~/.bashrc" + source = "./assets/bashrc" + } + + provisioner "file" { + destination = "~/.bash_profile" + source = "./assets/bashprofile" + } + + provisioner "shell" { + inline = [ "mkdir ~/bootstrap" ] + } + + provisioner "file" { + destination = "~/bootstrap" + source = "./assets/bootstrap-provisioner/" + } + + provisioner "file" { + destination = "~/image-generation/toolset.json" + source = "./toolsets/toolset-11.json" + } + + provisioner "shell" { + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + inline = [ + "mv ~/image-generation/docs-gen ~/image-generation/software-report", + "mv ~/image-generation/xamarin-selector ~/image-generation/assets", + "mkdir ~/utils", + "mv ~/image-generation/helpers/confirm-identified-developers.scpt ~/utils", + "mv ~/image-generation/helpers/invoke-tests.sh ~/utils", + "mv ~/image-generation/helpers/utils.sh ~/utils", + "mv ~/image-generation/helpers/xamarin-utils.sh ~/utils" + ] + } + + provisioner "shell" { + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}" + scripts = [ + "./scripts/build/install-xcode-clt.sh", + "./scripts/build/install-homebrew.sh" + ] + } + + provisioner "shell" { + environment_vars = ["PASSWORD=${var.vm_password}", "USERNAME=${var.vm_username}"] + execute_command = "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}" + scripts = [ + "./scripts/build/install-xcode-clt.sh", + "./scripts/build/configure-network-interface-detection.sh", + "./scripts/build/configure-autologin.sh", + "./scripts/build/configure-auto-updates.sh", + "./scripts/build/configure-screensaver.sh", + "./scripts/build/configure-ntpconf.sh", + "./scripts/build/configure-max-files-limitation.sh", + "./scripts/build/configure-shell.sh" + ] + } + + provisioner "shell" { + environment_vars = ["IMAGE_VERSION=${var.build_id}", "IMAGE_OS=${var.image_os}"] + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}" + scripts = [ + "./scripts/build/configure-preimagedata.sh", + "./scripts/build/configure-ssh.sh", + "./scripts/build/configure-machine.sh" + ] + } + + provisioner "shell" { + execute_command = "sudo {{ .Vars }} {{ .Path }}" + expect_disconnect = true + inline = ["echo 'Reboot VM'", "shutdown -r now"] + } + + provisioner "shell" { + environment_vars = ["API_PAT=${var.github_api_pat}"] + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}" + pause_before = "30s" + scripts = [ + "./scripts/build/configure-windows.sh", + "./scripts/build/install-powershell.sh", + "./scripts/build/install-dotnet.sh", + "./scripts/build/install-python.sh", + "./scripts/build/install-azcopy.sh", + "./scripts/build/install-openssl.sh", + "./scripts/build/install-ruby.sh", + "./scripts/build/install-rubygems.sh", + "./scripts/build/install-git.sh", + "./scripts/build/install-mongodb.sh", + "./scripts/build/install-node.sh" + ] + } + + provisioner "shell" { + environment_vars = ["XCODE_INSTALL_STORAGE_URL=${var.xcode_install_storage_url}", "XCODE_INSTALL_SAS=${var.xcode_install_sas}"] + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}" + script = "./scripts/build/Install-Xcode.ps1" + } + + provisioner "shell" { + execute_command = "sudo {{ .Vars }} {{ .Path }}" + expect_disconnect = true + inline = ["echo 'Reboot VM'", "shutdown -r now"] + } + + provisioner "shell" { + environment_vars = ["API_PAT=${var.github_api_pat}"] + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}" + scripts = [ + "./scripts/build/install-actions-cache.sh", + "./scripts/build/install-common-utils.sh", + "./scripts/build/install-llvm.sh", + "./scripts/build/install-golang.sh", + "./scripts/build/install-swiftlint.sh", + "./scripts/build/install-openjdk.sh", + "./scripts/build/install-php.sh", + "./scripts/build/install-aws-tools.sh", + "./scripts/build/install-rust.sh", + "./scripts/build/install-gcc.sh", + "./scripts/build/install-haskell.sh", + "./scripts/build/install-cocoapods.sh", + "./scripts/build/install-android-sdk.sh", + "./scripts/build/install-xamarin.sh", + "./scripts/build/install-visualstudio.sh", + "./scripts/build/install-nvm.sh", + "./scripts/build/install-apache.sh", + "./scripts/build/install-nginx.sh", + "./scripts/build/install-postgresql.sh", + "./scripts/build/install-audiodevice.sh", + "./scripts/build/install-vcpkg.sh", + "./scripts/build/install-miniconda.sh", + "./scripts/build/install-safari.sh", + "./scripts/build/install-chrome.sh", + "./scripts/build/install-edge.sh", + "./scripts/build/install-firefox.sh", + "./scripts/build/install-pypy.sh", + "./scripts/build/install-pipx-packages.sh", + "./scripts/build/install-bicep.sh", + "./scripts/build/install-codeql-bundle.sh" + ] + } + + provisioner "shell" { + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}" + scripts = [ + "./scripts/build/Install-Toolset.ps1", + "./scripts/build/Configure-Toolset.ps1" + ] + } + + provisioner "shell" { + execute_command = "ruby {{ .Path }}" + script = "./scripts/build/configure-xcode-simulators.rb" + } + + provisioner "shell" { + inline = [ + "pwsh -File \"$HOME/image-generation/software-report/Generate-SoftwareReport.ps1\" -OutputDirectory \"$HOME/image-generation/output/software-report\" -ImageName ${var.build_id}", + "pwsh -File \"$HOME/image-generation/tests/RunAll-Tests.ps1\"" + ] + } + + provisioner "file" { + destination = "../image-output/" + direction = "download" + source = "~/image-generation/output/*" + } + + provisioner "shell" { + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}" + scripts = [ + "./scripts/build/configure-hostname.sh", + "./scripts/build/configure-system.sh" + ] + } +} diff --git a/images/macos/templates/macOS-12.json b/images/macos/templates/macOS-12.json deleted file mode 100644 index 7ca2da135a12..000000000000 --- a/images/macos/templates/macOS-12.json +++ /dev/null @@ -1,268 +0,0 @@ -{ - "variables": { - "vcenter_server": null, - "vcenter_username": null, - "vcenter_password": null, - "vcenter_datacenter": null, - "cluster_or_esxi_host": null, - "esxi_datastore": null, - "build_id": null, - "baseimage_name": null, - "output_folder": null, - "vm_username": null, - "vm_password": null, - "github_api_pat": null, - "xcode_install_storage_url": null, - "xcode_install_sas": null, - "image_os": "macos12" - }, - "builders": [ - { - "type": "vsphere-clone", - "vcenter_server": "{{user `vcenter_server`}}", - "username": "{{user `vcenter_username`}}", - "password": "{{user `vcenter_password`}}", - "insecure_connection": true, - "datacenter": "{{ user `vcenter_datacenter` }}", - "template": "{{ user `baseimage_name` }}", - "folder": "{{user `output_folder` }}", - "host": "{{user `cluster_or_esxi_host`}}", - "datastore": "{{user `esxi_datastore`}}", - "vm_name": "{{user `build_id`}}", - "ssh_username": "{{user `vm_username`}}", - "ssh_password": "{{user `vm_password`}}", - "CPUs": "5", - "cpu_cores": "5", - "RAM": "24576", - "NestedHV": "true", - "shutdown_timeout": "15m" - } - ], - "provisioners": [ - { - "type": "shell", - "inline": "mkdir ~/image-generation" - }, - { - "type": "file", - "sources": [ - "./assets/xamarin-selector", - "./scripts/tests", - "./scripts/docs-gen", - "./scripts/helpers" - ], - "destination": "~/image-generation/" - }, - { - "type": "file", - "source": "../../helpers/software-report-base", - "destination": "~/image-generation/docs-gen/" - }, - { - "type": "file", - "source": "./assets/add-certificate.swift", - "destination": "~/image-generation/add-certificate.swift" - }, - { - "type": "file", - "source": "./assets/bashrc", - "destination": "~/.bashrc" - }, - { - "type": "file", - "source": "./assets/bashprofile", - "destination": "~/.bash_profile" - }, - { - "type": "file", - "source": "./assets/bootstrap-provisioner", - "destination": "~/bootstrap" - }, - { - "type": "file", - "source": "./toolsets/toolset-12.json", - "destination": "~/image-generation/toolset.json" - }, - { - "type": "shell", - "inline": [ - "mv ~/image-generation/docs-gen ~/image-generation/software-report", - "mv ~/image-generation/xamarin-selector ~/image-generation/assets", - "mkdir ~/utils", - "mv ~/image-generation/helpers/confirm-identified-developers.scpt ~/utils", - "mv ~/image-generation/helpers/invoke-tests.sh ~/utils", - "mv ~/image-generation/helpers/utils.sh ~/utils", - "mv ~/image-generation/helpers/xamarin-utils.sh ~/utils" - ], - "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", - "scripts": [ - "./scripts/build/install-xcode-clt.sh", - "./scripts/build/install-homebrew.sh" - ] - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}", - "scripts": [ - "./scripts/build/configure-network-interface-detection.sh", - "./scripts/build/configure-autologin.sh", - "./scripts/build/configure-auto-updates.sh", - "./scripts/build/configure-screensaver.sh", - "./scripts/build/configure-ntpconf.sh", - "./scripts/build/configure-max-files-limitation.sh", - "./scripts/build/configure-shell.sh" - ], - "environment_vars": [ - "PASSWORD={{user `vm_password`}}", - "USERNAME={{user `vm_username`}}" - ] - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", - "scripts": [ - "./scripts/build/configure-preimagedata.sh", - "./scripts/build/configure-ssh.sh", - "./scripts/build/configure-machine.sh" - ], - "environment_vars": [ - "IMAGE_VERSION={{user `build_id`}}", - "IMAGE_OS={{user `image_os`}}", - "PASSWORD={{user `vm_password`}}" - ] - }, - { - "type": "shell", - "execute_command": "sudo {{ .Vars }} {{ .Path }}", - "inline": [ - "echo 'Reboot VM'", - "shutdown -r now" - ], - "expect_disconnect": true - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", - "pause_before": "30s", - "scripts": [ - "./scripts/build/configure-windows.sh", - "./scripts/build/install-powershell.sh", - "./scripts/build/install-dotnet.sh", - "./scripts/build/install-python.sh", - "./scripts/build/install-azcopy.sh", - "./scripts/build/install-openssl.sh", - "./scripts/build/install-ruby.sh", - "./scripts/build/install-rubygems.sh", - "./scripts/build/install-git.sh", - "./scripts/build/install-mongodb.sh", - "./scripts/build/install-node.sh", - "./scripts/build/install-common-utils.sh" - ], - "environment_vars": [ - "API_PAT={{user `github_api_pat`}}", - "USER_PASSWORD={{user `vm_password`}}" - ] - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}", - "script": "./scripts/build/Install-Xcode.ps1", - "environment_vars": [ - "XCODE_INSTALL_STORAGE_URL={{user `xcode_install_storage_url`}}", - "XCODE_INSTALL_SAS={{user `xcode_install_sas`}}" - ] - }, - { - "type": "shell", - "execute_command": "sudo {{ .Vars }} {{ .Path }}", - "inline": [ - "echo 'Reboot VM'", - "shutdown -r now" - ], - "expect_disconnect": true - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", - "scripts": [ - "./scripts/build/install-actions-cache.sh", - "./scripts/build/install-llvm.sh", - "./scripts/build/install-golang.sh", - "./scripts/build/install-swiftlint.sh", - "./scripts/build/install-openjdk.sh", - "./scripts/build/install-php.sh", - "./scripts/build/install-aws-tools.sh", - "./scripts/build/install-rust.sh", - "./scripts/build/install-gcc.sh", - "./scripts/build/install-haskell.sh", - "./scripts/build/install-cocoapods.sh", - "./scripts/build/install-android-sdk.sh", - "./scripts/build/install-xamarin.sh", - "./scripts/build/install-visualstudio.sh", - "./scripts/build/install-nvm.sh", - "./scripts/build/install-apache.sh", - "./scripts/build/install-nginx.sh", - "./scripts/build/install-postgresql.sh", - "./scripts/build/install-audiodevice.sh", - "./scripts/build/install-vcpkg.sh", - "./scripts/build/install-miniconda.sh", - "./scripts/build/install-safari.sh", - "./scripts/build/install-chrome.sh", - "./scripts/build/install-edge.sh", - "./scripts/build/install-firefox.sh", - "./scripts/build/install-pypy.sh", - "./scripts/build/install-pipx-packages.sh", - "./scripts/build/install-bicep.sh", - "./scripts/build/install-codeql-bundle.sh" - ], - "environment_vars": [ - "API_PAT={{user `github_api_pat`}}" - ] - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}", - "scripts": [ - "./scripts/build/Install-Toolset.ps1", - "./scripts/build/Configure-Toolset.ps1" - ] - }, - { - "type": "shell", - "execute_command": "ruby {{ .Path }}", - "scripts": [ - "./scripts/build/configure-xcode-simulators.rb" - ] - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}", - "script": "./scripts/build/Update-XcodeSimulators.ps1" - }, - { - "type": "shell", - "inline": [ - "pwsh -File \"$HOME/image-generation/software-report/Generate-SoftwareReport.ps1\" -OutputDirectory \"$HOME/image-generation/output/software-report\" -ImageName {{user `build_id`}}", - "pwsh -File \"$HOME/image-generation/tests/RunAll-Tests.ps1\"" - ] - }, - { - "type": "file", - "direction": "download", - "source": "~/image-generation/output/*", - "destination": "../image-output/" - }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", - "scripts": [ - "./scripts/build/configure-hostname.sh", - "./scripts/build/configure-system.sh" - ] - } - ] -} diff --git a/images/macos/templates/macOS-12.pkr.hcl b/images/macos/templates/macOS-12.pkr.hcl new file mode 100644 index 000000000000..8d27481be137 --- /dev/null +++ b/images/macos/templates/macOS-12.pkr.hcl @@ -0,0 +1,307 @@ +packer { + required_plugins { + vsphere = { + source = "github.com/hashicorp/vsphere" + version = "~> 1" + } + } +} + +variable "baseimage_name" { + type = string +} + +variable "build_id" { + type = string +} + +variable "cluster_or_esxi_host" { + type = string +} + +variable "esxi_datastore" { + type = string +} + +variable "github_api_pat" { + type = string + default = "" + sensitive = true +} + +variable "image_os" { + type = string + default = "macos12" +} + +variable "output_folder" { + type = string +} + +variable "vcenter_datacenter" { + type = string +} + +variable "vcenter_password" { + type = string + sensitive = true +} + +variable "vcenter_server" { + type = string +} + +variable "vcenter_username" { + type = string + sensitive = true +} + +variable "vm_password" { + type = string + sensitive = true +} + +variable "vm_username" { + type = string + sensitive = true +} + +variable "xcode_install_sas" { + type = string + sensitive = true +} + +variable "xcode_install_storage_url" { + type = string + sensitive = true +} + +source "vsphere-clone" "template" { + CPUs = "5" + NestedHV = "true" + RAM = "24576" + cpu_cores = "5" + datacenter = "${var.vcenter_datacenter}" + datastore = "${var.esxi_datastore}" + folder = "${var.output_folder}" + host = "${var.cluster_or_esxi_host}" + insecure_connection = true + password = "${var.vcenter_password}" + shutdown_timeout = "15m" + ssh_password = "${var.vm_password}" + ssh_username = "${var.vm_username}" + template = "${var.baseimage_name}" + username = "${var.vcenter_username}" + vcenter_server = "${var.vcenter_server}" + vm_name = "${var.build_id}" +} + +build { + sources = ["source.vsphere-clone.template"] + + provisioner "shell" { + inline = ["mkdir ~/image-generation"] + } + + provisioner "file" { + destination = "~/image-generation/" + sources = [ + "./assets/xamarin-selector", + "./scripts/tests", + "./scripts/docs-gen", + "./scripts/helpers" + ] + } + + provisioner "file" { + destination = "~/image-generation/docs-gen/" + source = "../../helpers/software-report-base" + } + + provisioner "file" { + destination = "~/image-generation/add-certificate.swift" + source = "./assets/add-certificate.swift" + } + + provisioner "file" { + destination = "~/.bashrc" + source = "./assets/bashrc" + } + + provisioner "file" { + destination = "~/.bash_profile" + source = "./assets/bashprofile" + } + + provisioner "shell" { + inline = [ "mkdir ~/bootstrap" ] + } + + provisioner "file" { + destination = "~/bootstrap" + source = "./assets/bootstrap-provisioner/" + } + + provisioner "file" { + destination = "~/image-generation/toolset.json" + source = "./toolsets/toolset-12.json" + } + + provisioner "shell" { + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + inline = [ + "mv ~/image-generation/docs-gen ~/image-generation/software-report", + "mv ~/image-generation/xamarin-selector ~/image-generation/assets", + "mkdir ~/utils", + "mv ~/image-generation/helpers/confirm-identified-developers.scpt ~/utils", + "mv ~/image-generation/helpers/invoke-tests.sh ~/utils", + "mv ~/image-generation/helpers/utils.sh ~/utils", + "mv ~/image-generation/helpers/xamarin-utils.sh ~/utils" + ] + } + + provisioner "shell" { + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}" + scripts = [ + "./scripts/build/install-xcode-clt.sh", + "./scripts/build/install-homebrew.sh" + ] + } + + provisioner "shell" { + environment_vars = ["PASSWORD=${var.vm_password}", "USERNAME=${var.vm_username}"] + execute_command = "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}" + scripts = [ + "./scripts/build/configure-network-interface-detection.sh", + "./scripts/build/configure-autologin.sh", + "./scripts/build/configure-auto-updates.sh", + "./scripts/build/configure-screensaver.sh", + "./scripts/build/configure-ntpconf.sh", + "./scripts/build/configure-max-files-limitation.sh", + "./scripts/build/configure-shell.sh" + ] + } + + provisioner "shell" { + environment_vars = ["IMAGE_VERSION=${var.build_id}", "IMAGE_OS=${var.image_os}", "PASSWORD=${var.vm_password}"] + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}" + scripts = [ + "./scripts/build/configure-preimagedata.sh", + "./scripts/build/configure-ssh.sh", + "./scripts/build/configure-machine.sh" + ] + } + + provisioner "shell" { + execute_command = "sudo {{ .Vars }} {{ .Path }}" + expect_disconnect = true + inline = ["echo 'Reboot VM'", "shutdown -r now"] + } + + provisioner "shell" { + environment_vars = ["API_PAT=${var.github_api_pat}", "USER_PASSWORD=${var.vm_password}"] + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}" + pause_before = "30s" + scripts = [ + "./scripts/build/configure-windows.sh", + "./scripts/build/install-powershell.sh", + "./scripts/build/install-dotnet.sh", + "./scripts/build/install-python.sh", + "./scripts/build/install-azcopy.sh", + "./scripts/build/install-openssl.sh", + "./scripts/build/install-ruby.sh", + "./scripts/build/install-rubygems.sh", + "./scripts/build/install-git.sh", + "./scripts/build/install-mongodb.sh", + "./scripts/build/install-node.sh", + "./scripts/build/install-common-utils.sh" + ] + } + + provisioner "shell" { + environment_vars = ["XCODE_INSTALL_STORAGE_URL=${var.xcode_install_storage_url}", "XCODE_INSTALL_SAS=${var.xcode_install_sas}"] + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}" + script = "./scripts/build/Install-Xcode.ps1" + } + + provisioner "shell" { + execute_command = "sudo {{ .Vars }} {{ .Path }}" + expect_disconnect = true + inline = ["echo 'Reboot VM'", "shutdown -r now"] + } + + provisioner "shell" { + environment_vars = ["API_PAT=${var.github_api_pat}"] + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}" + scripts = [ + "./scripts/build/install-actions-cache.sh", + "./scripts/build/install-llvm.sh", + "./scripts/build/install-golang.sh", + "./scripts/build/install-swiftlint.sh", + "./scripts/build/install-openjdk.sh", + "./scripts/build/install-php.sh", + "./scripts/build/install-aws-tools.sh", + "./scripts/build/install-rust.sh", + "./scripts/build/install-gcc.sh", + "./scripts/build/install-haskell.sh", + "./scripts/build/install-cocoapods.sh", + "./scripts/build/install-android-sdk.sh", + "./scripts/build/install-xamarin.sh", + "./scripts/build/install-visualstudio.sh", + "./scripts/build/install-nvm.sh", + "./scripts/build/install-apache.sh", + "./scripts/build/install-nginx.sh", + "./scripts/build/install-postgresql.sh", + "./scripts/build/install-audiodevice.sh", + "./scripts/build/install-vcpkg.sh", + "./scripts/build/install-miniconda.sh", + "./scripts/build/install-safari.sh", + "./scripts/build/install-chrome.sh", + "./scripts/build/install-edge.sh", + "./scripts/build/install-firefox.sh", + "./scripts/build/install-pypy.sh", + "./scripts/build/install-pipx-packages.sh", + "./scripts/build/install-bicep.sh", + "./scripts/build/install-codeql-bundle.sh" + ] + } + + provisioner "shell" { + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}" + scripts = [ + "./scripts/build/Install-Toolset.ps1", + "./scripts/build/Configure-Toolset.ps1" + ] + } + + provisioner "shell" { + execute_command = "ruby {{ .Path }}" + script = "./scripts/build/configure-xcode-simulators.rb" + } + + provisioner "shell" { + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}" + script = "./scripts/build/Update-XcodeSimulators.ps1" + } + + provisioner "shell" { + inline = [ + "pwsh -File \"$HOME/image-generation/software-report/Generate-SoftwareReport.ps1\" -OutputDirectory \"$HOME/image-generation/output/software-report\" -ImageName ${var.build_id}", + "pwsh -File \"$HOME/image-generation/tests/RunAll-Tests.ps1\"" + ] + } + + provisioner "file" { + destination = "../image-output/" + direction = "download" + source = "~/image-generation/output/*" + } + + provisioner "shell" { + execute_command = "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}" + scripts = [ + "./scripts/build/configure-hostname.sh", + "./scripts/build/configure-system.sh" + ] + } +}