Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ubuntu] add aws ami source #1

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions images/ubuntu/Ubuntu2204-Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Ubuntu 22.04
- OS Version: 22.04.5 LTS
- Kernel Version: 6.5.0-1025-azure
- Image Version: 20241015.1.0
- Image Version: 20241020.1.0
- Systemd version: 249.11-0ubuntu3.12

## Installed Software
Expand All @@ -20,7 +20,7 @@
- Dash 0.5.11+git20210903+057cd650a4ed-3build1
- GNU C++: 10.5.0, 11.4.0, 12.3.0
- GNU Fortran: 10.5.0, 11.4.0, 12.3.0
- Julia 1.11.0
- Julia 1.11.1
- Kotlin 2.0.21-release-482
- Mono 6.12.0.200
- MSBuild 16.10.1.31701 (Mono 6.12.0.200)
Expand All @@ -41,7 +41,7 @@
- Pip3 22.0.2
- Pipx 1.7.1
- RubyGems 3.3.5
- Vcpkg (build from commit e63bd09dc)
- Vcpkg (build from commit d567b667a)
- Yarn 1.22.22

#### Environment variables
Expand All @@ -63,7 +63,7 @@ to accomplish this.
- Gradle 8.10.2
- Lerna 8.1.8
- Maven 3.8.8
- Sbt 1.10.2
- Sbt 1.10.3

### Tools
- Ansible 2.17.5
Expand Down Expand Up @@ -101,29 +101,29 @@ to accomplish this.
- Packer 1.11.2
- Parcel 2.12.0
- Podman 3.4.4
- Pulumi 3.136.1
- Pulumi 3.137.0
- R 4.4.1
- Skopeo 1.4.1
- Sphinx Open Source Search Server 2.2.11
- SVN 1.14.1
- Terraform 1.9.7
- Terraform 1.9.8
- yamllint 1.35.1
- yq 4.44.3
- zstd 1.5.6

### CLI Tools
- Alibaba Cloud CLI 3.0.227
- AWS CLI 2.18.7
- AWS CLI 2.18.10
- AWS CLI Session Manager Plugin 1.2.677.0
- AWS SAM CLI 1.125.0
- AWS SAM CLI 1.126.0
- Azure CLI 2.65.0
- Azure CLI (azure-devops) 1.0.1
- GitHub CLI 2.58.0
- GitHub CLI 2.59.0
- Google Cloud CLI 497.0.0
- Netlify CLI 17.37.0
- OpenShift CLI 4.17.0
- Netlify CLI 17.37.1
- OpenShift CLI 4.17.1
- ORAS CLI 1.2.0
- Vercel CLI 37.8.0
- Vercel CLI 37.11.0

### Java
| Version | Environment Variable |
Expand All @@ -148,15 +148,15 @@ Both Xdebug and PCOV extensions are installed, but only Xdebug is enabled.
- Stack 3.1.1

### Rust Tools
- Cargo 1.81.0
- Rust 1.81.0
- Rustdoc 1.81.0
- Cargo 1.82.0
- Rust 1.82.0
- Rustdoc 1.82.0
- Rustup 1.27.1

#### Packages
- Bindgen 0.70.1
- Cargo audit 0.20.1
- Cargo clippy 0.1.81
- Cargo clippy 0.1.82
- Cargo outdated 0.15.0
- Cbindgen 0.27.0
- Rustfmt 1.7.1
Expand All @@ -165,10 +165,10 @@ Both Xdebug and PCOV extensions are installed, but only Xdebug is enabled.
- Google Chrome 130.0.6723.58
- ChromeDriver 130.0.6723.58
- Chromium 130.0.6723.0
- Microsoft Edge 129.0.2792.89
- Microsoft Edge WebDriver 129.0.2792.93
- Microsoft Edge 130.0.2849.46
- Microsoft Edge WebDriver 130.0.2849.46
- Selenium server 4.25.0
- Mozilla Firefox 131.0.2
- Mozilla Firefox 131.0.3
- Geckodriver 0.35.0

#### Environment variables
Expand All @@ -181,7 +181,7 @@ Both Xdebug and PCOV extensions are installed, but only Xdebug is enabled.

### .NET Tools
- .NET Core SDK: 6.0.427, 7.0.410, 8.0.403
- nbgv 3.6.143+57d4199a9c
- nbgv 3.6.146+392592327a

### Databases
- sqlite3 3.37.2
Expand Down Expand Up @@ -263,16 +263,16 @@ Use the following command as a part of your job to start the service: 'sudo syst
| CMake | 3.10.2<br>3.18.1<br>3.22.1 |
| Google Play services | 49 |
| Google Repository | 58 |
| NDK | 26.3.11579264<br>27.1.12297006 (default) |
| NDK | 26.3.11579264<br>27.2.12479018 (default) |

