Skip to content

Commit a3cce04

Browse files
committed
chore: try a qemu build
1 parent 4b0e661 commit a3cce04

17 files changed

+320
-538
lines changed

Dockerfile-kubevirt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM scratch
2+
ADD --chown=107:107 focal.img /disk/focal.qcow2

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# TODO (darora): we can get rid of this once we're actually building nix things on this
2+
UPSTREAM_NIX_GIT_SHA := $(shell git rev-parse origin/release/15.6)
3+
GIT_SHA := $(shell git describe --tags --always --dirty)
4+
5+
init: amazon-arm64-nix.pkr.hcl
6+
packer init amazon-arm64-nix.pkr.hcl
7+
8+
output-cloudimg/packer-cloudimg: ansible amazon-arm64-nix.pkr.hcl
9+
packer build -var "git_sha=$(UPSTREAM_NIX_GIT_SHA)" amazon-arm64-nix.pkr.hcl
10+
11+
disk/focal-raw.img: output-cloudimg/packer-cloudimg
12+
mkdir -p disk
13+
sudo qemu-img convert -O raw output-cloudimg/packer-cloudimg disk/focal-raw.img
14+
15+
container-disk-image: disk/focal-raw.img
16+
sudo nerdctl build . -t supabase-postgres-test:$(GIT_SHA) --namespace k8s.io -f ./Dockerfile-kubevirt
17+
18+
host-disk: disk/focal-raw.img
19+
sudo chown 107 -R disk
20+
21+
clean:
22+
rm -rf output-cloudimg
23+
24+
.PHONY: container-disk-image host-disk init clean

amazon-arm64-nix.pkr.hcl

Lines changed: 70 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ variable "environment" {
3838
default = "prod"
3939
}
4040

