Skip to content

Commit

Permalink
feat: add Windows Server 2022
Browse files Browse the repository at this point in the history
Signed-off-by: Damien Duportal <[email protected]>
  • Loading branch information
dduportal committed May 14, 2022
1 parent a36924a commit dc3e078
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
12 changes: 11 additions & 1 deletion Jenkinsfile_k8s
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pipeline {
}
axis {
name 'agent_type'
values 'ubuntu-20.04', 'windows-2019'
values 'ubuntu-20.04', 'windows-2019', 'windows-2022'
}
axis {
name 'compute_type'
Expand Down Expand Up @@ -133,6 +133,16 @@ pipeline {
values 'docker'
}
}
exclude {
axis {
name 'PKR_VAR_agent'
values 'windows-2022'
}
axis {
name 'PKR_VAR_image_type'
values 'docker'
}
}
}
agent {
label "linux-${env.cpu_architecture}-docker"
Expand Down
2 changes: 1 addition & 1 deletion build-jenkins-agent-ubuntu.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build {
name = "ubuntu"
image_offer = "0001-com-ubuntu-server-focal"
image_publisher = "canonical"
image_sku = "${local.agent_os_version_safe}-lts-gen2"
image_sku = local.azure_sku[local.agent]
os_type = "Linux"
vm_size = local.azure_vm_size
}
Expand Down
6 changes: 2 additions & 4 deletions build-jenkins-agent-windows.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ build {
communicator = "winrm"
image_offer = "WindowsServer"
image_publisher = "MicrosoftWindowsServer"
image_sku = "${var.agent_os_version}-datacenter-core-with-containers-smalldisk-g2"
image_sku = local.azure_sku[local.agent]
vm_size = local.azure_vm_size
os_type = "Windows"
os_disk_size_gb = local.windows_disk_size_gb
Expand Down Expand Up @@ -68,9 +68,7 @@ build {
elevated_password = build.Password
# Ref. https:#docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-user-data.html#user-data-scripts-subsequent
inline = [
"C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\SendWindowsIsReady.ps1 -Schedule",
"C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\InitializeInstance.ps1 -Schedule",
"C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\SysprepInstance.ps1 -NoShutdown"
"if($env:AGENT_OS_VERSION = '2019') { C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\SendWindowsIsReady.ps1 -Schedule; C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\InitializeInstance.ps1 -Schedule; C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\SysprepInstance.ps1 -NoShutdown;};"
]
}
}
11 changes: 11 additions & 0 deletions datasources.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ data "amazon-ami" "windows-2019" {
owners = ["amazon"]
region = var.aws_region
}

data "amazon-ami" "windows-2022" {
filters = {
name = "Windows_Server-2022-English-Core-ContainersLatest-*"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["amazon"]
region = var.aws_region
}
6 changes: 6 additions & 0 deletions locals.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ locals {
"amazon-ebs" = "Administrator" # In AWS EC2, WinRM super admin must be the "Administrator" account
"docker" = "packer"
}
## List available offers with the command `az vm image list-skus --offer <> --location eastus --publisher <> --output table`
azure_sku = {
"windows-2019" = "2019-datacenter-core-with-containers-smalldisk-g2"
"windows-2022" = "2022-datacenter-core-smalldisk-g2"
"ubuntu-20.04" = "20_04-lts-gen2"
}
azure_vm_size = "Standard_D4s_v3" # 4 CPU / 16 GB / Huge size required to avoid https:#docs.microsoft.com/en-us/azure/virtual-machines/linux/image-builder-troubleshoot#sysprep-timing and avoid full disk (DS2v2 only have 14 Gb SSD for system)
azure_resource_group = "${var.build_type}-packer-images"
azure_galleries = {
Expand Down
10 changes: 10 additions & 0 deletions provisioning/windows-provision.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ Set-Service -Name sshd -StartupType 'Automatic'
Start-Service sshd
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 | Out-Null

# Install Docker Engine if absent
docker -v ## client version only
if(! ($?)) {
Install-PackageProvider -Name NuGet -Force
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Install-Package -Name docker -ProviderName DockerMsftProvider
## A reboot is required to use start containers: only check the client
docker -v ## client version only
}

## Prepare Tools Installation
$baseDir = 'C:\tools'
New-Item -ItemType Directory -Path $baseDir -Force | Out-Null
Expand Down

0 comments on commit dc3e078

Please sign in to comment.