#### Environment variables
| Name | Value |
| ----------------------- | -------------------------------------------- |
| ANDROID_HOME | /usr/local/lib/android/sdk |
| ANDROID_NDK | /usr/local/lib/android/sdk/ndk/27.1.12297006 |
| ANDROID_NDK_HOME | /usr/local/lib/android/sdk/ndk/27.1.12297006 |
| ANDROID_NDK_LATEST_HOME | /usr/local/lib/android/sdk/ndk/27.1.12297006 |
| ANDROID_NDK_ROOT | /usr/local/lib/android/sdk/ndk/27.1.12297006 |
| ANDROID_NDK | /usr/local/lib/android/sdk/ndk/27.2.12479018 |
| ANDROID_NDK_HOME | /usr/local/lib/android/sdk/ndk/27.2.12479018 |
| ANDROID_NDK_LATEST_HOME | /usr/local/lib/android/sdk/ndk/27.2.12479018 |
| ANDROID_NDK_ROOT | /usr/local/lib/android/sdk/ndk/27.2.12479018 |
| ANDROID_SDK_ROOT | /usr/local/lib/android/sdk |

### Cached Docker images
Expand All @@ -283,16 +283,16 @@ Use the following command as a part of your job to start the service: 'sudo syst
| alpine:3.18 | sha256:3ddf7bf1d408188f9849efbf4f902720ae08f5131bb39013518b918aa056d0de | 2024-09-06 |
| alpine:3.19 | sha256:ae65dbf8749a7d4527648ccee1fa3deb6bfcae34cbc30fc67aa45c44dcaa90ee | 2024-09-06 |
| debian:10 | sha256:58ce6f1271ae1c8a2006ff7d3e54e9874d839f573d8009c20154ad0f2fb0a225 | 2024-06-13 |
| debian:11 | sha256:152b9a5dc2a03f18ddfd88fbe7b1df41bd2b16be9f2df573a373caf46ce78c08 | 2024-09-27 |
| debian:11 | sha256:d0036be35fe0a4d2649bf074ca467a37dab8c5b26bbbdfca0375b4dc682f011d | 2024-10-17 |
| moby/buildkit:latest | sha256:bc1fe18224dbcb92599139db0c745696c48ba9fd4ac24038d1fa81fdd7dcac27 | 2024-09-10 |
| node:16 | sha256:f77a1aef2da8d83e45ec990f45df50f1a286c5fe8bbfb8c6e4246c6389705c0b | 2023-09-07 |
| node:16-alpine | sha256:a1f9d027912b58a7c75be7716c97cfbc6d3099f3a97ed84aa490be9dee20e787 | 2023-08-10 |
| node:18 | sha256:f910225c96b0f77b0149f350a3184568a9ba6cddba2a7c7805cc125a50591605 | 2024-07-09 |
| node:18 | sha256:ddd173cd94537e155b378342056e0968e8299eb3da9dd5d412d3b7f796ac38c0 | 2024-07-09 |
| node:18-alpine | sha256:02376a266c84acbf45bd19440e08e48b1c8b98037417334046029ab585de03e2 | 2024-07-09 |
| node:20 | sha256:fffa89e023a3351904c04284029105d9e2ac7020886d683775a298569591e5bb | 2024-10-04 |
| node:20 | sha256:a5e0ed56f2c20b9689e0f7dd498cac7e08d2a3a283e92d9304e7b9b83e3c6ff3 | 2024-10-04 |
| node:20-alpine | sha256:c13b26e7e602ef2f1074aef304ce6e9b7dd284c419b35d89fcf3cc8e44a8def9 | 2024-10-04 |
| ubuntu:20.04 | sha256:e341aa0d58bb9480bd092a137658bd1a7a5e8ae4fca31769df0eb7d6c4b8266e | 2024-10-11 |
| ubuntu:22.04 | sha256:58b87898e82351c6cf9cf5b9f3c20257bb9e2dcf33af051e12ce532d7f94e3fe | 2024-09-11 |
| ubuntu:20.04 | sha256:8e5c4f0285ecbb4ead070431d29b576a530d3166df73ec44affc1cd27555141b | 2024-10-11 |
| ubuntu:22.04 | sha256:0e5e4a57c2499249aafc3b40fcd541e9a456aab7296681a3994d631587203f97 | 2024-09-11 |

### Installed apt packages
| Name | Version |
Expand Down
10 changes: 10 additions & 0 deletions images/ubuntu/scripts/build/configure-environment-azure-arm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -e
################################################################################
## File: configure-environment.sh
## Desc: Configure system and environment for azure build target
################################################################################

# Change waagent entries to use /mnt for swapfile
sed -i -e 's/ResourceDisk.Format=n/ResourceDisk.Format=y/g' \
-e 's/ResourceDisk.EnableSwap=n/ResourceDisk.EnableSwap=y/g' \
-e 's/ResourceDisk.SwapSizeMB=0/ResourceDisk.SwapSizeMB=4096/g' /etc/waagent.conf
5 changes: 0 additions & 5 deletions images/ubuntu/scripts/build/configure-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ set_etc_environment_variable "ACCEPT_EULA" "Y"
mkdir -p /etc/skel/.config/configstore
set_etc_environment_variable "XDG_CONFIG_HOME" '$HOME/.config'

