Commit dadf3609 authored by Patrick Lang's avatar Patrick Lang
Browse files
parents 039c205d 3d944253
......@@ -40,9 +40,22 @@
</InstallTo>
<WillShowUI>OnError</WillShowUI>
<InstallToAvailablePartition>false</InstallToAvailablePartition>
<InstallFrom>
<MetaData wcm:action="add">
<Key>/IMAGE/NAME</Key>
<Value>Windows 10 Enterprise</Value>
</MetaData>
</InstallFrom>
</OSImage>
</ImageInstall>
</component>
<component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<InputLocale>en-US</InputLocale>
<SystemLocale>en-US</SystemLocale>
<UILanguage>en-US</UILanguage>
<UILanguageFallback>en-US</UILanguageFallback>
<UserLocale>en-US</UserLocale>
</component>
<component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<SetupUILanguage>
<UILanguage>en-US</UILanguage>
......
......@@ -50,8 +50,8 @@
<OSImage>
<InstallFrom>
<MetaData wcm:action="add">
<Key>/IMAGE/NAME </Key>
<Value>Windows Server 2016 SERVERDATACENTERCORE</Value>
<Key>/IMAGE/NAME</Key>
<Value>Windows Server 2016 SERVERDATACENTERACORE</Value>
</MetaData>
</InstallFrom>
<InstallTo>
......@@ -62,8 +62,11 @@
</ImageInstall>
<UserData>
<ProductKey>
<!-- Windows Server Insider product key -->
<Key>XXXXX-XXXXX-XXXXX-XXXXX-XXXXX</Key>
<!--
Windows Server Insider product key
See https://blogs.windows.com/windowsexperience/2017/07/13/announcing-windows-server-insider-preview-build-16237/
-->
<Key>B69WH-PRNHK-BXVK3-P9XF7-XD84W</Key>
<WillShowUI>OnError</WillShowUI>
</ProductKey>
<AcceptEula>true</AcceptEula>
......
......@@ -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 \
......
#!/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
#!/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
#!/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
<FirstLogonCommands>
<SynchronousCommand>
<CommandLine>cmd /c "copy C:\AzureData\CustomData.bin C:\provision.ps1"</CommandLine
><Description>CopyScript</Description>
<Order>11</Order>
</SynchronousCommand>
<SynchronousCommand>
<CommandLine>powershell.exe -sta -ExecutionPolicy Unrestricted -file C:\provision.ps1</CommandLine
><Description>RunScript</Description>
<Order>12</Order>
</SynchronousCommand>
</FirstLogonCommands>
# 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).
# 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}"
}
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
# 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"
}
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 = "<AutoLogon><Password><Value>${var.admin_password}</Value></Password><Enabled>true</Enabled><LogonCount>1</LogonCount><Username>${var.admin_username}</Username></AutoLogon>"
}
additional_unattend_config {
pass = "oobeSystem"
component = "Microsoft-Windows-Shell-Setup"
setting_name = "FirstLogonCommands"
content = "${file("./FirstLogonCommands.xml")}"
}
}
tags {
environment = "staging"
}
}
$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
......@@ -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"
}
......
......@@ -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"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment