Skip to content

Commit

Permalink
DUPLO-9835: Support arm64 docker native (#38)
Browse files Browse the repository at this point in the history
* add new packer builds

* update packer build steps for new AMIs

* add arch to the docker native JSON

* fix bug in github action

* add codium agent config

* add CHANGELOG.md

* Update CHANGELOG.md

* temporarily disable AmazonLinux 2023

* temporarily disable AmazonLinux 2023

* skip google images in govcloud

* fix missing dependency

* fix PR generation

---------

Co-authored-by: codiumai-pr-agent-pro[bot] <151058649+codiumai-pr-agent-pro[bot]@users.noreply.github.com>
  • Loading branch information
joek-duplo and qodo-merge-pro[bot] authored Feb 7, 2024
1 parent 2f71785 commit 865e34d
Show file tree
Hide file tree
Showing 7 changed files with 351 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:
# Parse build options.
if [ "$ONLY_BUILDERS" = "all" ]; then
ONLY_BUILDERS="-only=amazon-ebs.ubuntu-20,amazon-ebs.ubuntu-22,amazon-ebs.amazonlinux-2"
ONLY_BUILDERS="-except=amazon-ebs.ubuntu-18,googlecompute.ubuntu-20,googlecompute.ubuntu-22"
elif [ -n "$ONLY_BUILDERS" ]; then
ONLY_BUILDERS="-only=$ONLY_BUILDERS"
fi
Expand Down Expand Up @@ -204,6 +204,7 @@ jobs:
if: "${{ startsWith(github.event.inputs.image_version, 'release-') && github.event.inputs.only_partition == 'all' }}"
needs:
- build-commercial
- build-govcloud
steps:
# Get the code for the image JSON generation, and the code for Duplo master.
- name: Checkout duplo-infra
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Ignore packer manifest
packer-manifest.json
govcloud-packer-manifest.json
snippet-*.json
*.pkrvars.json

Expand Down
23 changes: 23 additions & 0 deletions .pr_agent.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See: https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#working-with-github-app
# See: https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml

[pr_reviewer]
enable_review_labels_effort = true

[pr_description]
add_original_user_description = true
keep_original_user_title = true

[github_app]
handle_pr_actions = ['opened', 'reopened', 'ready_for_review', 'review_requested']
pr_commands = [
"/describe",
"/review",
"/update_changelog --pr_update_changelog.push_changelog_changes=true"
]
handle_push_trigger = true
push_commands = [
"/describe",
"/review -i --pr_reviewer.remove_previous_review_comment=true",
"/update_changelog"
]
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## 2024-02-07

### Added
- Introduced support for ARM64 architecture in Docker native image generation.
- Added ARM64 builds for Ubuntu 20, Ubuntu 22, Amazon Linux 2, and Amazon Linux 2023 in AWS Packer configurations.
- Updated the main Packer build configuration to include ARM64 versions.

### Changed
- Modified the GitHub Actions workflow to exclude Ubuntu 18 from the build process, facilitating ARM64 build integration.
291 changes: 291 additions & 0 deletions packer/aws.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Settings for AWS
variable "aws_instance_type" { default = "t3.small" }
variable "aws_instance_type_arm64" { default = "t4g.small" }
variable "aws_region" { default = "us-west-2" }
variable "aws_vpc_id" { default = "vpc-083b7145ef48f1f6d" }
variable "aws_subnet_id" { default = "subnet-01ebe232b391d652b" }
Expand Down Expand Up @@ -204,6 +205,122 @@ source "amazon-ebs" "ubuntu-22" {
}
}