# Change waagent entries to use /mnt for swap file
sed -i 's/ResourceDisk.Format=n/ResourceDisk.Format=y/g' /etc/waagent.conf
sed -i 's/ResourceDisk.EnableSwap=n/ResourceDisk.EnableSwap=y/g' /etc/waagent.conf
sed -i 's/ResourceDisk.SwapSizeMB=0/ResourceDisk.SwapSizeMB=4096/g' /etc/waagent.conf

# Add localhost alias to ::1 IPv6
sed -i 's/::1 ip6-localhost ip6-loopback/::1 localhost ip6-localhost ip6-loopback/g' /etc/hosts

Expand Down
141 changes: 140 additions & 1 deletion images/ubuntu/templates/ubuntu-22.04.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ packer {
source = "github.com/hashicorp/azure"
version = "1.4.5"
}
amazon = {
source = "github.com/hashicorp/amazon"
version = "1.3.2"
}
}
}

Expand Down Expand Up @@ -143,6 +147,86 @@ variable "vm_size" {
default = "Standard_D4s_v4"
}

variable "sources" {
type = list(string)
default = ["source.azure-arm.build_image"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input as variable with default value for backward compatibility reasons
azure is always build as default if no sources variable is provided

}

variable "aws_ami_name" {
type = string
default = "github-runner"
}

variable "aws_ami_regions" {
type = list(string)
default = ["eu-west-1"]
}

variable "aws_instance_type" {
type = string
default = "m5.large"
}

variable "aws_run_tags" {
type = map(string)
default = {}
}

variable "aws_tags" {
type = map(string)
default = {}
}

variable "aws_force_deregister" {
type = bool
default = false
}

variable "aws_force_delete_snapshot" {
type = bool
default = false
}

variable "aws_region" {
type = string
default = "${env("AWS_REGION")}"
}

variable "aws_vpc_id" {
type = string
default = "${env("AWS_VPC_ID")}"
}

variable "aws_subnet_id" {
type = string
default = "${env("AWS_SUBNET_ID")}"
}

variable "aws_volume_size" {
type = number
default = 150
ostefek99 marked this conversation as resolved.
Show resolved Hide resolved
}

variable "aws_run_volume_tags" {
type = map(string)
default = {}
}

variable "aws_associate_public_ip_address" {
type = bool
default = false
}

variable "aws_ssh_username" {
type = string
default = "ubuntu"
}

variable "aws_deprecate_after" {
type = string
default = "4380h" # 4380 hours = 6 months
}

source "azure-arm" "build_image" {
allowed_inbound_ip_addresses = "${var.allowed_inbound_ip_addresses}"
build_resource_group_name = "${var.build_resource_group_name}"
Expand Down Expand Up @@ -175,8 +259,55 @@ source "azure-arm" "build_image" {
}
}

source "amazon-ebs" "ubuntu-base-2204" {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new source for aws ami source

ami_name = "${var.aws_ami_name}"
ami_regions = var.aws_ami_regions # all known AWS regions

deprecate_at = timeadd(timestamp(), "${var.aws_deprecate_after}")

run_tags = var.aws_run_tags
tags = var.aws_tags

instance_type = "${var.aws_instance_type}"

force_deregister = var.aws_force_deregister
force_delete_snapshot = var.aws_force_delete_snapshot

region = "${var.aws_region}"
vpc_id = "${var.aws_vpc_id}"
subnet_id = "${var.aws_subnet_id}"

launch_block_device_mappings {
device_name = "/dev/sda1"
volume_size = var.aws_volume_size
delete_on_termination = true
}

run_volume_tags = var.aws_run_volume_tags

associate_public_ip_address = var.aws_associate_public_ip_address
ssh_username = "ubuntu"

metadata_options {
instance_metadata_tags = "enabled"
}

source_ami_filter {
# See https://ubuntu.com/server/docs/cloud-images/amazon-ec2
filters = {
virtualization-type = "hvm"
name = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"
root-device-type = "ebs"
architecture = "x86_64"
}

owners = ["099720109477"] # this is Canonical (official)
most_recent = true
}
}

build {
ostefek99 marked this conversation as resolved.
Show resolved Hide resolved
sources = ["source.azure-arm.build_image"]
sources = var.sources
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input as variable with default value for backward compatibility reasons
azure is always build as default if no sources variable is provided


provisioner "shell" {
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"
Expand Down Expand Up @@ -252,6 +383,13 @@ build {
scripts = ["${path.root}/../scripts/build/configure-environment.sh"]
}

provisioner "shell" {
only = ["azure-arm.build_image"]
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-azure-arm.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 }}'"
Expand Down Expand Up @@ -414,6 +552,7 @@ build {
}

provisioner "shell" {
only = ["azure-arm.build_image"]
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"
inline = ["sleep 30", "/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"]
}
Expand Down