-
Notifications
You must be signed in to change notification settings - Fork 173
/
ubuntu-cloudimg.pkr.hcl
127 lines (113 loc) · 3.75 KB
/
ubuntu-cloudimg.pkr.hcl
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
116
117
118
119
120
121
122
123
124
125
126
127
locals {
qemu_arch = {
"amd64" = "x86_64"
"arm64" = "aarch64"
}
uefi_imp = {
"amd64" = "OVMF"
"arm64" = "AAVMF"
}
qemu_machine = {
"amd64" = "ubuntu,accel=kvm"
"arm64" = "virt"
}
qemu_cpu = {
"amd64" = "host"
"arm64" = "cortex-a57"
}
proxy_env = [
"http_proxy=${var.http_proxy}",
"https_proxy=${var.https_proxy}",
"no_proxy=${var.https_proxy}",
]
}
source "null" "dependencies" {
communicator = "none"
}
source "qemu" "cloudimg" {
boot_wait = "2s"
cpus = 2
disk_image = true
disk_size = "6G"
format = "qcow2"
headless = var.headless
http_directory = var.http_directory
iso_checksum = "file:https://cloud-images.ubuntu.com/${var.ubuntu_series}/current/SHA256SUMS"
iso_url = "https://cloud-images.ubuntu.com/${var.ubuntu_series}/current/${var.ubuntu_series}-server-cloudimg-${var.architecture}.img"
memory = 2048
qemu_binary = "qemu-system-${lookup(local.qemu_arch, var.architecture, "")}"
qemu_img_args {
create = ["-F", "qcow2"]
}
qemuargs = [
["-machine", "${lookup(local.qemu_machine, var.architecture, "")}"],
["-cpu", "${lookup(local.qemu_cpu, var.architecture, "")}"],
["-device", "virtio-gpu-pci"],
["-drive", "if=pflash,format=raw,id=ovmf_code,readonly=on,file=/usr/share/${lookup(local.uefi_imp, var.architecture, "")}/${lookup(local.uefi_imp, var.architecture, "")}_CODE${var.ovmf_suffix}.fd"],
["-drive", "if=pflash,format=raw,id=ovmf_vars,file=${lookup(local.uefi_imp, var.architecture, "")}_VARS.fd"],
["-drive", "file=output-cloudimg/packer-cloudimg,format=qcow2"],
["-drive", "file=seeds-cloudimg.iso,format=raw"]
]
shutdown_command = "sudo -S shutdown -P now"
ssh_handshake_attempts = 500
ssh_password = var.ssh_password
ssh_timeout = var.timeout
ssh_username = var.ssh_username
ssh_wait_timeout = var.timeout
use_backing_file = true
}
build {
name = "cloudimg.deps"
sources = ["source.null.dependencies"]
provisioner "shell-local" {
inline = [
"cp /usr/share/${lookup(local.uefi_imp, var.architecture, "")}/${lookup(local.uefi_imp, var.architecture, "")}_VARS.fd ${lookup(local.uefi_imp, var.architecture, "")}_VARS.fd",
"cloud-localds seeds-cloudimg.iso user-data-cloudimg meta-data"
]
inline_shebang = "/bin/bash -e"
}
}
build {
name = "cloudimg.image"
sources = ["source.qemu.cloudimg"]
provisioner "shell" {
environment_vars = concat(local.proxy_env, ["DEBIAN_FRONTEND=noninteractive"])
scripts = ["${path.root}/scripts/cloudimg/setup-boot.sh"]
}
provisioner "shell" {
environment_vars = concat(local.proxy_env, ["DEBIAN_FRONTEND=noninteractive"])
expect_disconnect = true
scripts = [var.customize_script]
}
provisioner "shell" {
environment_vars = [
"CLOUDIMG_CUSTOM_KERNEL=${var.kernel}",
"DEBIAN_FRONTEND=noninteractive"
]
scripts = ["${path.root}/scripts/cloudimg/install-custom-kernel.sh"]
}
provisioner "file" {
destination = "/tmp/"
sources = ["${path.root}/scripts/cloudimg/curtin-hooks"]
}
provisioner "shell" {
environment_vars = ["CLOUDIMG_CUSTOM_KERNEL=${var.kernel}"]
scripts = ["${path.root}/scripts/cloudimg/setup-curtin.sh"]
}
provisioner "shell" {
environment_vars = ["DEBIAN_FRONTEND=noninteractive"]
scripts = ["${path.root}/scripts/cloudimg/cleanup.sh"]
}
post-processor "shell-local" {
inline = [
"IMG_FMT=qcow2",
"SOURCE=cloudimg",
"ROOT_PARTITION=1",
"DETECT_BLS_BOOT=1",
"OUTPUT=${var.filename}",
"source ../scripts/fuse-nbd",
"source ../scripts/fuse-tar-root"
]
inline_shebang = "/bin/bash -e"
}
}