@@ -38,14 +38,10 @@ variable "environment" {
38
38
default = " prod"
39
39
}
40
40
41
- variable "git_sha " {
41
+ variable "region " {
42
42
type = string
43
43
}
44
44
45
- # variable "region" {
46
- # type = string
47
- # }
48
-
49
45
variable "build-vol" {
50
46
type = string
51
47
default = " xvdc"
@@ -102,83 +98,129 @@ packer {
102
98
source = " github.com/hashicorp/amazon"
103
99
version = " ~> 1"
104
100
}
105
- qemu = {
106
- version = " ~> 1.0"
107
- source = " github.com/hashicorp/qemu"
108
- }
109
101
}
110
102
}
111
103
112
- source "null" "dependencies" {
113
- communicator = " none"
114
- }
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
115
117
116
- build {
117
- name = " cloudimg.deps"
118
- sources = [" source.null.dependencies" ]
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"
124
+ }
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
+ }
119
135
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"
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
+ }
183
+
184
+ associate_public_ip_address = true
163
185
}
164
186
187
+ # a build block invokes sources and runs provisioning steps on them.
165
188
build {
166
- name = " cloudimg.image"
167
- sources = [" source.qemu.cloudimg" ]
189
+ sources = [" source.amazon-ebssurrogate.source" ]
168
190
169
- # Copy ansible playbook
170
- provisioner "shell" {
171
- inline = [ " mkdir /tmp/ansible-playbook " ]
191
+ provisioner "file" {
192
+ source = " ebssurrogate/files/sources-arm64.cfg "
193
+ destination = " /tmp/sources.list "
172
194
}
173
195
174
196
provisioner "file" {
175
- source = " ansible "
176
- destination = " /tmp/ansible-playbook "
197
+ source = " ebssurrogate/files/ebsnvme-id "
198
+ destination = " /tmp/ebsnvme-id "
177
199
}
178
200
179
201
provisioner "file" {
180
- source = " scripts"
181
- destination = " /tmp/ansible-playbook"
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"
182
224
}
183
225
184
226
provisioner "file" {
@@ -191,15 +233,45 @@ build {
191
233
destination = " /tmp"
192
234
}
193
235
236
+ # Copy ansible playbook
237
+ provisioner "shell" {
238
+ inline = [" mkdir /tmp/ansible-playbook" ]
239
+ }
240
+
241
+ provisioner "file" {
242
+ source = " ansible"
243
+ destination = " /tmp/ansible-playbook"
244
+ }
245
+
246
+ provisioner "file" {
247
+ source = " scripts"
248
+ destination = " /tmp/ansible-playbook"
249
+ }
250
+
251
+ provisioner "file" {
252
+ source = " ansible/vars.yml"
253
+ destination = " /tmp/ansible-playbook/vars.yml"
254
+ }
255
+
194
256
provisioner "shell" {
195
257
environment_vars = [
196
- " POSTGRES_SUPABASE_VERSION=${ var . postgres-version } " ,
197
- " GIT_SHA=${ var . git_sha } "
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 } "
198
264
]
199
265
use_env_var_file = true
200
266
script = " ebssurrogate/scripts/surrogate-bootstrap-nix.sh"
201
- execute_command = " sudo -S sh -c '. {{.EnvVarFile}} && cd /tmp/ansible-playbook && {{.Path}}'"
267
+ execute_command = " sudo -S sh -c '. {{.EnvVarFile}} && {{.Path}}'"
202
268
start_retry_timeout = " 5m"
203
269
skip_clean = true
204
270
}
271
+
272
+ provisioner "file" {
273
+ source = " /tmp/ansible.log"
274
+ destination = " /tmp/ansible.log"
275
+ direction = " download"
276
+ }
205
277
}
0 commit comments