Skip to content

Commit e82dd6d

Browse files
committed
feat: retain old and new ansible/packer files until change is complete
1 parent 3e9e76c commit e82dd6d

File tree

125 files changed

+5896
-78
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+5896
-78
lines changed

amazon-arm64-nix.pkr.hcl

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
variable "ami" {
2+
type = string
3+
default = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-arm64-server-*"
4+
}
5+
6+
variable "profile" {
7+
type = string
8+
default = "${env("AWS_PROFILE")}"
9+
}
10+
11+
variable "ami_name" {
12+
type = string
13+
default = "supabase-postgres"
14+
}
15+
16+
variable "ami_regions" {
17+
type = list(string)
18+
default = ["ap-southeast-2"]
19+
}
20+
21+
variable "ansible_arguments" {
22+
type = string
23+
default = "--skip-tags install-postgrest,install-pgbouncer,install-supabase-internal"
24+
}
25+
26+
variable "aws_access_key" {
27+
type = string
28+
default = ""
29+
}
30+
31+
variable "aws_secret_key" {
32+
type = string
33+
default = ""
34+
}
35+
36+
variable "environment" {
37+
type = string
38+
default = "prod"
39+
}
40+
41+
variable "region" {
42+
type = string
43+
}
44+
45+
variable "build-vol" {
46+
type = string
47+
default = "xvdc"
48+
}
49+
50+
# ccache docker image details
51+
variable "docker_user" {
52+
type = string
53+
default = ""
54+
}
55+
56+
variable "docker_passwd" {
57+
type = string
58+
default = ""
59+
}
60+
61+
variable "docker_image" {
62+
type = string
63+
default = ""
64+
}
65+
66+
variable "docker_image_tag" {
67+
type = string
68+
default = "latest"
69+
}
70+
71+
locals {
72+
creator = "packer"
73+
}
74+
75+
variable "postgres-version" {
76+
type = string
77+
default = ""
78+
}
79+
80+
variable "git-head-version" {
81+
type = string
82+
default = "unknown"
83+
}
84+
85+
variable "packer-execution-id" {
86+
type = string
87+
default = "unknown"
88+
}
89+
90+
variable "force-deregister" {
91+
type = bool
92+
default = false
93+
}
94+
95+
packer {
96+
required_plugins {
97+
amazon = {
98+
source = "github.com/hashicorp/amazon"
99+
version = "~> 1"
100+
}
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"
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+
}
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}"
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
185+
}
186+
187+
# a build block invokes sources and runs provisioning steps on them.
188+
build {
189+
sources = ["source.amazon-ebssurrogate.source"]
190+
191+
provisioner "file" {
192+
source = "ebssurrogate/files/sources-arm64.cfg"
193+
destination = "/tmp/sources.list"
194+
}
195+
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.sh"
208+
destination = "/tmp/chroot-bootstrap.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+
}
230+
231+
provisioner "file" {
232+
source = "ebssurrogate/files/unit-tests"
233+
destination = "/tmp"
234+
}
235+
236+
# Copy ansible playbook
237+
provisioner "shell" {
238+
inline = ["mkdir /tmp/ansible-playbook"]
239+
}
240+
241+
provisioner "file" {
242+
source = "ansible-nix"
243+
destination = "/tmp/ansible-playbook"
244+
}
245+
246+
provisioner "file" {
247+
source = "scripts"
248+
destination = "/tmp/ansible-playbook"
249+
}
250+
251+
provisioner "shell" {
252+
environment_vars = [
253+
"ARGS=${var.ansible_arguments}",
254+
"DOCKER_USER=${var.docker_user}",
255+
"DOCKER_PASSWD=${var.docker_passwd}",
256+
"DOCKER_IMAGE=${var.docker_image}",
257+
"DOCKER_IMAGE_TAG=${var.docker_image_tag}",
258+
"POSTGRES_SUPABASE_VERSION=${var.postgres-version}"
259+
]
260+
use_env_var_file = true
261+
script = "ebssurrogate/scripts/surrogate-bootstrap.sh"
262+
execute_command = "sudo -S sh -c '. {{.EnvVarFile}} && {{.Path}}'"
263+
start_retry_timeout = "5m"
264+
skip_clean = true
265+
}
266+
267+
provisioner "file" {
268+
source = "/tmp/ansible.log"
269+
destination = "/tmp/ansible.log"
270+
direction = "download"
271+
}
272+
}

