Skip to content

Commit 70d861c

Browse files
committed
chore: better os-version specific handling
1 parent 09734d9 commit 70d861c

File tree

9 files changed

+56
-30
lines changed

9 files changed

+56
-30
lines changed

.github/workflows/ami-build-ubuntu-18.yml

+12-11
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ name: Build Ubuntu 18 AMI
22

33
on:
44
push:
5-
branches:
6-
- develop
7-
- pcnc/build-glibc227-bin
8-
# paths:
9-
# - '.github/workflows/ami-build-ubuntu-18.yml'
10-
# - 'common.vars.pkr.hcl'
5+
paths:
6+
- '.github/workflows/ami-build-ubuntu-18.yml'
7+
workflow_run:
8+
workflows: [Release AMI]
9+
types:
10+
- completed
11+
1112
workflow_dispatch:
1213

1314
jobs:
@@ -26,8 +27,7 @@ jobs:
2627
- name: Build AMI
2728
run: |
2829
GIT_SHA=${{github.sha}}
29-
# packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=u18-${GITHUB_RUN_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common.vars.pkr.hcl" -var "ami=ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-arm64-server-*" -var "ami_name=builder-supabase-postgres-u18" -var ansible_arguments="ebssurrogate_mode='true' --skip-tags 'install-supabase-internal,migrations,unit-tests'" amazon-arm64.pkr.hcl
30-
packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=u18-${GITHUB_RUN_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common.vars.pkr.hcl" -var "ami=ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-arm64-server-*" -var "ami_name=builder-supabase-postgres-u18" -var ansible_arguments="ebssurrogate_mode='true' --skip-tags 'install-supabase-internal,ubuntu-18-incompatible'" amazon-arm64.pkr.hcl
30+
packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=u18-${GITHUB_RUN_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common.vars.pkr.hcl" -var-file="legacy.vars.pkr.hcl" amazon-arm64.pkr.hcl
3131
3232
- name: Grab release version
3333
id: process_release_version
@@ -58,21 +58,22 @@ jobs:
5858

5959
- name: Upload pg binaries to s3 prod
6060
run: |
61-
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.PROD_ARTIFACTS_BUCKET }}/upgrades/postgres/${{ steps.process_release_version.outputs.version }}/20.04.tar.gz
61+
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.PROD_ARTIFACTS_BUCKET }}/upgrades/postgres/${{ steps.process_release_version.outputs.version }}/18.04.tar.gz
6262
6363
- name: Deregister image
6464
if: ${{ always() }}
65+
continue-on-error: true
6566
run: |
6667
IMAGE_IDS=$(aws ec2 describe-images --filters "Name=name,Values=builder-supabase-postgres-u18-*" --query "Images[] .ImageId" --output text)
6768
for IMAGE_ID in $IMAGE_IDS; do
6869
SNAPSHOTS=$(aws ec2 describe-images --image-ids $IMAGE_ID --query "Images[*].BlockDeviceMappings[*].Ebs.SnapshotId" --output text)
6970
7071
echo "Deregistering image $IMAGE_ID"
71-
# aws ec2 deregister-image --image-id $IMAGE_ID
72+
aws ec2 deregister-image --image-id $IMAGE_ID
7273
7374
for SNAPSHOT in $SNAPSHOTS; do
7475
echo "Deleting snapshot $SNAPSHOT"
75-
# aws ec2 delete-snapshot --snapshot-id $SNAPSHOT
76+
aws ec2 delete-snapshot --snapshot-id $SNAPSHOT
7677
done
7778
done
7879

