Skip to content

Commit c64a85c

Browse files
author
Daniel Noland
committed
Build CI ami
1 parent c50f6ab commit c64a85c

File tree

20 files changed

+5385
-0
lines changed

20 files changed

+5385
-0
lines changed

ci/.terraform.lock.hcl

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ci/ami-builder/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
make-container.sh

ci/ami-builder/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM debian:bullseye
2+
3+
RUN apt-get update \
4+
&& apt-get dist-upgrade --yes \
5+
&& apt-get install --yes --no-install-recommends \
6+
packer \
7+
&& apt-get clean
8+
9+
COPY ./assets/root /
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
variable "ami_label" {
2+
type = string
3+
default = "rust_ibverbs-{{timestamp}}"
4+
}
5+
6+
variable "aws_access_key_id" {
7+
type = string
8+
default = ""
9+
}
10+
11+
variable "aws_secret_access_key" {
12+
type = string
13+
default = ""
14+
}
15+
16+
variable "aws_region" {
17+
type = string
18+
default = "us-west-1"
19+
}
20+
21+
source "amazon-ebssurrogate" "generated" {
22+
access_key = var.aws_access_key_id
23+
ami_description = "rust_ibverbs CI AMI"
24+
ami_name = var.ami_label
25+
ami_regions = [
26+
var.aws_region,
27+
]
28+
skip_region_validation = true
29+
ami_root_device {
30+
delete_on_termination = true
31+
device_name = "/dev/xvda"
32+
source_device_name = "/dev/xvdf"
33+
volume_size = 32
34+
volume_type = "gp2"
35+
}
36+
ami_virtualization_type = "hvm"
37+
associate_public_ip_address = true
38+
instance_type = "t2.micro"
39+
launch_block_device_mappings {
40+
delete_on_termination = true
41+
device_name = "/dev/xvdf"
42+
volume_size = 32
43+
volume_type = "gp2"
44+
}
45+
secret_key = var.aws_secret_access_key
46+
source_ami_filter {
47+
filters = {
48+
name = "*debian-10-amd64-*"
49+
root-device-type = "ebs"
50+
virtualization-type = "hvm"
51+
}
52+
most_recent = true
53+
owners = [
54+
"136693071363", # debian aws id
55+
]
56+
}
57+
ssh_pty = true
58+
ssh_timeout = "5m"
59+
ssh_username = "admin"
60+
}
61+
62+
build {
63+
sources = [
64+
"source.amazon-ebssurrogate.generated"
65+
]
66+
67+
provisioner "file" {
68+
source = "/tmp/rust_ibverbs.img.zst"
69+
destination = "/tmp/rust_ibverbs.img.zst"
70+
}
71+
72+
provisioner "file" {
73+
source = "provision-image.sh"
74+
destination = "/tmp/provision-image.sh"
75+
}
76+
77+
provisioner "shell" {
78+
script = "install-image.sh"
79+
skip_clean = true
80+
start_retry_timeout = "5m"
81+
}
82+
83+
post-processor "manifest" {
84+
output = "manifest.json"
85+
}
86+
87+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env bash
2+
# Install the generated image to the EBS volume
3+
4+
set -euxETo pipefail
5+
6+
declare -rx DEBIAN_FRONTEND="noninteractive"
7+
8+
declare -r IMAGE_DEVICE="/dev/xvdf"
9+
10+
sudo apt-get update
11+
sudo apt-get install --yes --no-install-recommends \
12+
coreutils `#needed for chroot` \
13+
e2fsprogs `#needed to resize root filesystem` \
14+
gdisk `#needed to resize root partition` \
15+
parted `#needed to partprobe image after transfer` \
16+
zstd `#needed to decompress system image`
17+
sudo zstd --decompress --force -o "${IMAGE_DEVICE}" /tmp/rust_ibverbs.img.zst
18+
sync
19+
20+
sudo partprobe --summary
21+
22+
declare -ri ROOT_DEVICE_PARTITION_NUMBER=3
23+
declare -ri BOOT_DEVICE_PARTITION_NUMBER=2
24+
declare -r ROOT_DEVICE="${IMAGE_DEVICE}${ROOT_DEVICE_PARTITION_NUMBER}"
25+
declare -r BOOT_DEVICE="${IMAGE_DEVICE}${BOOT_DEVICE_PARTITION_NUMBER}"
26+
27+
# Resize the root partition to take all available space.
28+
sync
29+
sudo sgdisk --move-second-header "${IMAGE_DEVICE}"
30+
sync
31+
sudo sgdisk --delete="${ROOT_DEVICE_PARTITION_NUMBER}" "${IMAGE_DEVICE}"
32+
sync
33+
sudo sgdisk --largest-new="${ROOT_DEVICE_PARTITION_NUMBER}" "${IMAGE_DEVICE}"
34+
sync
35+
sudo sgdisk --change-name="${ROOT_DEVICE_PARTITION_NUMBER}":root "${IMAGE_DEVICE}"
36+
sync
37+
sudo sgdisk --move-second-header "${IMAGE_DEVICE}"
38+
sync
39+
sudo partprobe --summary
40+
sync
41+
sudo e2fsck -v -f "${ROOT_DEVICE}" || true
42+
sync
43+
sudo e2fsck -v -f "${ROOT_DEVICE}"
44+
sync
45+
sudo resize2fs "${ROOT_DEVICE}"
46+
sync
47+
sudo partprobe --summary
48+
sync
49+
50+
declare CHROOT
51+
CHROOT="$(sudo mktemp -t --directory --suffix=".rust_ibverbs.rootfs")"
52+
declare -r CHROOT
53+
54+
sudo mount "${ROOT_DEVICE}" "${CHROOT}"
55+
sudo mount "${BOOT_DEVICE}" "${CHROOT}/boot"
56+
57+
# Prepare our chroot with necessary bind mounts
58+
sudo mount -t proc /proc "${CHROOT}"/proc
59+
sudo mount --rbind /sys "${CHROOT}"/sys
60+
sudo mount --rbind /dev/ "${CHROOT}"/dev
61+
sudo mount --make-rslave "${CHROOT}"
62+
sudo mount -t tmpfs -o size=128M tmpfs "${CHROOT}/tmp"
63+
64+
sudo cp /tmp/provision-image.sh "${CHROOT}/tmp/provision-image.sh"
65+
sudo mv "${CHROOT}/etc/resolv.conf" "${CHROOT}/etc/resolv.conf.orig"
66+
sudo cp /etc/resolv.conf "${CHROOT}/etc/resolv.conf"
67+
sudo chmod +x "${CHROOT}/tmp/provision-image.sh"
68+
69+
sudo chroot "${CHROOT}" /tmp/provision-image.sh "${IMAGE_DEVICE}"
70+
sync
71+
sudo mv "${CHROOT}/etc/resolv.conf.orig" "${CHROOT}/etc/resolv.conf"
72+
sync
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"builds": [
3+
{
4+
"name": "generated",
5+
"builder_type": "amazon-ebssurrogate",
6+
"build_time": 1623427339,
7+
"files": null,
8+
"artifact_id": "us-west-1:ami-0f0a43086150a5cc6",
9+
"packer_run_uuid": "92a44adf-384a-9b0d-f8d4-45cd0cbf0cc7",
10+
"custom_data": null
11+
},
12+
{
13+
"name": "generated",
14+
"builder_type": "amazon-ebssurrogate",
15+
"build_time": 1623432569,
16+
"files": null,
17+
"artifact_id": "us-west-1:ami-0b71e7b75ef6e432c",
18+
"packer_run_uuid": "6e6eca61-519a-a174-1fd0-67f2541137df",
19+
"custom_data": null
20+
},
21+
{
22+
"name": "generated",
23+
"builder_type": "amazon-ebssurrogate",
24+
"build_time": 1623434041,
25+
"files": null,
26+
"artifact_id": "us-west-1:ami-0247055d748c65c9a",
27+
"packer_run_uuid": "f9da5cf2-917f-c887-a537-a1defd907fe7",
28+
"custom_data": null
29+
}
30+
],
31+
"last_run_uuid": "f9da5cf2-917f-c887-a537-a1defd907fe7"
32+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxETo pipefail
4+
5+
declare -x DEBIAN_FRONTEND=noninteractive
6+
declare -r IMAGE_DEVICE="${1}"
7+
8+
apt-get update
9+
10+
# Do not configure grub during package install
11+
printf 'grub-pc grub-pc/install_devices_empty select true\n' | debconf-set-selections
12+
printf 'grub-pc grub-pc/install_devices select\n' | debconf-set-selections
13+
14+
# Install various packages needed for a booting system
15+
apt-get install --yes --no-install-recommends \
16+
grub2 \
17+
locales
18+
19+
# Set the locale to en_US.UTF-8
20+
locale-gen --purge en_US.UTF-8
21+
printf 'LANG="en_US.UTF-8"\nLANGUAGE="en_US:en"\n' > /etc/default/locale
22+
locale-gen
23+
24+
# Install GRUB (can't currently seem to do UEFI in AWS)
25+
grub-probe /
26+
grub-install "${IMAGE_DEVICE}"
27+
28+
# Configure and update GRUB
29+
mkdir -p /etc/default/grub.d
30+
cat <<EOF > /etc/default/grub.d/50-aws-settings.cfg
31+
GRUB_RECORDFAIL_TIMEOUT=0
32+
GRUB_TIMEOUT=0
33+
GRUB_CMDLINE_LINUX_DEFAULT="root=LABEL=ROOT rw console=tty0 earlyprintk=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 scsi_mod.use_blk_mq=Y"
34+
GRUB_TERMINAL=console
35+
EOF
36+
37+
update-grub
38+
39+
# Set options for the default interface
40+
cat <<EOF >> /etc/network/interfaces
41+
auto eth0
42+
iface eth0 inet dhcp
43+
EOF

ci/ami-builder/make-container.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxETo pipefail
4+
5+
declare build_dir
6+
build_dir="$(readlink --canonicalize-existing "$(dirname "${0}")")"
7+
declare -r build_dir
8+
9+
pushd "${build_dir}"
10+
docker buildx build --tag=rust_ibverbs_ami_builder "${build_dir}"
11+
popd

ci/image-builder/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
make-container.sh

ci/image-builder/Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM debian:bullseye
2+
3+
# Install tools necessary to assemble a physical / virtual disc image
4+
RUN apt-get update \
5+
&& apt-get dist-upgrade --yes \
6+
&& apt-get install --yes --no-install-recommends \
7+
apt-transport-https `#needed for docker` \
8+
ca-certificates `#needed for docker` \
9+
curl `#needed for docker` \
10+
dosfstools `#needed to make EFI disc partition` \
11+
gnupg `#needed for docker` \
12+
lsb-release `#needed for docker` \
13+
parted `#needed to partition loopback disc image` \
14+
zstd `#needed to de/compress generated image` \
15+
udev `#needed to silence parted chatter` \
16+
&& apt-get clean
17+
18+
# install most recent docker-ce (the one Debian ships whith is always ancient)
19+
RUN curl --fail --silent --show-error --location https://download.docker.com/linux/debian/gpg \
20+
| gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg \
21+
&& \
22+
{ \
23+
printf "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] "; \
24+
printf "https://download.docker.com/linux/debian bullseye stable\n"; \
25+
} | tee /etc/apt/sources.list.d/docker.list > /dev/null \
26+
&& apt-get update \
27+
&& apt-get install --yes --no-install-recommends \
28+
containerd.io \
29+
docker-ce \
30+
docker-ce-cli
31+
32+
COPY ./assets/generate-image.sh /
33+
34+
CMD ["/generate-image.sh"]

0 commit comments

Comments
 (0)