diff --git a/images/ubuntu/templates/ubuntu-24.04-bp.pkr.hcl b/images/ubuntu/templates/ubuntu-24.04-bp.pkr.hcl new file mode 100644 index 000000000000..abba9987c196 --- /dev/null +++ b/images/ubuntu/templates/ubuntu-24.04-bp.pkr.hcl @@ -0,0 +1,276 @@ +variable "dockerhub_login" { + type = string + default = "${env("DOCKERHUB_LOGIN")}" +} + +variable "dockerhub_password" { + type = string + default = "${env("DOCKERHUB_PASSWORD")}" +} + +variable "helper_script_folder" { + type = string + default = "/imagegeneration/helpers" +} + +variable "image_folder" { + type = string + default = "/imagegeneration" +} + +variable "image_os" { + type = string + default = "ubuntu24" +} + +variable "image_version" { + type = string + default = "dev" +} + +variable "imagedata_file" { + type = string + default = "/imagegeneration/imagedata.json" +} + +variable "installer_script_folder" { + type = string + default = "/imagegeneration/installers" +} + +variable "run_validation_diskspace" { + type = bool + default = false +} + +variable "instance_type" { + type = string + default = "m5.xlarge" +} + +variable "subnet_id" { + type = string + default = "subnet-0a0404228e23402fe" +} + +variable "vpc_id" { + type = string + default = "vpc-0327443f8fc269ed4" +} + +locals { timestamp = regex_replace(timestamp(), "[-TZ:]", "") } + +source "amazon-ebs" "build_ami" { + ami_name = "bold-penguin-noble-gh-runner-${local.timestamp}" + # ami_users = "${var.aws_accounts}" + encrypt_boot = "false" + instance_type = "${var.instance_type}" + launch_block_device_mappings { + delete_on_termination = true + device_name = "/dev/sda1" + volume_size = 86 + volume_type = "gp2" + } + profile = "dev" + region = "us-east-1" + # snapshot_users = "${var.aws_accounts}" + source_ami_filter { + filters = { + name = "ubuntu/images/hvm-ssd/ubuntu-noble-24.04-amd64-server-*" + root-device-type = "ebs" + virtualization-type = "hvm" + } + most_recent = true + owners = ["099720109477"] + } + ssh_timeout = "10m" + ssh_username = "ubuntu" + subnet_id = "${var.subnet_id}" + temporary_key_pair_type = "ed25519" + vpc_id = "${var.vpc_id}" +} + +build { + sources = ["source.amazon-ebs.build_ami"] + + provisioner "shell" { + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + inline = ["mkdir ${var.image_folder}", "chmod 777 ${var.image_folder}"] + } + + provisioner "file" { + destination = "${var.helper_script_folder}" + source = "${path.root}/../scripts/helpers" + } + + provisioner "shell" { + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + script = "${path.root}/../scripts/build/configure-apt-mock.sh" + } + + provisioner "shell" { + environment_vars = ["HELPER_SCRIPTS=${var.helper_script_folder}","DEBIAN_FRONTEND=noninteractive"] + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + scripts = [ + "${path.root}/../scripts/build/install-ms-repos.sh", + "${path.root}/../scripts/build/configure-apt-sources.sh", + "${path.root}/../scripts/build/configure-apt.sh" + ] + } + + provisioner "shell" { + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + script = "${path.root}/../scripts/build/configure-limits.sh" + } + + provisioner "file" { + destination = "${var.installer_script_folder}" + source = "${path.root}/../scripts/build" + } + + provisioner "file" { + destination = "${var.image_folder}" + sources = [ + "${path.root}/../assets/post-gen", + "${path.root}/../scripts/tests", + "${path.root}/../scripts/docs-gen" + ] + } + + provisioner "file" { + destination = "${var.image_folder}/docs-gen/" + source = "${path.root}/../../../helpers/software-report-base" + } + + provisioner "file" { + destination = "${var.installer_script_folder}/toolset.json" + source = "${path.root}/../toolsets/toolset-2404.json" + } + + provisioner "shell" { + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + inline = [ + "mv ${var.image_folder}/docs-gen ${var.image_folder}/SoftwareReport", + "mv ${var.image_folder}/post-gen ${var.image_folder}/post-generation" + ] + } + + provisioner "shell" { + environment_vars = ["IMAGE_VERSION=${var.image_version}", "IMAGEDATA_FILE=${var.imagedata_file}"] + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + scripts = ["${path.root}/../scripts/build/configure-image-data.sh"] + } + + provisioner "shell" { + environment_vars = ["IMAGE_VERSION=${var.image_version}", "IMAGE_OS=${var.image_os}", "HELPER_SCRIPTS=${var.helper_script_folder}"] + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + scripts = ["${path.root}/../scripts/build/configure-environment.sh"] + } + + provisioner "shell" { + environment_vars = ["DEBIAN_FRONTEND=noninteractive", "HELPER_SCRIPTS=${var.helper_script_folder}", "INSTALLER_SCRIPT_FOLDER=${var.installer_script_folder}"] + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + scripts = ["${path.root}/../scripts/build/install-apt-vital.sh"] + } + +provisioner "shell" { + environment_vars = ["HELPER_SCRIPTS=${var.helper_script_folder}", "INSTALLER_SCRIPT_FOLDER=${var.installer_script_folder}"] + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + scripts = ["${path.root}/../scripts/build/install-powershell.sh"] + } + + provisioner "shell" { + environment_vars = ["HELPER_SCRIPTS=${var.helper_script_folder}", "INSTALLER_SCRIPT_FOLDER=${var.installer_script_folder}"] + execute_command = "sudo sh -c '{{ .Vars }} pwsh -f {{ .Path }}'" + scripts = ["${path.root}/../scripts/build/Install-PowerShellModules.ps1"] + } + + provisioner "shell" { + environment_vars = ["HELPER_SCRIPTS=${var.helper_script_folder}", "INSTALLER_SCRIPT_FOLDER=${var.installer_script_folder}", "DEBIAN_FRONTEND=noninteractive"] + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + scripts = [ + "${path.root}/../scripts/build/install-actions-cache.sh", + "${path.root}/../scripts/build/install-runner-package.sh", + "${path.root}/../scripts/build/install-apt-common.sh", + "${path.root}/../scripts/build/install-apache.sh", + "${path.root}/../scripts/build/install-aws-tools.sh", + "${path.root}/../scripts/build/install-clang.sh", + "${path.root}/../scripts/build/install-cmake.sh", + "${path.root}/../scripts/build/install-codeql-bundle.sh", + "${path.root}/../scripts/build/install-container-tools.sh", + "${path.root}/../scripts/build/install-dotnetcore-sdk.sh", + "${path.root}/../scripts/build/install-microsoft-edge.sh", + "${path.root}/../scripts/build/install-gcc-compilers.sh", + "${path.root}/../scripts/build/install-firefox.sh", + "${path.root}/../scripts/build/install-gfortran.sh", + "${path.root}/../scripts/build/install-git.sh", + "${path.root}/../scripts/build/install-git-lfs.sh", + "${path.root}/../scripts/build/install-github-cli.sh", + "${path.root}/../scripts/build/install-google-chrome.sh", + "${path.root}/../scripts/build/install-java-tools.sh", + "${path.root}/../scripts/build/install-kubernetes-tools.sh", + "${path.root}/../scripts/build/install-mysql.sh", + "${path.root}/../scripts/build/install-nginx.sh", + "${path.root}/../scripts/build/install-nvm.sh", + "${path.root}/../scripts/build/install-nodejs.sh", + "${path.root}/../scripts/build/install-postgresql.sh", + "${path.root}/../scripts/build/install-ruby.sh", + "${path.root}/../scripts/build/install-rust.sh", + "${path.root}/../scripts/build/install-selenium.sh", + "${path.root}/../scripts/build/install-packer.sh", + "${path.root}/../scripts/build/configure-dpkg.sh", + "${path.root}/../scripts/build/install-yq.sh", + "${path.root}/../scripts/build/install-pypy.sh", + "${path.root}/../scripts/build/install-python.sh", + ] + } + + provisioner "shell" { + environment_vars = ["HELPER_SCRIPTS=${var.helper_script_folder}", "INSTALLER_SCRIPT_FOLDER=${var.installer_script_folder}", "DOCKERHUB_PULL_IMAGES=NO"] + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + scripts = ["${path.root}/../scripts/build/install-docker.sh"] + } + + provisioner "shell" { + environment_vars = ["HELPER_SCRIPTS=${var.helper_script_folder}", "INSTALLER_SCRIPT_FOLDER=${var.installer_script_folder}"] + execute_command = "sudo sh -c '{{ .Vars }} pwsh -f {{ .Path }}'" + scripts = ["${path.root}/../scripts/build/Install-Toolset.ps1", "${path.root}/../scripts/build/Configure-Toolset.ps1"] + } + + provisioner "shell" { + environment_vars = ["HELPER_SCRIPTS=${var.helper_script_folder}", "INSTALLER_SCRIPT_FOLDER=${var.installer_script_folder}"] + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + scripts = ["${path.root}/../scripts/build/install-pipx-packages.sh"] + } + + provisioner "shell" { + environment_vars = ["HELPER_SCRIPTS=${var.helper_script_folder}"] + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + scripts = ["${path.root}/../scripts/build/configure-snap.sh"] + } + + provisioner "shell" { + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + expect_disconnect = true + inline = ["echo 'Reboot VM'", "sudo reboot"] + } + + provisioner "shell" { + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + pause_before = "1m0s" + scripts = ["${path.root}/../scripts/build/cleanup.sh"] + start_retry_timeout = "10m" + } + + provisioner "shell" { + environment_vars = ["HELPER_SCRIPT_FOLDER=${var.helper_script_folder}", "INSTALLER_SCRIPT_FOLDER=${var.installer_script_folder}", "IMAGE_FOLDER=${var.image_folder}"] + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + scripts = ["${path.root}/../scripts/build/configure-system.sh"] + } + + provisioner "shell" { + execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" + inline = ["sleep 30", "export HISTSIZE=0 && sync"] + } + +}