.github/workflows/ami-release.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Build AMI
2626
run: |
2727
GIT_SHA=${{github.sha}}
28-
packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common.vars.pkr.hcl" amazon-arm64.pkr.hcl
28+
packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common.vars.pkr.hcl" -var "ansible_arguments=" amazon-arm64.pkr.hcl
2929
3030
- name: Grab release version
3131
id: process_release_version
@@ -47,6 +47,10 @@ jobs:
4747
-e "internal_artifacts_bucket=${{ secrets.ARTIFACTS_BUCKET }}" \
4848
manifest-playbook.yml
4949
50+
- name: Upload pg binaries to s3 staging
51+
run: |
52+
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.ARTIFACTS_BUCKET }}/upgrades/postgres/${{ steps.process_release_version.outputs.version }}/20.04.tar.gz
53+
5054
- name: configure aws credentials - prod
5155
uses: aws-actions/configure-aws-credentials@v1
5256
with:
@@ -61,6 +65,10 @@ jobs:
6165
-e "internal_artifacts_bucket=${{ secrets.PROD_ARTIFACTS_BUCKET }}" \
6266
manifest-playbook.yml
6367
68+
- name: Upload pg binaries to s3 prod
69+
run: |
70+
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.PROD_ARTIFACTS_BUCKET }}/upgrades/postgres/${{ steps.process_release_version.outputs.version }}/20.04.tar.gz
71+
6472
- name: Create release
6573
uses: softprops/action-gh-release@v1
6674
with:

amazon-arm64.pkr.hcl

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ variable "ami_regions" {
2020

2121
variable "ansible_arguments" {
2222
type = string
23-
default = "--skip-tags,install-postgrest,--skip-tags,install-pgbouncer,--skip-tags,install-supabase-internal,ebssurrogate_mode='true'"
23+
default = "--skip-tags install-postgrest,install-pgbouncer,install-supabase-internal"
2424
}
2525

2626
variable "aws_access_key" {
@@ -239,8 +239,9 @@ build {
239239
"DOCKER_IMAGE=${var.docker_image}",
240240
"DOCKER_IMAGE_TAG=${var.docker_image_tag}"
241241
]
242+
use_env_var_file = true
242243
script = "ebssurrogate/scripts/surrogate-bootstrap.sh"
243-
execute_command = "sudo -S sh -c '{{ .Vars }} {{ .Path }}'"
244+
execute_command = "sudo -S sh -c '. {{.EnvVarFile}} && {{.Path}}'"
244245
start_retry_timeout = "5m"
245246
skip_clean = true
246247
}

ansible/playbook.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,4 @@
172172
- name: Collect Postgres binaries
173173
import_tasks: tasks/internal/collect-pg-binaries.yml
174174
tags:
175-
- install-supabase-internal
175+
- collect-binaries

ansible/tasks/setup-extensions.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
- name: Install pljava
4141
import_tasks: tasks/postgres-extensions/12-pljava.yml
42+
tags:
43+
- legacy-incompatible
4244

4345
- name: Install pg_plan_filter
4446
import_tasks: tasks/postgres-extensions/14-pg_plan_filter.yml
@@ -58,7 +60,7 @@
5860
- name: Install pg_graphql
5961
import_tasks: tasks/postgres-extensions/19-pg_graphql.yml
6062
tags:
61-
- ubuntu-18-incompatible
63+
- legacy-incompatible
6264

6365
- name: Install pg_stat_monitor
6466
import_tasks: tasks/postgres-extensions/20-pg_stat_monitor.yml

common.vars.pkr.hcl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
postgres-version = "15.1.0.67"
1+
postgres-version = "15.1.0.67-versioned-bins-4"

ebssurrogate/scripts/surrogate-bootstrap.sh

+17-11
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ function install_packages {
4040
gdisk \
4141
e2fsprogs \
4242
debootstrap \
43-
nvme-cli \
44-
docker.io
45-
43+
nvme-cli
4644
}
4745

4846
# Partition the new root EBS volume
@@ -126,6 +124,7 @@ function format_build_partition {
126124
mkfs.ext4 -O ^has_journal /dev/xvdc
127125
}
128126
function pull_docker {
127+
apt-get install -y docker.io
129128
docker run -itd --name ccachedata "${DOCKER_IMAGE}:${DOCKER_IMAGE_TAG}" sh
130129
docker exec -itd ccachedata mkdir -p /build/ccache
131130
}
@@ -213,8 +212,8 @@ callbacks_enabled = timer, profile_tasks, profile_roles
213212
EOF
214213
# Run Ansible playbook
215214
#export ANSIBLE_LOG_PATH=/tmp/ansible.log && export ANSIBLE_DEBUG=True && export ANSIBLE_REMOTE_TEMP=/mnt/tmp
216-
export ANSIBLE_LOG_PATH=/tmp/ansible.log && export ANSIBLE_REMOTE_TEMP=/mnt/tmp
217-
ansible-playbook -c chroot -i '/mnt,' /tmp/ansible-playbook/ansible/playbook.yml --extra-vars " $ARGS"
215+
export ANSIBLE_LOG_PATH=/tmp/ansible.log && export ANSIBLE_REMOTE_TEMP=/mnt/tmp
216+
ansible-playbook -c chroot -i '/mnt,' /tmp/ansible-playbook/ansible/playbook.yml $ARGS
218217
}
219218