amazon-arm64.pkr.hcl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ source "amazon-ebssurrogate" "source" {
106106
profile = "${var.profile}"
107107
#access_key = "${var.aws_access_key}"
108108
#ami_name = "${var.ami_name}-arm64-${formatdate("YYYY-MM-DD-hhmm", timestamp())}"
109-
ami_name = "${var.ami_name}-${var.postgres-version}-stage-1"
109+
ami_name = "${var.ami_name}-${var.postgres-version}"
110110
ami_virtualization_type = "hvm"
111111
ami_architecture = "arm64"
112112
ami_regions = "${var.ami_regions}"
@@ -270,10 +270,9 @@ build {
270270
direction = "download"
271271
}
272272

273-
// provisioner "file" {
274-
// source = "/tmp/pg_binaries.tar.gz"
275-
// destination = "/tmp/pg_binaries.tar.gz"
276-
// direction = "download"
277-
// }
278-
// TODO RESOLVE IN NEW BUILD
273+
provisioner "file" {
274+
source = "/tmp/pg_binaries.tar.gz"
275+
destination = "/tmp/pg_binaries.tar.gz"
276+
direction = "download"
277+
}
279278
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
VOLUME_TYPE=${1:-data}
6+
7+
if [ -b /dev/nvme1n1 ] ; then
8+
if [[ "${VOLUME_TYPE}" == "data" ]]; then
9+
resize2fs /dev/nvme1n1
10+
11+
elif [[ "${VOLUME_TYPE}" == "root" ]] ; then
12+
growpart /dev/nvme0n1 2
13+
resize2fs /dev/nvme0n1p2
14+
15+
else
16+
echo "Invalid disk specified: ${VOLUME_TYPE}"
17+
exit 1
18+
fi
19+
else
20+
growpart /dev/nvme0n1 2
21+
resize2fs /dev/nvme0n1p2
22+
fi
23+
echo "Done resizing disk"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#! /usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
SUBCOMMAND=$1
6+
7+
function set_mode {
8+
MODE=$1
9+
psql -h localhost -U supabase_admin -d postgres -c "ALTER SYSTEM SET default_transaction_read_only to ${MODE};"
10+
psql -h localhost -U supabase_admin -d postgres -c "SELECT pg_reload_conf();"
11+
}
12+
13+
function check_override {
14+
COMMAND=$(cat <<EOF
15+
WITH role_comment as (
16+
SELECT pg_catalog.shobj_description(r.oid, 'pg_authid') AS content
17+
FROM pg_catalog.pg_roles r
18+
WHERE r.rolname = 'postgres'
19+
)
20+
SELECT
21+
CASE
22+
WHEN role_comment.content LIKE 'readonly mode overridden until%' THEN
23+
(NOW() < to_timestamp(role_comment.content, '"readonly mode overridden until "YYYY-MM-DD\THH24:MI:SS'))::int
24+
ELSE 0
25+
END as override_active
26+
FROM role_comment;
27+
EOF
28+
)
29+
RESULT=$(psql -h localhost -U supabase_admin -d postgres -At -c "$COMMAND")
30+
echo -n "$RESULT"
31+
}
32+
33+
case $SUBCOMMAND in
34+
"check_override")
35+
check_override
36+
;;
37+
"set")
38+
shift
39+
set_mode "$@"
40+
;;
41+
*)
42+
echo "Error: '$SUBCOMMAND' is not a known subcommand."
43+
exit 1
44+
;;
45+
esac

0 commit comments

Comments
 (0)