@@ -38,10 +38,14 @@ variable "environment" {
38
38
default = " prod"
39
39
}
40
40
41
- variable "region " {
41
+ variable "git_sha " {
42
42
type = string
43
43
}
44
44
45
+ # variable "region" {
46
+ # type = string
47
+ # }
48
+
45
49
variable "build-vol" {
46
50
type = string
47
51
default = " xvdc"
@@ -98,140 +102,69 @@ packer {
98
102
source = " github.com/hashicorp/amazon"
99
103
version = " ~> 1"
100
104
}
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"
124
108
}
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"
182
109
}
110
+ }
183
111
184
- associate_public_ip_address = true
112
+ source "null" "dependencies" {
113
+ communicator = " none"
185
114
}
186
115
187
- # a build block invokes sources and runs provisioning steps on them.
188
116
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" ]
195
119
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
+ }
230
164
231
- provisioner "file" {
232
- source = " ebssurrogate/files/unit-tests"
233
- destination = " /tmp"
234
- }
165
+ build {
166
+ name = " cloudimg.image"
167
+ sources = [" source.qemu.cloudimg" ]
235
168
236
169
# Copy ansible playbook
237
170
provisioner "shell" {
@@ -249,29 +182,24 @@ build {
249
182
}
250
183
251
184
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"
254
192
}
255
193
256
194
provisioner "shell" {
257
195
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 } "
264
198
]
265
199
use_env_var_file = true
266
200
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}}'"
268
202
start_retry_timeout = " 5m"
269
203
skip_clean = true
270
204
}
271
-
272
- provisioner "file" {
273
- source = " /tmp/ansible.log"
274
- destination = " /tmp/ansible.log"
275
- direction = " download"
276
- }
277
205
}
0 commit comments