220219
function update_systemd_services {
@@ -246,20 +245,27 @@ function clean_system {
246245
touch /mnt/var/log/auth.log
247246

248247
touch /mnt/var/log/pgbouncer.log
249-
chroot /mnt /usr/bin/chown pgbouncer:postgres /var/log/pgbouncer.log
248+
if [ -f /usr/bin/chown ]; then
249+
chroot /mnt /usr/bin/chown pgbouncer:postgres /var/log/pgbouncer.log
250+
fi
250251

251252
# Setup postgresql logs
252253
mkdir -p /mnt/var/log/postgresql
253-
chroot /mnt /usr/bin/chown postgres:postgres /var/log/postgresql
254+
if [ -f /usr/bin/chown ]; then
255+
chroot /mnt /usr/bin/chown postgres:postgres /var/log/postgresql
256+
fi
254257

255258
# Setup wal-g logs
256259
mkdir /mnt/var/log/wal-g
257260
touch /mnt/var/log/wal-g/{backup-push.log,backup-fetch.log,wal-push.log,wal-fetch.log}
258-
chroot /mnt /usr/bin/chown -R postgres:postgres /var/log/wal-g
259-
chroot /mnt /usr/bin/chmod -R 0300 /var/log/wal-g
260261

261-
# audit logs directory for apparmor
262-
mkdir /mnt/var/log/audit
262+
if [ -f /usr/bin/chown ]; then
263+
chroot /mnt /usr/bin/chown -R postgres:postgres /var/log/wal-g
264+
chroot /mnt /usr/bin/chmod -R 0300 /var/log/wal-g
265+
fi
266+
267+
# audit logs directory for apparmor
268+
mkdir /mnt/var/log/audit
263269

264270
# unwanted files
265271
rm -rf /mnt/var/lib/apt/lists/*

legacy.vars.pkr.hcl

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ansible_arguments="--skip-tags install-supabase-internal,install-pgbouncer,legacy-incompatible,migrations,unit-tests,aws-only"
2+
ami_name="builder-supabase-postgres-u18"
3+
ami="ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-arm64-server-*"

scripts/90-cleanup.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ elif [ -n "$(command -v apt-get)" ]; then
3636
libicu-dev \
3737
libcgal-dev \
3838
libgcc-9-dev \
39-
libgcc-8-dev \
40-
linux-headers-5.11.0-1021-aws
39+
libgcc-8-dev
40+
41+
source /etc/os-release
42+
if [ "${UBUNTU_VERSION}" != "bionic" ]; then
43+
apt-get -y remove --purge linux-headers-5.11.0-1021-aws
44+
fi
45+
4146
apt-get -y update
4247
apt-get -y upgrade
4348
apt-get -y autoremove

0 commit comments

Comments
 (0)