Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(windows) add AWS EC2 builds (2019 and 2022) jenkins-infra#1611
Browse files Browse the repository at this point in the history
Note: partial revert of jenkins-infra#734

Signed-off-by: Damien Duportal <damien.duportal@gmail.com>
dduportal committed Dec 18, 2024
1 parent 6430da8 commit 81582e7
Showing 5 changed files with 29 additions and 37 deletions.
32 changes: 1 addition & 31 deletions Jenkinsfile_k8s
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ pipeline {
}
}
excludes {
// Only build Ubuntu images for arm64 CPU in AWS (notValues)
// Only build arm64 VMs when OS is Ubuntu (notValues) as Windows Server amr64 does not exist anywhere
exclude {
axis {
name 'cpu_architecture'
@@ -105,36 +105,6 @@ pipeline {
name 'agent_type'
notValues 'ubuntu-22.04'
}
axis {
name 'compute_type'
values 'amazon-ebs'
}
}
// Exclude 'amazon-ebs' Windows builds while testing for Linux AMI
exclude {
axis {
name 'agent_type'
values 'windows-2019', 'windows-2022'
}
axis {
name 'compute_type'
values 'amazon-ebs'
}
}
// Only build Ubuntu images for arm64 CPU in Azure (notValues)
exclude {
axis {
name 'cpu_architecture'
values 'arm64'
}
axis {
name 'agent_type'
notValues 'ubuntu-22.04'
}
axis {
name 'compute_type'
values 'azure-arm'
}
}
// No build on Windows or Docker, not yet implemented
exclude {
4 changes: 1 addition & 3 deletions build-jenkins-agent-ubuntu.pkr.hcl
Original file line number Diff line number Diff line change
@@ -6,8 +6,6 @@ build {
source "amazon-ebs.base" {
name = "ubuntu"
ssh_username = "ubuntu"
# Egg-and-chicken: what is the base image to start from (eg. what is my egg)?
source_ami = try(local.images_versions["aws"]["ubuntu"][var.agent_os_version][var.architecture], "N/A")
}

source "azure-arm.base" {
@@ -17,7 +15,7 @@ build {
image_publisher = "canonical"
# List available SKUs with the command `az vm image list-skus --offer 0001-com-ubuntu-server-jammy --location eastus --publisher canonical --output table`
image_sku = local.az_instance_image_sku[var.architecture]
image_version = try(local.images_versions["azure"]["ubuntu"][var.agent_os_version][var.architecture], "N/A")
image_version = try(local.images_versions["azure"][var.agent_os_type][var.agent_os_version][var.architecture], "N/A")
os_type = "Linux"
}

22 changes: 22 additions & 0 deletions build-jenkins-agent-windows.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
build {
source "amazon-ebs.base" {
name = "windows"
communicator = "winrm"
user_data_file = "./provisioning/setupWinRM.ps1"
winrm_insecure = true
winrm_timeout = "20m"
winrm_use_ssl = true
winrm_username = local.windows_winrm_user[var.image_type]
}

source "azure-arm.base" {
name = "windows"
communicator = "winrm"
@@ -131,4 +141,16 @@ build {
"while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10 } else { break } }"
]
}

# This provisioner must be the last for AWS EBS builds, after reboots
provisioner "powershell" {
only = ["amazon-ebs.windows"]
elevated_user = local.windows_winrm_user[var.image_type]
elevated_password = build.Password

inline = [
"& 'C:/Program Files/Amazon/EC2Launch/ec2launch' reset --block",
"& 'C:/Program Files/Amazon/EC2Launch/ec2launch' sysprep --block",
]
}
}
3 changes: 1 addition & 2 deletions locals.pkr.hcl
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ locals {
image_name = format("jenkins-agent-%s-%s-%s", var.agent_os_type, var.agent_os_version, var.architecture)
unique_image_name = format("%s-%s", local.image_name, local.now_unix_timestamp)


aws_instance_types = {
"amd64" = "t3.xlarge"
"arm64" = "t4g.xlarge"
@@ -19,7 +18,7 @@ locals {
windows_winrm_user = {
"azure-arm" = "packer"
"docker" = "packer"
"amazon-ebs" = "Administrator"
"amazon-ebs" = "Administrator" # In AWS EC2, WinRM super admin must be the "Administrator" account
}

images_versions = yamldecode(file("./images-versions.yaml"))
5 changes: 4 additions & 1 deletion sources.pkr.hcl
Original file line number Diff line number Diff line change
@@ -3,6 +3,10 @@ source "amazon-ebs" "base" {
ami_name = "${local.image_name}-${var.architecture}-${local.now_unix_timestamp}"
instance_type = local.aws_instance_types[var.architecture]

# Egg-and-chicken: what is the base image to start from (eg. what is my egg)?
# Note: tracked by updatecli
source_ami = try(local.images_versions["aws"][var.agent_os_type][var.agent_os_version][var.architecture], "N/A")

# Define custom rootfs for build to avoid later filesystem extension during agent startups
launch_block_device_mappings {
delete_on_termination = true
@@ -17,7 +21,6 @@ source "amazon-ebs" "base" {
var.aws_destination_region
]


# To improve audit and garbage collecting, we provide tags
tags = {
Name = "${local.image_name}-Packer-${var.architecture}"

0 comments on commit 81582e7

Please sign in to comment.