Skip to content

Commit

Permalink
Add VM image for linux ARM64
Browse files Browse the repository at this point in the history
  • Loading branch information
hcho3 committed Dec 10, 2024
1 parent a973701 commit fb79c44
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 6 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ packer {

locals {
ami_name_prefix = "xgboost-ci"
image_name = "RunsOn worker with Ubuntu 24.04 + CUDA driver"
image_name = "RunsOn worker with Ubuntu 24.04 AMD64 + CUDA driver"
region = "us-west-2"
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
volume_size = 40
}

data "amazon-ami" "aws-ubuntu-x64" {
data "amazon-ami" "aws-ubuntu-amd64" {
filters = {
name = "ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*"
root-device-type = "ebs"
Expand All @@ -25,9 +25,9 @@ data "amazon-ami" "aws-ubuntu-x64" {
owners = ["amazon"]
}

source "amazon-ebs" "runs-on-linux" {
source_ami = "${data.amazon-ami.aws-ubuntu-x64.id}"
ami_name = "${local.ami_name_prefix}-runs-on-linux-${local.timestamp}"
source "amazon-ebs" "runs-on-linux-amd64" {
source_ami = "${data.amazon-ami.aws-ubuntu-amd64.id}"
ami_name = "${local.ami_name_prefix}-runs-on-linux-amd64-${local.timestamp}"
ami_description = "${local.image_name}"
ami_regions = ["${local.region}"]
ami_virtualization_type = "hvm"
Expand Down Expand Up @@ -60,7 +60,7 @@ source "amazon-ebs" "runs-on-linux" {
}

build {
sources = ["source.amazon-ebs.runs-on-linux"]
sources = ["source.amazon-ebs.runs-on-linux-amd64"]

provisioner "shell" {
script = "install_drivers.sh"
Expand Down
File renamed without changes.
49 changes: 49 additions & 0 deletions vm_images/linux-arm64/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
set -euo pipefail

## Install basic tools
echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections
sudo apt-get update
sudo apt-get install -y cmake git build-essential wget ca-certificates curl unzip

## Install Python3
sudo apt-get update
sudo apt-get install -y python3 python3-pip python3-venv
sudo pip3 install --break-system-packages 'pip>=23' 'wheel>=0.42' pydistcheck

## Install Docker
# Add Docker's official GPG key:
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Allow users to use Docker without sudo
sudo usermod -aG docker ubuntu

# Start Docker daemon
sudo systemctl is-active --quiet docker.service || sudo systemctl start docker.service
sudo systemctl is-enabled --quiet docker.service || sudo systemctl enable docker.service
sleep 10 # Docker daemon takes time to come up after installing
sudo docker info
sudo systemctl stop docker

## Install AWS CLI v2
wget -nv https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip -O awscliv2.zip
unzip -q awscliv2.zip
sudo ./aws/install
rm -rf ./aws/ ./awscliv2.zip

## Install jq and yq
sudo apt update && sudo apt install jq
mkdir yq/
pushd yq/
wget -nv https://github.com/mikefarah/yq/releases/download/v4.44.3/yq_linux_arm64.tar.gz -O - | \
tar xz && sudo mv ./yq_linux_arm64 /usr/bin/yq
popd
rm -rf yq/
68 changes: 68 additions & 0 deletions vm_images/linux-arm64/linux-arm64.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
packer {
required_plugins {
amazon = {
source = "github.com/hashicorp/amazon"
version = "~> 1"
}
}
}

locals {
ami_name_prefix = "xgboost-ci"
image_name = "RunsOn worker with Ubuntu 24.04 ARM64"
region = "us-west-2"
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
volume_size = 40
}

data "amazon-ami" "aws-ubuntu-arm64" {
filters = {
name = "ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-arm64-server-*"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["amazon"]
}

source "amazon-ebs" "runs-on-linux-arm64" {
source_ami = "${data.amazon-ami.aws-ubuntu-arm64.id}"
ami_name = "${local.ami_name_prefix}-runs-on-linux-arm64-${local.timestamp}"
ami_description = "${local.image_name}"
ami_regions = ["${local.region}"]
ami_virtualization_type = "hvm"
associate_public_ip_address = true
communicator = "ssh"
instance_type = "c6g.4xlarge"
region = "${local.region}"
ssh_timeout = "10m"
ssh_username = "ubuntu"
ssh_file_transfer_method = "sftp"
user_data_file = "setup_ssh.sh"
launch_block_device_mappings {
device_name = "/dev/sda1"
volume_size = "${local.volume_size}"
volume_type = "gp3"
delete_on_termination = true
}
aws_polling { # Wait up to 1 hour until the AMI is ready
delay_seconds = 15
max_attempts = 240
}
snapshot_tags = {
Name = "${local.image_name}"
BuildTime = "${local.timestamp}"
}
tags = {
Name = "${local.image_name}"
BuildTime = "${local.timestamp}"
}
}

build {
sources = ["source.amazon-ebs.runs-on-linux-arm64"]

provisioner "shell" {
script = "bootstrap.sh"
}
}
2 changes: 2 additions & 0 deletions vm_images/linux-arm64/setup_ssh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
systemctl start ssh

0 comments on commit fb79c44

Please sign in to comment.