diff --git a/answer_files/10_insider/Autounattend.xml b/answer_files/10_insider/Autounattend.xml index 302736fe8309b226aab417166d7f88e956da4199..05cca10ad38331f5efcefe962e28c595d406055e 100644 --- a/answer_files/10_insider/Autounattend.xml +++ b/answer_files/10_insider/Autounattend.xml @@ -40,9 +40,22 @@ OnError false + + + /IMAGE/NAME + Windows 10 Enterprise + + + + en-US + en-US + en-US + en-US + en-US + en-US diff --git a/answer_files/2016_insider/Autounattend.xml b/answer_files/2016_insider/Autounattend.xml index 1ed6cf169572b61fd27befe5d79fd5aa28900ddd..b2defe3e500b20146178b9558fba6b8c70c108c8 100644 --- a/answer_files/2016_insider/Autounattend.xml +++ b/answer_files/2016_insider/Autounattend.xml @@ -50,8 +50,8 @@ - /IMAGE/NAME - Windows Server 2016 SERVERDATACENTERCORE + /IMAGE/NAME + Windows Server 2016 SERVERDATACENTERACORE @@ -62,8 +62,11 @@ - - XXXXX-XXXXX-XXXXX-XXXXX-XXXXX + + B69WH-PRNHK-BXVK3-P9XF7-XD84W OnError true diff --git a/build_windows_10.sh b/build_windows_10.sh index 40ec06792b26ca647853f1b33353d6966028fced..887aae05bb6700c864948812d8fc28e2c1732bf4 100755 --- a/build_windows_10.sh +++ b/build_windows_10.sh @@ -4,12 +4,14 @@ # Windows 10 Pro own license #packer build --only=vmware-iso --var iso_url=~/packer_cache/my/Win10_1607_English_x64.iso --var iso_checksum=99fd8082a609997ae97a514dca22becf20420891 --var autounattend=./tmp/10_pro/Autounattend.xml windows_10.json -# Windows 10 Insider 15063 -#packer build --only=vmware-iso --var iso_url=~/packer_cache/connect/15063.0.170317-1834.RS2_RELEASE_CLIENTENTERPRISE_VOL_X64FRE_EN-US.ISO --var iso_checksum=77d5e7c91b5dbbee410fb6c57cb944238bf7176a windows_10_insider.json +# Windows 10 Insider 16232 +# packer build --only=vmware-iso --var iso_url=~/packer_cache/insider/Windows10_InsiderPreview_EnterpriseVL_x64_en-us_16232.iso --var iso_checksum=8e84a14b972a2d7643d347c57068b51e88e86ae5 windows_10_insider.json +# Windows 10 Insider 16241 +packer build --only=vmware-iso --var iso_url=~/packer_cache/connect/16241.1001.170708-1800.rs_prerelease_CLIENTENTERPRISE_VOL_X64FRE_en-US.iso --var iso_checksum=1ef19500cd45ba6bd013c4a0c3fd1633a2f830c6 windows_10_insider.json # Windows 10 Enterprise MSDN #packer build --only=vmware-iso --var iso_url=~/packer_cache/msdn/en_windows_10_enterprise_version_1607_updated_jan_2017_x64_dvd_9714415.iso --var iso_checksum=97164DD5C1C933BAEF89A4BDE93D544256134FE4 --var iso_checksum_type=sha1 --var autounattend=./tmp/10/Autounattend.xml windows_10.json -packer build --only=vmware-iso --var iso_url=~/packer_cache/msdn/en_windows_10_enterprise_version_1703_updated_march_2017_x64_dvd_10189290.iso --var iso_checksum=77D5E7C91B5DBBEE410FB6C57CB944238BF7176A --var iso_checksum_type=sha1 --var autounattend=./tmp/10/Autounattend.xml windows_10.json +# packer build --only=vmware-iso --var iso_url=~/packer_cache/msdn/en_windows_10_enterprise_version_1703_updated_march_2017_x64_dvd_10189290.iso --var iso_checksum=77D5E7C91B5DBBEE410FB6C57CB944238BF7176A --var iso_checksum_type=sha1 --var autounattend=./tmp/10/Autounattend.xml windows_10.json # Windows 10 Client 15031 #packer build --only=vmware-iso \ diff --git a/build_windows_2016_core.sh b/build_windows_2016_core.sh new file mode 100755 index 0000000000000000000000000000000000000000..e7642e7f794e96635acca051a0e4e4c00084bb80 --- /dev/null +++ b/build_windows_2016_core.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# packer build --only=vmware-iso --var iso_url=~/packer_cache/14393.0.160715-1616.RS1_RELEASE_SERVER_EVAL_X64FRE_EN-US.ISO windows_2016_docker.json + +# MSDN ISO +packer build --only=vmware-iso --var iso_url=~/packer_cache/msdn/en_windows_server_2016_x64_dvd_9718492.iso --var iso_checksum=F185197AF68FAE4F0E06510A4579FC511BA27616 --var iso_checksum_type=sha1 --var autounattend=./tmp/2016/Autounattend.xml windows_2016_core.json diff --git a/build_windows_2016_dc.sh b/build_windows_2016_dc.sh new file mode 100755 index 0000000000000000000000000000000000000000..147293396de3015184c6fca2625741d037696f94 --- /dev/null +++ b/build_windows_2016_dc.sh @@ -0,0 +1,3 @@ +#!/bin/bash +#packer build --only=vmware-iso --var iso_url=~/packer_cache/14393.0.160715-1616.RS1_RELEASE_SERVER_EVAL_X64FRE_EN-US.ISO windows_2016_docker.json +packer build --only=vmware-iso --var iso_url=~/packer_cache/en_windows_server_2016_x64_dvd_9327751.iso --var iso_checksum=91d7b2ebcff099b3557570af7a8a5cd6 --var autounattend=./tmp/2016_core/Autounattend.xml windows_2016_dc.json diff --git a/build_windows_2016_insider.sh b/build_windows_2016_insider.sh new file mode 100755 index 0000000000000000000000000000000000000000..340496ec75aca3109590825df9742810e6b164cd --- /dev/null +++ b/build_windows_2016_insider.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Microsoft Connect ISO +# packer build --only=vmware-iso --var iso_url=~/packer_cache/connect/16237.1001.170701-0549.rs_prerelease_SERVER_ACORE_VOL_X64FRE_en-US.iso --var iso_checksum=674e275b0191bc1588c6b123eda372dd6c2d6c1b01ef63a70e86be2cc009b256 --var iso_checksum_type=sha256 --var autounattend=./tmp/2016_connect/Autounattend.xml windows_2016_insider.json +packer build --only=vmware-iso --var iso_url=~/packer_cache/insider/Windows_InsiderPreview_Server_2_16237.iso windows_2016_insider.json diff --git a/hyperv/terraform/.gitignore b/hyperv/terraform/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..3093b1a31b0bfab93616c64a4a53131056e62166 --- /dev/null +++ b/hyperv/terraform/.gitignore @@ -0,0 +1 @@ +terraform.tf* diff --git a/hyperv/terraform/FirstLogonCommands.xml b/hyperv/terraform/FirstLogonCommands.xml new file mode 100644 index 0000000000000000000000000000000000000000..3a35a3fed3b73191bd1b5a36bd2caf00ab1c2476 --- /dev/null +++ b/hyperv/terraform/FirstLogonCommands.xml @@ -0,0 +1,12 @@ + + + cmd /c "copy C:\AzureData\CustomData.bin C:\provision.ps1"CopyScript + 11 + + + powershell.exe -sta -ExecutionPolicy Unrestricted -file C:\provision.ps1RunScript + 12 + + diff --git a/hyperv/terraform/README.md b/hyperv/terraform/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a0e7a0822ec3c5b70d80d4180bcfeec0b6c29b68 --- /dev/null +++ b/hyperv/terraform/README.md @@ -0,0 +1,82 @@ +# Packer builder in Azure + +This is a Terraform template to spin up a VM in Azure that has nested HyperV +activated and tools like Packer, Vagrant and Docker CLI installed. + +Now you are able to build Vagrant base boxes for HyperV in the Cloud with Packer. + +## Stage 1: Spin up the Azure VM with Terraform + +### Install Terraform + +``` +brew install terraform +``` + +### Secrets + +Get your Azure ID's and secret with `pass` + +``` +eval $(pass azure-terraform) +``` + +You will need these environment variables for terraform + +``` +export ARM_SUBSCRIPTION_ID="uuid" +export ARM_CLIENT_ID="uuid" +export ARM_CLIENT_SECRET="secret" +export ARM_TENANT_ID="uuid" +``` + +### Configure + +Adjust the file `variables.tf` to your needs to choose + +- location / region +- DNS prefix and suffix +- size of the VM's, default is `Standard_D2_v3` which is needed for nested virtualization +- username and password + +### Plan + +```bash +terraform plan +``` + +### Create / Apply + +Create the Azure VM with. After 5 minutes the VM should be up and running, and the provision.ps1 script will run inside the VM to install Packer, Vagrant, HyperV and then reboots the VM. + +```bash +terraform apply +``` + +## Stage 2: Packer build + +Now RDP into the Azure VM. Open a PowerShell terminal and clone my packer-windows repo or any other repo with a Packer template for HyperV. + +``` +git clone https://github.com/StefanScherer/packer-windows +mkdir D:\packer_cache +$env:PACKER_CACHE="D:\packer_cache" +cd packer-windows +packer build --only=hyperv-iso --var hyperv_switchname=ext windows_2016_docker.json +``` + +Packer creates an external Hyper-V virtual switch with name "ext". It downloads the eval ISO file and boots a Hyper-V VM to run the whole packer build configuration. + +You could also try to run it in this Azure VM with + +``` +vagrant box add windows_2016_docker windows_2016_docker_hyperv.box +cd .. +git clone https://github.com/StefanScherer/docker-windows-box +cd docker-windows-box +vagrant up +``` + +### packer push + +Now you can push the Vagrant box to Vagrant Cloud (https://app.vagrantup.com). diff --git a/hyperv/terraform/init.tf b/hyperv/terraform/init.tf new file mode 100644 index 0000000000000000000000000000000000000000..809b7f96df029adf6e1e39ac53694011b1ad18e4 --- /dev/null +++ b/hyperv/terraform/init.tf @@ -0,0 +1,16 @@ +# Configure the Microsoft Azure Provider +provider "azurerm" {} + +# Create a resource group +resource "azurerm_resource_group" "global" { + location = "${var.location}" + name = "${var.account}" +} + +# Create a storage account +resource "azurerm_storage_account" "global" { + account_type = "Standard_LRS" # Only locally redundant + location = "${var.location}" + name = "${var.account}" + resource_group_name = "${azurerm_resource_group.global.name}" +} diff --git a/hyperv/terraform/provision.ps1 b/hyperv/terraform/provision.ps1 new file mode 100644 index 0000000000000000000000000000000000000000..c0dd8f98a1415d2513dbd79ad740bc273ef7918f --- /dev/null +++ b/hyperv/terraform/provision.ps1 @@ -0,0 +1,58 @@ +Start-Transcript -Path C:\provision.log + +function Get-HostToIP($hostname) { + $result = [system.Net.Dns]::GetHostByName($hostname) + $result.AddressList | ForEach-Object {$_.IPAddressToString } +} + +Write-Host "provision.ps1" +Write-Host "HostName = $($HostName)" + +Write-Host Windows Updates to manual +Cscript $env:WinDir\System32\SCregEdit.wsf /AU 1 +Net stop wuauserv +Net start wuauserv + +Write-Host Disable Windows Defender +Set-MpPreference -DisableRealtimeMonitoring $true + +Write-Host Do not open Server Manager at logon +New-ItemProperty -Path HKCU:\Software\Microsoft\ServerManager -Name DoNotOpenServerManagerAtLogon -PropertyType DWORD -Value "1" -Force + +Write-Host Install Chocolatey +iex (wget 'https://chocolatey.org/install.ps1' -UseBasicParsing) + +Write-Host Install editors +choco install -y atom + +Write-Host Install Git +choco install -y git + +Write-Host Install Packer +choco install -y packer + +Write-Host Install Vagrant +choco install -y vagrant + +Write-Host Install Docker +choco install -y docker + +Write-Host Install HyperV +Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart +Install-WindowsFeature Hyper-V-Tools +Install-WindowsFeature Hyper-V-PowerShell + +Write-Host Disable autologon +New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoAdminLogon -PropertyType DWORD -Value "0" -Force + +Write-Host Install all Windows Updates +Get-Content C:\windows\system32\en-us\WUA_SearchDownloadInstall.vbs | ForEach-Object { + $_ -replace 'confirm = msgbox.*$', 'confirm = vbNo' +} | Out-File $env:TEMP\WUA_SearchDownloadInstall.vbs +"a`na" | cscript $env:TEMP\WUA_SearchDownloadInstall.vbs + +Write-Host Cleaning up +Remove-Item C:\provision.ps1 + +Write-Host Restarting computer +Restart-Computer diff --git a/hyperv/terraform/variables.tf b/hyperv/terraform/variables.tf new file mode 100644 index 0000000000000000000000000000000000000000..e166275a2f1dad5239b85379095c0e6535a4e51d --- /dev/null +++ b/hyperv/terraform/variables.tf @@ -0,0 +1,39 @@ +# Settings + +variable "account" { + default = "pckr" +} + +variable "dns_prefix" { + default = "pckr" +} + +variable "location" { + // default = "northeurope" + default = "westeurope" +} + +variable "azure_dns_suffix" { + description = "Azure DNS suffix for the Public IP" + default = "cloudapp.azure.com" +} + +variable "admin_username" { + default = "vagrant" +} + +variable "admin_password" { + default = "Password1234!" +} + +variable "count" { + type = "map" + + default = { + windows = "1" + } +} + +variable "vm_size" { + default = "Standard_D2_v3" +} diff --git a/hyperv/terraform/windows.tf b/hyperv/terraform/windows.tf new file mode 100644 index 0000000000000000000000000000000000000000..77737bcb6a3f34f4d49e184d13943a78b2019c6d --- /dev/null +++ b/hyperv/terraform/windows.tf @@ -0,0 +1,97 @@ + +resource "azurerm_virtual_network" "windows" { + name = "windows-virtnet" + address_space = ["10.0.0.0/16"] + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.global.name}" +} + +resource "azurerm_subnet" "windows" { + name = "windows-${format("%02d", count.index + 1)}-sn" + resource_group_name = "${azurerm_resource_group.global.name}" + virtual_network_name = "${azurerm_virtual_network.windows.name}" + address_prefix = "10.0.2.0/24" +} + +resource "azurerm_network_interface" "windows" { + count = "${var.count["windows"]}" + name = "windows-${format("%02d", count.index + 1)}-nic" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.global.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.windows.id}" + public_ip_address_id = "${element(azurerm_public_ip.windows.*.id, count.index)}" + private_ip_address_allocation = "dynamic" + } +} + +resource "azurerm_public_ip" "windows" { + count = "${var.count["windows"]}" + domain_name_label = "${var.dns_prefix}-win-${format("%02d", count.index + 1)}" + idle_timeout_in_minutes = 30 + location = "${var.location}" + name = "windows-${format("%02d", count.index + 1)}-publicip" + public_ip_address_allocation = "dynamic" + resource_group_name = "${azurerm_resource_group.global.name}" +} + +resource "azurerm_storage_container" "windows" { + container_access_type = "private" + count = "${var.count["windows"]}" + name = "windows-${format("%02d", count.index + 1)}-storage" + resource_group_name = "${azurerm_resource_group.global.name}" + storage_account_name = "${azurerm_storage_account.global.name}" +} + +resource "azurerm_virtual_machine" "windows" { + count = "${var.count["windows"]}" + name = "windows-${format("%02d", count.index + 1)}-vm" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.global.name}" + network_interface_ids = ["${element(azurerm_network_interface.windows.*.id, count.index)}"] + vm_size = "${var.vm_size}" + + storage_image_reference { + publisher = "MicrosoftWindowsServer" + offer = "WindowsServer" + sku = "2016-Datacenter-with-Containers" + version = "latest" + } + + storage_os_disk { + name = "windows-${format("%02d", count.index + 1)}-osdisk" + vhd_uri = "${azurerm_storage_account.global.primary_blob_endpoint}${element(azurerm_storage_container.windows.*.id, count.index)}/disk1.vhd" + caching = "ReadWrite" + create_option = "FromImage" + } + + os_profile { + computer_name = "${var.dns_prefix}-win-${format("%02d", count.index + 1)}" + admin_username = "${var.admin_username}" + admin_password = "${var.admin_password}" + custom_data = "${base64encode("Param($HostName = \"${var.dns_prefix}-win-${format("%02d", count.index + 1)}.${var.location}.${var.azure_dns_suffix}\") ${file("./provision.ps1")}")}" + } + + os_profile_windows_config { + provision_vm_agent = true + enable_automatic_upgrades = true + additional_unattend_config { + pass = "oobeSystem" + component = "Microsoft-Windows-Shell-Setup" + setting_name = "AutoLogon" + content = "${var.admin_password}true1${var.admin_username}" + } + additional_unattend_config { + pass = "oobeSystem" + component = "Microsoft-Windows-Shell-Setup" + setting_name = "FirstLogonCommands" + content = "${file("./FirstLogonCommands.xml")}" + } + } + + tags { + environment = "staging" + } +} diff --git a/scripts/docker/2016/install-docker.ps1 b/scripts/docker/2016/install-docker.ps1 index 932db67ed04c44590bd3aec8a8b89a8a4be31d60..3d2d77f42d9e1a1ed14eb9df463900b0bff0b55c 100644 --- a/scripts/docker/2016/install-docker.ps1 +++ b/scripts/docker/2016/install-docker.ps1 @@ -1,12 +1,9 @@ -$ProgressPreference = 'SilentlyContinue' - -Set-ExecutionPolicy Bypass -scope Process -New-Item -Type Directory -Path "$($env:ProgramFiles)\docker" -wget -outfile $env:TEMP\docker-17-03-1-ee.zip "https://dockermsft.blob.core.windows.net/dockercontainer/docker-17-03-1-ee.zip" -Expand-Archive -Path $env:TEMP\docker-17-03-1-ee.zip -DestinationPath $env:TEMP -Force -copy $env:TEMP\docker\*.exe $env:ProgramFiles\docker -Remove-Item $env:TEMP\docker-17-03-1-ee.zip -[Environment]::SetEnvironmentVariable("Path", $env:Path + ";$($env:ProgramFiles)\docker", [EnvironmentVariableTarget]::Machine) -$env:Path = $env:Path + ";$($env:ProgramFiles)\docker" -. dockerd --register-service -H npipe:// -H 0.0.0.0:2375 -G docker +Write-Host "Install-PackageProvider ..." +Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force +Write-Host "Install-Module ..." +Install-Module -Name DockerMsftProviderInsider -Force +Write-Host "Install-Package ..." +Set-PSRepository -InstallationPolicy Trusted -Name PSGallery +Install-Package -Name docker -ProviderName DockerMsftProviderInsider -Force -RequiredVersion 17.06.0-ce +Set-PSRepository -InstallationPolicy Untrusted -Name PSGallery Start-Service docker diff --git a/windows_10_insider.json b/windows_10_insider.json index 1711092079ae6a7f68073e05684f3669a9b427d6..5d7834dc2e67a85cca72b9c24a95d737c032461b 100644 --- a/windows_10_insider.json +++ b/windows_10_insider.json @@ -130,9 +130,9 @@ ], "variables": { "manually_download_iso_from": "https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewadvanced", - "iso_url": "https://software-download.microsoft.com/pr/Windows10_InsiderPreview_EnterpriseVL_x64_en-us_15042.iso", + "iso_url": "https://software-download.microsoft.com/pr/Windows10_InsiderPreview_EnterpriseVL_x64_en-us_16232.iso", "iso_checksum_type": "sha1", - "iso_checksum": "e7b84c020fb9cbe34c50b18b9d4ce6bffe973387", + "iso_checksum": "8e84a14b972a2d7643d347c57068b51e88e86ae5", "autounattend": "./answer_files/10_insider/Autounattend.xml", "disk_size": "61440" } diff --git a/windows_2016_insider.json b/windows_2016_insider.json index 9afd8b319efe5489693d5a49d93cffbba013cf87..92ab9eb8653da5875f78a7033ebd0a8b3132b69d 100644 --- a/windows_2016_insider.json +++ b/windows_2016_insider.json @@ -114,7 +114,7 @@ "type": "powershell", "scripts": [ "./scripts/docker/add-docker-group.ps1", - "./scripts/docker/10/install-docker.ps1", + "./scripts/docker/2016/install-docker.ps1", "./scripts/docker/docker-pull-insider-async.ps1", "./scripts/docker/open-docker-insecure-port.ps1", "./scripts/docker/remove-docker-key-json.ps1", @@ -141,9 +141,9 @@ } ], "variables": { - "iso_url": "http://care.dlservice.microsoft.com/dl/download/1/4/9/149D5452-9B29-4274-B6B3-5361DBDA30BC/14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64FRE_EN-US.ISO", - "iso_checksum_type": "md5", - "iso_checksum": "70721288BBCDFE3239D8F8C0FAE55F1F", + "iso_url": "https://software-download.microsoft.com/pr/Windows_InsiderPreview_Server_2_16237.iso", + "iso_checksum_type": "sha256", + "iso_checksum": "3d7f496892424926ad6b50f6acda74cf4f9f5d509ffd378767a3950932dbfce0", "autounattend": "./answer_files/2016_insider/Autounattend.xml" } }