-
-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathqemu.pkr.hcl
More file actions
115 lines (100 loc) · 2.81 KB
/
Copy pathqemu.pkr.hcl
File metadata and controls
115 lines (100 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
variable "git_sha" {
type = string
}
variable "postgres-version" {
type = string
default = ""
}
variable "postgres_major_version" {
type = string
default = ""
}
# Working dir to pick up non-source files and put output files
variable "workdir" {
type = string
}
# Arch-specific values supplied by build-qemu-image
variable "arch" {
type = string
}
variable "cpu" {
type = string
}
variable "machine" {
type = string
}
variable "qemu_binary" {
type = string
}
packer {
required_plugins {
qemu = {
source = "github.com/hashicorp/qemu"
version = "1.1.6"
}
}
}
source "qemu" "cloudimg" {
boot_wait = "2s"
cpus = 8
disk_image = true
disk_size = "15G"
format = "qcow2"
headless = true
http_directory = "http"
iso_checksum = "file:https://cloud-images.ubuntu.com/minimal/releases/noble/release/SHA256SUMS"
iso_url = "https://cloud-images.ubuntu.com/minimal/releases/noble/release/ubuntu-24.04-minimal-cloudimg-${var.arch}.img"
memory = 4096 # MiB
output_directory = "${var.workdir}/output-cloudimg"
qemu_img_args {
convert = ["-o", "compression_type=zstd"]
}
qemu_binary = var.qemu_binary
qemuargs = [
["-machine", var.machine],
["-cpu", var.cpu],
["-device", "virtio-gpu-pci"],
["-drive", "if=pflash,format=raw,id=ovmf_code,readonly=on,file=${var.workdir}/ovmf_code.fd"],
["-drive", "if=pflash,format=raw,id=ovmf_vars,file=${var.workdir}/ovmf_vars.fd"],
["-drive", "file=${var.workdir}/output-cloudimg/packer-cloudimg,if=virtio,format=qcow2,discard=on,detect-zeroes=unmap"],
["-drive", "file=${var.workdir}/seeds-cloudimg.iso,format=raw,if=virtio"],
]
shutdown_command = "sudo -S shutdown -P now"
ssh_handshake_attempts = 500
ssh_password = "ubuntu"
ssh_timeout = "1h"
ssh_username = "ubuntu"
ssh_wait_timeout = "1h"
use_backing_file = false
}
build {
name = "cloudimg.image"
sources = ["source.qemu.cloudimg"]
# Copy ansible playbook
provisioner "shell" {
inline = ["mkdir /tmp/ansible-playbook"]
}
provisioner "file" {
source = "ansible"
destination = "/tmp/ansible-playbook"
}
provisioner "file" {
source = "migrations"
destination = "/tmp"
}
provisioner "file" {
source = "scripts"
destination = "/tmp/ansible-playbook"
}
provisioner "shell" {
environment_vars = [
"GIT_SHA=${var.git_sha}",
"POSTGRES_MAJOR_VERSION=${var.postgres_major_version}"
]
use_env_var_file = true
script = "ebssurrogate/scripts/qemu-bootstrap-nix.sh"
execute_command = "sudo -S sh -c '. {{.EnvVarFile}} && cd /tmp/ansible-playbook && {{.Path}}'"
start_retry_timeout = "5m"
skip_clean = true
}
}