source "amazon-ebs" "ubuntu-20-arm64" {
ami_name = "${local.image_family}-ubuntu20-arm64-${local.image_version}"
ami_description = "${local.image_description} arm64 (ubuntu20)"
instance_type = var.aws_instance_type_arm64
region = var.aws_region
vpc_id = var.aws_vpc_id
subnet_id = var.aws_subnet_id
security_group_id = var.aws_security_group_id
iam_instance_profile = var.aws_iam_instance_profile
associate_public_ip_address = true

temporary_key_pair_type = var.temporary_key_pair_type
ssh_username = "ubuntu"
ssh_interface = "session_manager"

source_ami_filter {
filters = {
name = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-arm64-server-*"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = local.ubuntu_owners
}

# Build a public AMI
encrypt_boot = false
ami_groups = local.is_public ? ["all"] : []
ami_regions = [for region in local.ami_regions: region if region != var.aws_region]

# Customize the volumes
launch_block_device_mappings {
device_name = "/dev/sda1"
encrypted = false
volume_size = 35
volume_type = "gp3"
delete_on_termination = true
}

# Source instance tags.
run_tags = {
Name = "Packer Builder: ${local.image_family}-ubuntu20-arm64-${local.image_version}"
Creator = "Packer"
}
run_volume_tags = {
Creator = "Packer"
}

# Target AMI tags.
tags = {
Name = "${local.image_family}-ubuntu20-arm64-${local.image_version}"
Creator = "Packer"
}
snapshot_tags = {
Creator = "Packer"
}
}

source "amazon-ebs" "ubuntu-22-arm64" {
ami_name = "${local.image_family}-ubuntu22-arm64_${local.image_version}"
ami_description = "${local.image_description} arm64 (ubuntu22)"
instance_type = var.aws_instance_type_arm64
region = var.aws_region
vpc_id = var.aws_vpc_id
subnet_id = var.aws_subnet_id
security_group_id = var.aws_security_group_id
iam_instance_profile = var.aws_iam_instance_profile
associate_public_ip_address = true

temporary_key_pair_type = var.temporary_key_pair_type
ssh_username = "ubuntu"
ssh_interface = "session_manager"

source_ami_filter {
filters = {
name = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-arm64-server-*"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = local.ubuntu_owners
}

# Build a public AMI
encrypt_boot = false
ami_groups = local.is_public ? ["all"] : []
ami_regions = [for region in local.ami_regions: region if region != var.aws_region]

# Customize the volumes
launch_block_device_mappings {
device_name = "/dev/sda1"
encrypted = false
volume_size = 35
volume_type = "gp3"
delete_on_termination = true
}

# Source instance tags.
run_tags = {
Name = "Packer Builder: ${local.image_family}-ubuntu22-arm64-${local.image_version}"
Creator = "Packer"
}
run_volume_tags = {
Creator = "Packer"
}

# Target AMI tags.
tags = {
Name = "${local.image_family}-ubuntu22-arm64-${local.image_version}"
Creator = "Packer"
}
snapshot_tags = {
Creator = "Packer"
}
}

source "amazon-ebs" "amazonlinux-2" {
ami_name = "${local.image_family}-amazonlinux2-${local.image_version}"
ami_description = "${local.image_description} (amazonlinux2)"
Expand Down Expand Up @@ -261,3 +378,177 @@ source "amazon-ebs" "amazonlinux-2" {
Creator = "Packer"
}
}

source "amazon-ebs" "amazonlinux-2-arm64" {
ami_name = "${local.image_family}-amazonlinux2-arm64-${local.image_version}"
ami_description = "${local.image_description} arm64 (amazonlinux2)"
instance_type = var.aws_instance_type_arm64
region = var.aws_region
vpc_id = var.aws_vpc_id
subnet_id = var.aws_subnet_id
security_group_id = var.aws_security_group_id
iam_instance_profile = var.aws_iam_instance_profile
associate_public_ip_address = true

temporary_key_pair_type = var.temporary_key_pair_type
ssh_username = "ec2-user"
ssh_interface = "session_manager"

source_ami_filter {
filters = {
name = "amzn2-ami-kernel-5.10-hvm-*-arm64-gp2"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["amazon"]
}

# Build a public AMI
encrypt_boot = false
ami_groups = local.is_public ? ["all"] : []
ami_regions = [for region in local.ami_regions: region if region != var.aws_region]

# Customize the volumes
launch_block_device_mappings {
device_name = "/dev/xvda"
encrypted = false
volume_size = 35
volume_type = "gp3"
delete_on_termination = true
}

# Source instance tags.
run_tags = {
Name = "Packer Builder: ${local.image_family}-amazonlinux2-arm64-${local.image_version}"
Creator = "Packer"
}
run_volume_tags = {
Creator = "Packer"
}

# Target AMI tags.
tags = {
Name = "${local.image_family}-amazonlinux2-arm64-${local.image_version}"
Creator = "Packer"
}
snapshot_tags = {
Creator = "Packer"
}
}

// source "amazon-ebs" "amazonlinux-2023" {
// ami_name = "${local.image_family}-al2023-${local.image_version}"
// ami_description = "${local.image_description} (al2023)"
// instance_type = var.aws_instance_type
// region = var.aws_region
// vpc_id = var.aws_vpc_id
// subnet_id = var.aws_subnet_id
// security_group_id = var.aws_security_group_id
// iam_instance_profile = var.aws_iam_instance_profile
// associate_public_ip_address = true

// temporary_key_pair_type = var.temporary_key_pair_type
// ssh_username = "ec2-user"
// ssh_interface = "session_manager"

// source_ami_filter {
// filters = {
// name = "al2023-ami-*-kernel-6.1-x86_64"
// root-device-type = "ebs"
// virtualization-type = "hvm"
// }
// most_recent = true
// owners = ["amazon"]
// }

// # Build a public AMI
// encrypt_boot = false
// ami_groups = local.is_public ? ["all"] : []
// ami_regions = [for region in local.ami_regions: region if region != var.aws_region]

// # Customize the volumes
// launch_block_device_mappings {
// device_name = "/dev/xvda"
// encrypted = false
// volume_size = 35
// volume_type = "gp3"
// delete_on_termination = true
// }

// # Source instance tags.
// run_tags = {
// Name = "Packer Builder: ${local.image_family}-al2023-${local.image_version}"
// Creator = "Packer"
// }
// run_volume_tags = {
// Creator = "Packer"
// }

// # Target AMI tags.
// tags = {
// Name = "${local.image_family}-al2023-${local.image_version}"
// Creator = "Packer"
// }
// snapshot_tags = {
// Creator = "Packer"
// }
// }

// source "amazon-ebs" "amazonlinux-2023-arm64" {
// ami_name = "${local.image_family}-al2023-arm64-${local.image_version}"
// ami_description = "${local.image_description} arm64 (al2023)"
// instance_type = var.aws_instance_type_arm64
// region = var.aws_region
// vpc_id = var.aws_vpc_id
// subnet_id = var.aws_subnet_id
// security_group_id = var.aws_security_group_id
// iam_instance_profile = var.aws_iam_instance_profile
// associate_public_ip_address = true

// temporary_key_pair_type = var.temporary_key_pair_type
// ssh_username = "ec2-user"
// ssh_interface = "session_manager"

// source_ami_filter {
// filters = {
// name = "al2023-ami-*-kernel-6.1-arm64"
// root-device-type = "ebs"
// virtualization-type = "hvm"
// }
// most_recent = true
// owners = ["amazon"]
// }

// # Build a public AMI
// encrypt_boot = false
// ami_groups = local.is_public ? ["all"] : []
// ami_regions = [for region in local.ami_regions: region if region != var.aws_region]

// # Customize the volumes
// launch_block_device_mappings {
// device_name = "/dev/xvda"
// encrypted = false
// volume_size = 35
// volume_type = "gp3"
// delete_on_termination = true
// }

// # Source instance tags.
// run_tags = {
// Name = "Packer Builder: ${local.image_family}-al2023-arm64-${local.image_version}"
// Creator = "Packer"
// }
// run_volume_tags = {
// Creator = "Packer"
// }

// # Target AMI tags.
// tags = {
// Name = "${local.image_family}-al2023-arm64-${local.image_version}"
// Creator = "Packer"
// }
// snapshot_tags = {
// Creator = "Packer"
// }
// }
10 changes: 8 additions & 2 deletions packer/gen-native-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ do
s/ubuntu-/Ubuntu/g
')"

arch="amd64"
[ "${name/arm64/}" != $name ] && arch="arm64"
nicename="${nicename/-arm64/ (arm64)}"

echo "
$nicename images:"
artifacts="$(
Expand Down Expand Up @@ -87,15 +91,17 @@ $nicename images:"
\"ImageId\": \"${image}\",
\"Region\": \"${region}\",
\"Username\": \"${user}\",
\"Agent\": 0
\"Agent\": 0,
\"Arch\": \"${arch}\"
}"
done
done
done

echo "[$json
]" >snippet-temp.json
jq '. | map(select(.Name == "Docker-Duplo-Oregon-Ubuntu22") | .Name = "Docker-Duplo") + .' <snippet-temp.json >snippet-NativeImages.json
jq '. | map(select(.Name == "Docker-Duplo-Oregon-Ubuntu22" and .Arch == "amd64") | .Name = "Docker-Duplo") + .' <snippet-temp.json >snippet-temp2.json
jq '. | map(select(.Name == "Docker-Duplo-Oregon-Ubuntu22 (arm64)" and .Arch == "arm64") | .Name = "Docker-Duplo (arm64)") + .' <snippet-temp2.json >snippet-NativeImages.json
out "NativeImages JSON: snippet done"

# Step 2 - Build a new native images JSON
Expand Down
Loading

0 comments on commit 865e34d

Please sign in to comment.