41-
variable "region" {
41+
variable "git_sha" {
4242
type = string
4343
}
4444

45+
# variable "region" {
46+
# type = string
47+
# }
48+
4549
variable "build-vol" {
4650
type = string
4751
default = "xvdc"
@@ -98,140 +102,69 @@ packer {
98102
source = "github.com/hashicorp/amazon"
99103
version = "~> 1"
100104
}
101-
}
102-
}
103-
104-
# source block
105-
source "amazon-ebssurrogate" "source" {
106-
profile = "${var.profile}"
107-
#access_key = "${var.aws_access_key}"
108-
#ami_name = "${var.ami_name}-arm64-${formatdate("YYYY-MM-DD-hhmm", timestamp())}"
109-
ami_name = "${var.ami_name}-${var.postgres-version}-stage-1"
110-
ami_virtualization_type = "hvm"
111-
ami_architecture = "arm64"
112-
ami_regions = "${var.ami_regions}"
113-
instance_type = "c6g.4xlarge"
114-
region = "${var.region}"
115-
#secret_key = "${var.aws_secret_key}"
116-
force_deregister = var.force-deregister
117-
118-
# Use latest official ubuntu focal ami owned by Canonical.
119-
source_ami_filter {
120-
filters = {
121-
virtualization-type = "hvm"
122-
name = "${var.ami}"
123-
root-device-type = "ebs"
105+
qemu = {
106+
version = "~> 1.0"
107+
source = "github.com/hashicorp/qemu"
124108
}
125-
owners = [ "099720109477" ]
126-
most_recent = true
127-
}
128-
ena_support = true
129-
launch_block_device_mappings {
130-
device_name = "/dev/xvdf"
131-
delete_on_termination = true
132-
volume_size = 10
133-
volume_type = "gp3"
134-
}
135-
136-
launch_block_device_mappings {
137-
device_name = "/dev/xvdh"
138-
delete_on_termination = true
139-
volume_size = 8
140-
volume_type = "gp3"
141-
}
142-
143-
launch_block_device_mappings {
144-
device_name = "/dev/${var.build-vol}"
145-
delete_on_termination = true
146-
volume_size = 16
147-
volume_type = "gp2"
148-
omit_from_artifact = true
149-
}
150-
151-
run_tags = {
152-
creator = "packer"
153-
appType = "postgres"
154-
packerExecutionId = "${var.packer-execution-id}"
155-
}
156-
run_volume_tags = {
157-
creator = "packer"
158-
appType = "postgres"
159-
}
160-
snapshot_tags = {
161-
creator = "packer"
162-
appType = "postgres"
163-
}
164-
tags = {
165-
creator = "packer"
166-
appType = "postgres"
167-
postgresVersion = "${var.postgres-version}-stage1"
168-
sourceSha = "${var.git-head-version}"
169-
}
170-
171-
communicator = "ssh"
172-
ssh_pty = true
173-
ssh_username = "ubuntu"
174-
ssh_timeout = "5m"
175-
176-
ami_root_device {
177-
source_device_name = "/dev/xvdf"
178-
device_name = "/dev/xvda"
179-
delete_on_termination = true
180-
volume_size = 10
181-
volume_type = "gp2"
182109
}
110+
}
183111

184-
associate_public_ip_address = true
112+
source "null" "dependencies" {
113+
communicator = "none"
185114
}
186115

187-
# a build block invokes sources and runs provisioning steps on them.
188116
build {
189-
sources = ["source.amazon-ebssurrogate.source"]
190-
191-
provisioner "file" {
192-
source = "ebssurrogate/files/sources-arm64.cfg"
193-
destination = "/tmp/sources.list"
194-
}
117+
name = "cloudimg.deps"
118+
sources = ["source.null.dependencies"]
195119

196-
provisioner "file" {
197-
source = "ebssurrogate/files/ebsnvme-id"
198-
destination = "/tmp/ebsnvme-id"
199-
}
200-
201-
provisioner "file" {
202-
source = "ebssurrogate/files/70-ec2-nvme-devices.rules"
203-
destination = "/tmp/70-ec2-nvme-devices.rules"
204-
}
205-
206-
provisioner "file" {
207-
source = "ebssurrogate/scripts/chroot-bootstrap-nix.sh"
208-
destination = "/tmp/chroot-bootstrap-nix.sh"
209-
}
210-
211-
provisioner "file" {
212-
source = "ebssurrogate/files/cloud.cfg"
213-
destination = "/tmp/cloud.cfg"
214-
}
215-
216-
provisioner "file" {
217-
source = "ebssurrogate/files/vector.timer"
218-
destination = "/tmp/vector.timer"
219-
}
220-
221-
provisioner "file" {
222-
source = "ebssurrogate/files/apparmor_profiles"
223-
destination = "/tmp"
224-
}
225-
226-
provisioner "file" {
227-
source = "migrations"
228-
destination = "/tmp"
229-
}
120+
provisioner "shell-local" {
121+
inline = [
122+
"cp /usr/share/AAVMF/AAVMF_VARS.fd AAVMF_VARS.fd",
123+
"cloud-localds seeds-cloudimg.iso user-data-cloudimg meta-data"
124+
]
125+
inline_shebang = "/bin/bash -e"
126+
}
127+
}
128+
129+
source "qemu" "cloudimg" {
130+
boot_wait = "2s"
131+
cpus = 12
132+
disk_image = true
133+
disk_size = "15G"
134+
format = "qcow2"
135+
# TODO (darora): disable backing image for qcow2
136+
headless = true
137+
http_directory = "http"
138+
iso_checksum = "file:https://cloud-images.ubuntu.com/focal/current/SHA256SUMS"
139+
iso_url = "https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-arm64.img"
140+
memory = 20000
141+
qemu_binary = "qemu-system-aarch64"
142+
qemu_img_args {
143+
create = ["-F", "qcow2"]
144+
}
145+
qemuargs = [
146+
["-machine", "virt"],
147+
["-cpu", "host"],
148+
["-device", "virtio-gpu-pci"],
149+
["-drive", "if=pflash,format=raw,id=ovmf_code,readonly=on,file=/usr/share/AAVMF/AAVMF_CODE.fd"],
150+
["-drive", "if=pflash,format=raw,id=ovmf_vars,file=AAVMF_VARS.fd"],
151+
["-drive", "file=output-cloudimg/packer-cloudimg,format=qcow2"],
152+
["-drive", "file=seeds-cloudimg.iso,format=raw"],
153+
["--enable-kvm"]
154+
]
155+
shutdown_command = "sudo -S shutdown -P now"
156+
ssh_handshake_attempts = 500
157+
ssh_password = "ubuntu"
158+
ssh_timeout = "1h"
159+
ssh_username = "ubuntu"
160+
ssh_wait_timeout = "1h"
161+
use_backing_file = true
162+
accelerator = "kvm"
163+
}
230164

231-
provisioner "file" {
232-
source = "ebssurrogate/files/unit-tests"
233-
destination = "/tmp"
234-
}
165+
build {
166+
name = "cloudimg.image"
167+
sources = ["source.qemu.cloudimg"]
235168

236169
# Copy ansible playbook
237170
provisioner "shell" {
@@ -249,29 +182,24 @@ build {
249182
}
250183

251184
provisioner "file" {
252-
source = "ansible/vars.yml"
253-
destination = "/tmp/ansible-playbook/vars.yml"
185+
source = "migrations"
186+
destination = "/tmp"
187+
}
188+
189+
provisioner "file" {
190+
source = "ebssurrogate/files/unit-tests"
191+
destination = "/tmp"
254192
}
255193

256194
provisioner "shell" {
257195
environment_vars = [
258-
"ARGS=${var.ansible_arguments}",
259-
"DOCKER_USER=${var.docker_user}",
260-
"DOCKER_PASSWD=${var.docker_passwd}",
261-
"DOCKER_IMAGE=${var.docker_image}",
262-
"DOCKER_IMAGE_TAG=${var.docker_image_tag}",
263-
"POSTGRES_SUPABASE_VERSION=${var.postgres-version}"
196+
"POSTGRES_SUPABASE_VERSION=${var.postgres-version}",
197+
"GIT_SHA=${var.git_sha}"
264198
]
265199
use_env_var_file = true
266200
script = "ebssurrogate/scripts/surrogate-bootstrap-nix.sh"
267-
execute_command = "sudo -S sh -c '. {{.EnvVarFile}} && {{.Path}}'"
201+
execute_command = "sudo -S sh -c '. {{.EnvVarFile}} && cd /tmp/ansible-playbook && {{.Path}}'"
268202
start_retry_timeout = "5m"
269203
skip_clean = true
270204
}
271-
272-
provisioner "file" {
273-
source = "/tmp/ansible.log"
274-
destination = "/tmp/ansible.log"
275-
direction = "download"
276-
}
277205
}

0 commit comments

Comments
 (0)