Skip to content

Commit 4c2aa5b

Browse files
committed
chore: avoid using ansible globbing
1 parent a3cce04 commit 4c2aa5b

File tree

3 files changed

+157
-122
lines changed

3 files changed

+157
-122
lines changed

amazon-arm64-nix.pkr.hcl

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

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

45-
# variable "region" {
46-
# type = string
47-
# }
48-
4945
variable "build-vol" {
5046
type = string
5147
default = "xvdc"
@@ -102,83 +98,129 @@ packer {
10298
source = "github.com/hashicorp/amazon"
10399
version = "~> 1"
104100
}
105-
qemu = {
106-
version = "~> 1.0"
107-
source = "github.com/hashicorp/qemu"
108-
}
109101
}
110102
}
111103

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
115117

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+
}
119135

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
163185
}
164186

187+
# a build block invokes sources and runs provisioning steps on them.
165188
build {
166-
name = "cloudimg.image"
167-
sources = ["source.qemu.cloudimg"]
189+
sources = ["source.amazon-ebssurrogate.source"]
168190

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"
172194
}
173195

174196
provisioner "file" {
175-
source = "ansible"
176-
destination = "/tmp/ansible-playbook"
197+
source = "ebssurrogate/files/ebsnvme-id"
198+
destination = "/tmp/ebsnvme-id"
177199
}
178200

179201
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"
182224
}
183225

184226
provisioner "file" {
@@ -191,15 +233,45 @@ build {
191233
destination = "/tmp"
192234
}
193235

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+
194256
provisioner "shell" {
195257
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}"
198264
]
199265
use_env_var_file = true
200266
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}}'"
202268
start_retry_timeout = "5m"
203269
skip_clean = true
204270
}
271+
272+
provisioner "file" {
273+
source = "/tmp/ansible.log"
274+
destination = "/tmp/ansible.log"
275+
direction = "download"
276+
}
205277
}

ansible/tasks/setup-postgres.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,6 @@
218218
shell: source /var/lib/postgresql/.bashrc && /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data initdb -o "--allow-group-access" -o "--username=supabase_admin"
219219
args:
220220
executable: /bin/bash
221-
environment:
222-
LANG: en_US.UTF-8
223-
LANGUAGE: en_US.UTF-8
224-
LC_ALL: en_US.UTF-8
225-
LC_CTYPE: en_US.UTF-8
226-
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
227221
vars:
228222
ansible_command_timeout: 60
229223
# Circumvents the following error:

ansible/tasks/stage2-setup-postgres.yml

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,11 @@
107107
when: stage2_nix
108108

109109
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/bin to /usr/lib/postgresql/bin
110-
file:
111-
src: "{{ item }}"
112-
dest: "/usr/lib/postgresql/bin/{{ item | basename }}"
113-
state: link
114-
with_fileglob:
115-
- "/var/lib/postgresql/.nix-profile/bin/*"
110+
shell: >-
111+
find /var/lib/postgresql/.nix-profile/bin/ -maxdepth 1 -type f,l -exec sh -c 'ln -s "$0" "{{ item }}/$(basename $0)"' {} \;
112+
loop:
113+
- /usr/lib/postgresql/bin
114+
- /usr/bin
116115
become: yes
117116
when: stage2_nix
118117

@@ -129,23 +128,9 @@
129128
when: pg_config_stat.stat.exists and not pg_config_stat.stat.islnk and stage2_nix
130129
become: yes
131130

132-
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/bin to /usr/bin
133-
file:
134-
src: "{{ item }}"
135-
dest: "/usr/bin/{{ item | basename }}"
136-
state: link
137-
with_fileglob:
138-
- "/var/lib/postgresql/.nix-profile/bin/*"
139-
become: yes
140-
when: stage2_nix
141-
142131
- name: Ensure postgres user has ownership of symlink
143-
file:
144-
path: "/usr/bin/{{ item | basename }}"
145-
owner: postgres
146-
group: postgres
147-
with_fileglob:
148-
- "/var/lib/postgresql/.nix-profile/bin/*"
132+
shell: >-
133+
find /var/lib/postgresql/.nix-profile/bin/ -maxdepth 1 -type f,l -exec chown postgres:postgres "/usr/bin/$(basename {})" \;
149134
become: yes
150135
when: stage2_nix
151136

@@ -160,22 +145,14 @@
160145
# It was decided to leave pljava disabled at https://github.com/supabase/postgres/pull/690 therefore removing this task
161146

162147
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/share/postgresql to /usr/lib/postgresql/share/postgresql
163-
file:
164-
src: "{{ item }}"
165-
dest: "/usr/lib/postgresql/share/postgresql/{{ item | basename }}"
166-
state: link
167-
with_fileglob:
168-
- "/var/lib/postgresql/.nix-profile/share/postgresql/*"
148+
shell: >-
149+
find /var/lib/postgresql/.nix-profile/share/postgresql/ -maxdepth 1 -type f,l -exec sh -c 'ln -s "$0" "/usr/lib/postgresql/share/postgresql/$(basename $0)"' {} \;
169150
become: yes
170151
when: stage2_nix
171152

172153
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/share/postgresql/extension to /usr/lib/postgresql/share/postgresql/extension
173-
file:
174-
src: "{{ item }}"
175-
dest: "/usr/lib/postgresql/share/postgresql/extension/{{ item | basename }}"
176-
state: link
177-
with_fileglob:
178-
- "/var/lib/postgresql/.nix-profile/share/postgresql/extension/*"
154+
shell: >-
155+
find /var/lib/postgresql/.nix-profile/share/postgresql/extension/ -maxdepth 1 -type f,l -exec sh -c 'ln -s "$0" "/usr/lib/postgresql/share/postgresql/extension/$(basename $0)"' {} \;
179156
become: yes
180157
when: stage2_nix
181158

@@ -195,22 +172,14 @@
195172
when: stage2_nix
196173

197174
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/share/postgresql/timezonesets to /usr/lib/postgresql/share/postgresql/timeszonesets
198-
file:
199-
src: "{{ item }}"
200-
dest: "/usr/lib/postgresql/share/postgresql/timezonesets/{{ item | basename }}"
201-
state: link
202-
with_fileglob:
203-
- "/var/lib/postgresql/.nix-profile/share/postgresql/timezonesets/*"
175+
shell: >-
176+
find /var/lib/postgresql/.nix-profile/share/postgresql/timezonesets/ -maxdepth 1 -type f,l -exec sh -c 'ln -s "$0" "/usr/lib/postgresql/share/postgresql/timezonesets/$(basename $0)"' {} \;
204177
become: yes
205178
when: stage2_nix
206179

207180
- name: Create symbolic links from /var/lib/postgresql/.nix-profile/share/postgresql/tsearch_data to /usr/lib/postgresql/share/postgresql/tsearch_data
208-
file:
209-
src: "{{ item }}"
210-
dest: "/usr/lib/postgresql/share/postgresql/tsearch_data/{{ item | basename }}"
211-
state: link
212-
with_fileglob:
213-
- "/var/lib/postgresql/.nix-profile/share/postgresql/tsearch_data/*"
181+
shell: >-
182+
find /var/lib/postgresql/.nix-profile/share/postgresql/tsearch_data/ -maxdepth 1 -type f,l -exec sh -c 'ln -s "$0" "/usr/lib/postgresql/share/postgresql/tsearch_data/$(basename $0)"' {} \;
214183
become: yes
215184
when: stage2_nix
216185

0 commit comments

Comments
 (0)