Skip to content

Commit 55b705e

Browse files
authored
Merge pull request #3 from supabase/develop
updating the postgres.
2 parents 47ae98d + 4433e21 commit 55b705e

File tree

19 files changed

+528
-75
lines changed

19 files changed

+528
-75
lines changed

.github/workflows/ami-release-nix-single.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ jobs:
4040
run: |
4141
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
4242
43-
- uses: DeterminateSystems/nix-installer-action@main
43+
- name: Install nix
44+
uses: cachix/install-nix-action@v27
45+
with:
46+
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
47+
extra_nix_config: |
48+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
49+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
4450
4551
- name: Set PostgreSQL version environment variable
4652
run: echo "POSTGRES_MAJOR_VERSION=${{ github.event.inputs.postgres_version }}" >> $GITHUB_ENV
@@ -57,18 +63,18 @@ jobs:
5763
env:
5864
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
5965
run: |
60-
packer init amazon-arm64-nix.pkr.hcl
6166
GIT_SHA=${{ steps.get_sha.outputs.sha }}
62-
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-nix.vars.pkr.hcl" -var "ansible_arguments=-e postgresql_major=${POSTGRES_MAJOR_VERSION}" amazon-arm64-nix.pkr.hcl
67+
nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
68+
nix run github:supabase/postgres/${GIT_SHA}#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-nix.vars.pkr.hcl" -var "ansible_arguments=-e postgresql_major=${POSTGRES_MAJOR_VERSION}" amazon-arm64-nix.pkr.hcl
6369
6470
- name: Build AMI stage 2
6571
env:
6672
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
6773
run: |
68-
packer init stage2-nix-psql.pkr.hcl
6974
GIT_SHA=${{ steps.get_sha.outputs.sha }}
75+
nix run github:supabase/postgres/${GIT_SHA}#packer -- init stage2-nix-psql.pkr.hcl
7076
POSTGRES_MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
71-
packer build -var "git_sha=${GIT_SHA}" -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var "postgres_major_version=${POSTGRES_MAJOR_VERSION}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" stage2-nix-psql.pkr.hcl
77+
nix run github:supabase/postgres/${GIT_SHA}#packer -- build -var "git_sha=${GIT_SHA}" -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var "postgres_major_version=${POSTGRES_MAJOR_VERSION}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" stage2-nix-psql.pkr.hcl
7278
7379
- name: Grab release version
7480
id: process_release_version

.github/workflows/ami-release-nix.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ jobs:
1616
- name: Checkout Repo
1717
uses: supabase/postgres/.github/actions/shared-checkout@HEAD
1818

19-
- uses: DeterminateSystems/nix-installer-action@main
19+
- name: Install nix
20+
uses: cachix/install-nix-action@v27
21+
with:
22+
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
23+
extra_nix_config: |
24+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
25+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
2026
2127
- name: Set PostgreSQL versions
2228
id: set-versions
@@ -44,7 +50,14 @@ jobs:
4450
aws-region: "us-east-1"
4551
output-credentials: true
4652
role-duration-seconds: 7200
47-
- uses: DeterminateSystems/nix-installer-action@main
53+
54+
- name: Install nix
55+
uses: cachix/install-nix-action@v27
56+
with:
57+
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
58+
extra_nix_config: |
59+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
60+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
4861
4962
- name: Run checks if triggered manually
5063
if: ${{ github.event_name == 'workflow_dispatch' }}
@@ -70,19 +83,19 @@ jobs:
7083
env:
7184
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
7285
run: |
73-
packer init amazon-arm64-nix.pkr.hcl
7486
GIT_SHA=${{github.sha}}
87+
nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
7588
# why is postgresql_major defined here instead of where the _three_ other postgresql_* variables are defined?
76-
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-nix.vars.pkr.hcl" -var "ansible_arguments=-e postgresql_major=${POSTGRES_MAJOR_VERSION}" amazon-arm64-nix.pkr.hcl
89+
nix run github:supabase/postgres/${GIT_SHA}#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-nix.vars.pkr.hcl" -var "ansible_arguments=-e postgresql_major=${POSTGRES_MAJOR_VERSION}" amazon-arm64-nix.pkr.hcl
7790
7891
- name: Build AMI stage 2
7992
env:
8093
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
8194
run: |
82-
packer init stage2-nix-psql.pkr.hcl
8395
GIT_SHA=${{github.sha}}
96+
nix run github:supabase/postgres/${GIT_SHA}#packer -- init stage2-nix-psql.pkr.hcl
8497
POSTGRES_MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
85-
packer build -var "git_sha=${GIT_SHA}" -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var "postgres_major_version=${POSTGRES_MAJOR_VERSION}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" stage2-nix-psql.pkr.hcl
98+
nix run github:supabase/postgres/${GIT_SHA}#packer -- build -var "git_sha=${GIT_SHA}" -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var "postgres_major_version=${POSTGRES_MAJOR_VERSION}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" stage2-nix-psql.pkr.hcl
8699
87100
- name: Grab release version
88101
id: process_release_version

.github/workflows/nix-build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ jobs:
7777
- name: Aggressive disk cleanup for DuckDB build
7878
if: matrix.runner == 'macos-latest-xlarge'
7979
run: |
80+
nix --version
8081
echo "=== BEFORE CLEANUP ==="
8182
df -h
8283
# Remove major space consumers
@@ -112,6 +113,8 @@ jobs:
112113
needs: build-run-image
113114
if: ${{ success() }}
114115
uses: ./.github/workflows/testinfra-ami-build.yml
116+
secrets:
117+
DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }}
115118

116119
run-tests:
117120
needs: build-run-image

.github/workflows/qemu-image-build.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ jobs:
1616
- name: Checkout Repo
1717
uses: supabase/postgres/.github/actions/shared-checkout@HEAD
1818

19-
- uses: DeterminateSystems/nix-installer-action@main
20-
2119
- name: Set PostgreSQL versions - only builds pg17 atm
2220
id: set-versions
2321
run: |
24-
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[1]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
22+
VERSIONS=$(yq '.postgres_major[1]' ansible/vars.yml | jq -R -s -c 'split("\n")[:-1]')
2523
echo "postgres_versions=$VERSIONS" >> $GITHUB_OUTPUT
2624
2725
build:
@@ -45,7 +43,7 @@ jobs:
4543
- name: Run checks if triggered manually
4644
if: ${{ github.event_name == 'workflow_dispatch' }}
4745
run: |
48-
SUFFIX=$(sudo nix run nixpkgs#yq -- ".postgres_release[\"postgres${{ matrix.postgres_version }}\"]" ansible/vars.yml | sed -E 's/[0-9\.]+(.*)$/\1/')
46+
SUFFIX=$(yq ".postgres_release[\"postgres${{ matrix.postgres_version }}\"]" ansible/vars.yml | sed -E 's/[0-9\.]+(.*)$/\1/')
4947
if [[ -z $SUFFIX ]] ; then
5048
echo "Version must include non-numeric characters if built manually."
5149
exit 1
@@ -134,6 +132,16 @@ jobs:
134132
docker tag "postgres:$IMAGE_TAG" "$REGISTRY/$REPOSITORY:$IMAGE_TAG"
135133
docker push "$REGISTRY/$REPOSITORY:$IMAGE_TAG"
136134
135+
- name: Slack Notification on Failure
136+
if: ${{ failure() }}
137+
uses: rtCamp/action-slack-notify@v2
138+
env:
139+
SLACK_WEBHOOK: ${{ secrets.SLACK_NOTIFICATIONS_WEBHOOK }}
140+
SLACK_USERNAME: 'gha-failures-notifier'
141+
SLACK_COLOR: 'danger'
142+
SLACK_MESSAGE: 'Building Postgres QEMU artifact failed'
143+
SLACK_FOOTER: ''
144+
137145
- name: Cleanup resources after build
138146
if: ${{ always() }}
139147
run: |

.github/workflows/testinfra-ami-build.yml

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ name: Testinfra Integration Tests Nix
33
on:
44
workflow_dispatch:
55
workflow_call:
6+
secrets:
7+
DEV_AWS_ROLE:
8+
description: 'AWS role for dev environment'
9+
required: true
610

711
permissions:
8-
contents: read
12+
contents: write
913
id-token: write
1014

1115
jobs:
@@ -17,7 +21,13 @@ jobs:
1721
- name: Checkout Repo
1822
uses: supabase/postgres/.github/actions/shared-checkout@HEAD
1923

20-
- uses: DeterminateSystems/nix-installer-action@main
24+
- name: Install nix
25+
uses: cachix/install-nix-action@v27
26+
with:
27+
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
28+
extra_nix_config: |
29+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
30+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
2131
2232
- name: Set PostgreSQL versions
2333
id: set-versions
@@ -32,22 +42,44 @@ jobs:
3242
matrix:
3343
postgres_version: ${{ fromJson(needs.prepare.outputs.postgres_versions) }}
3444
include:
35-
- runner: arm-runner
45+
- runner: large-linux-arm
3646
arch: arm64
3747
ubuntu_release: noble
3848
ubuntu_version: 24.04
3949
mcpu: neoverse-n1
4050
runs-on: ${{ matrix.runner }}
4151
timeout-minutes: 150
42-
permissions:
43-
contents: write
44-
packages: write
45-
id-token: write
4652

4753
steps:
4854
- name: Checkout Repo
4955
uses: supabase/postgres/.github/actions/shared-checkout@HEAD
5056

57+
- name: Debug AWS role secret
58+
run: |
59+
echo "Checking DEV_AWS_ROLE secret availability..."
60+
if [ -z "${{ secrets.DEV_AWS_ROLE }}" ]; then
61+
echo "❌ DEV_AWS_ROLE is empty or not available"
62+
else
63+
echo "✅ DEV_AWS_ROLE is available"
64+
fi
65+
66+
- name: Configure AWS credentials
67+
uses: aws-actions/configure-aws-credentials@v4
68+
with:
69+
role-to-assume: ${{ secrets.DEV_AWS_ROLE }}
70+
aws-region: "us-east-1"
71+
output-credentials: true
72+
role-duration-seconds: 7200
73+
74+
- name: Install nix
75+
uses: cachix/install-nix-action@v27
76+
with:
77+
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
78+
extra_nix_config: |
79+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
80+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
81+
82+
5183
- id: args
5284
uses: mikefarah/yq@master
5385
with:
@@ -68,23 +100,23 @@ jobs:
68100

69101
- name: Generate common-nix.vars.pkr.hcl
70102
run: |
71-
PG_VERSION=$(sudo nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
103+
PG_VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
72104
PG_VERSION=$(echo "$PG_VERSION" | tr -d '"') # Remove any surrounding quotes
73105
echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
74106
# Ensure there's a newline at the end of the file
75107
echo "" >> common-nix.vars.pkr.hcl
76108
77109
- name: Build AMI stage 1
78110
run: |
79-
packer init amazon-arm64-nix.pkr.hcl
80111
GIT_SHA=${{github.sha}}
81-
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-nix.vars.pkr.hcl" -var "ansible_arguments=" -var "postgres-version=${{ steps.random.outputs.random_string }}" -var "region=ap-southeast-1" -var 'ami_regions=["ap-southeast-1"]' -var "force-deregister=true" -var "ansible_arguments=-e postgresql_major=${POSTGRES_MAJOR_VERSION}" amazon-arm64-nix.pkr.hcl
112+
nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
113+
nix run github:supabase/postgres/${GIT_SHA}#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-nix.vars.pkr.hcl" -var "ansible_arguments=" -var "postgres-version=${{ steps.random.outputs.random_string }}" -var "region=ap-southeast-1" -var 'ami_regions=["ap-southeast-1"]' -var "force-deregister=true" -var "ansible_arguments=-e postgresql_major=${POSTGRES_MAJOR_VERSION}" amazon-arm64-nix.pkr.hcl
82114
83115
- name: Build AMI stage 2
84116
run: |
85-
packer init stage2-nix-psql.pkr.hcl
86117
GIT_SHA=${{github.sha}}
87-
packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var "postgres_major_version=${POSTGRES_MAJOR_VERSION}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" -var "postgres-version=${{ steps.random.outputs.random_string }}" -var "region=ap-southeast-1" -var 'ami_regions=["ap-southeast-1"]' -var "force-deregister=true" -var "git_sha=${GITHUB_SHA}" stage2-nix-psql.pkr.hcl
118+
nix run github:supabase/postgres/${GIT_SHA}#packer -- init stage2-nix-psql.pkr.hcl
119+
nix run github:supabase/postgres/${GIT_SHA}#packer -- build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var "postgres_major_version=${POSTGRES_MAJOR_VERSION}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" -var "postgres-version=${{ steps.random.outputs.random_string }}" -var "region=ap-southeast-1" -var 'ami_regions=["ap-southeast-1"]' -var "force-deregister=true" -var "git_sha=${GITHUB_SHA}" stage2-nix-psql.pkr.hcl
88120
89121
- name: Run tests
90122
timeout-minutes: 10

ansible/files/admin_api_scripts/grow_fs.sh

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,61 @@ set -euo pipefail
44

55
VOLUME_TYPE=${1:-data}
66

7+
# lsb release
8+
UBUNTU_VERSION=$(lsb_release -rs)
9+
710
if pgrep resizefs; then
811
echo "resize2fs is already running"
912
exit 1
1013
fi
1114

12-
# Parses the output of lsblk to get the root partition number
13-
# Example output:
14-
# NAME MOUNTPOINT
15-
# nvme0n1
16-
# ├─nvme0n1p1 /boot
17-
# └─nvme0n1p3 /
18-
# nvme1n1 /data
19-
#
20-
# Resulting in:
21-
# └─nvme0n1p3 / -> nvme0n1p3 -> 3
22-
ROOT_PARTITION_NUMBER=$(lsblk -no NAME,MOUNTPOINT | grep ' /$' | awk '{print $1;}' | sed 's/.*nvme[0-9]n[0-9]p//g')
15+
# install amazon disk utilities if not present on 24.04
16+
if [ "${UBUNTU_VERSION}" = "24.04" ] && ! dpkg -l | grep -q amazon-ec2-utils; then
17+
apt-get update
18+
apt-get install -y amazon-ec2-utils || true
19+
fi
20+
21+
# We currently mount 3 possible disks
22+
# - /dev/xvda (root disk)
23+
# - /dev/xvdh (data disk)
24+
# - /dev/xvdp (upgrade data disk), not used here
25+
# Initialize variables at 20.04 levels
26+
XVDA_DEVICE="/dev/nvme0n1"
27+
XVDH_DEVICE="/dev/nvme1n1"
28+
# Map AWS devices to NVMe for ubuntu 24.04 and later
29+
if [ "${UBUNTU_VERSION}" = "24.04" ] && dpkg -l | grep -q amazon-ec2-utils; then
30+
for nvme_dev in $(lsblk -dprno name,type | grep disk | awk '{print $1}'); do
31+
if [ -b "$nvme_dev" ]; then
32+
mapping=$(ebsnvme-id -b "$nvme_dev" 2>/dev/null)
33+
case "$mapping" in
34+
"xvda"|"/dev/xvda") XVDA_DEVICE="$nvme_dev" ;;
35+
"xvdh"|"/dev/xvdh") XVDH_DEVICE="$nvme_dev" ;;
36+
esac
37+
fi
38+
done
39+
fi
40+
41+
echo "Using devices - Root: $XVDA_DEVICE, Data: $XVDH_DEVICE"
42+
43+
# Get root partition using findmnt
44+
ROOT_DEVICE_FULL=$(findmnt -no SOURCE /)
45+
ROOT_DEVICE=$(lsblk -no PKNAME "$ROOT_DEVICE_FULL")
46+
ROOT_PARTITION_NUMBER=$(echo "$ROOT_DEVICE_FULL" | sed "s|.*${ROOT_DEVICE}p||")
2347

2448
if ! [[ "$ROOT_PARTITION_NUMBER" =~ ^[0-9]+$ ]]; then
2549
echo "Error: ROOT_PARTITION_NUMBER is not a valid number: $ROOT_PARTITION_NUMBER"
2650
exit 1
2751
fi
2852

29-
if [ -b /dev/nvme1n1 ] ; then
53+
if [ -b "${XVDH_DEVICE}" ] ; then
3054
if [[ "${VOLUME_TYPE}" == "data" ]]; then
31-
resize2fs /dev/nvme1n1
55+
resize2fs "${XVDH_DEVICE}"
3256

3357
elif [[ "${VOLUME_TYPE}" == "root" ]] ; then
3458
PLACEHOLDER_FL=/home/ubuntu/50M_PLACEHOLDER
3559
rm -f "${PLACEHOLDER_FL}" || true
36-
growpart /dev/nvme0n1 "${ROOT_PARTITION_NUMBER}"
37-
resize2fs "/dev/nvme0n1p${ROOT_PARTITION_NUMBER}"
60+
growpart "${XVDA_DEVICE}" "${ROOT_PARTITION_NUMBER}"
61+
resize2fs "${XVDA_DEVICE}p${ROOT_PARTITION_NUMBER}"
3862
if [[ ! -f "${PLACEHOLDER_FL}" ]] ; then
3963
fallocate -l50M "${PLACEHOLDER_FL}"
4064
fi
@@ -43,7 +67,7 @@ if [ -b /dev/nvme1n1 ] ; then
4367
exit 1
4468
fi
4569
else
46-
growpart /dev/nvme0n1 "${ROOT_PARTITION_NUMBER}"
47-
resize2fs "/dev/nvme0n1p${ROOT_PARTITION_NUMBER}"
70+
growpart "${XVDA_DEVICE}" "${ROOT_PARTITION_NUMBER}"
71+
resize2fs "${XVDA_DEVICE}p${ROOT_PARTITION_NUMBER}"
4872
fi
4973
echo "Done resizing disk"

ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,28 @@ function initiate_upgrade {
348348
locale-gen
349349

350350
if [ -z "$IS_CI" ] && [ -z "$IS_LOCAL_UPGRADE" ]; then
351-
# awk NF==3 prints lines with exactly 3 fields, which are the block devices currently not mounted anywhere
352-
# excluding nvme0 since it is the root disk
351+
# DATABASE_UPGRADE_DATA_MIGRATION_DEVICE_NAME = '/dev/xvdp' can be derived from the worker mount
353352
echo "5. Determining block device to mount"
354-
BLOCK_DEVICE=$(lsblk -dprno name,size,mountpoint,type | grep "disk" | grep -v "nvme0" | awk 'NF==3 { print $1; }')
353+
if command -v ebsnvme-id >/dev/null 2>&1 && dpkg -l | grep -q amazon-ec2-utils; then
354+
for nvme_dev in $(lsblk -dprno name,size,mountpoint,type | grep disk | awk '{print $1}'); do
355+
if [ -b "$nvme_dev" ]; then
356+
mapping=$(ebsnvme-id -b "$nvme_dev" 2>/dev/null)
357+
if [[ "$mapping" == "xvdp" || $mapping == "/dev/xvdp" ]]; then
358+
BLOCK_DEVICE="$nvme_dev"
359+
break
360+
fi
361+
fi
362+
done
363+
fi
364+
365+
# Fallback to lsblk if ebsnvme-id is not available or no mapping found, pre ubuntu 20.04
366+
if [ -z "${BLOCK_DEVICE:-}" ]; then
367+
echo "No block device found using ebsnvme-id, falling back to lsblk"
368+
# awk NF==3 prints lines with exactly 3 fields, which are the block devices currently not mounted anywhere
369+
# excluding nvme0 since it is the root disk
370+
BLOCK_DEVICE=$(lsblk -dprno name,size,mountpoint,type | grep "disk" | grep -v "nvme0" | awk 'NF==3 { print $1; exit }') # exit ensures we grab the first only
371+
fi
372+
355373
echo "Block device found: $BLOCK_DEVICE"
356374

357375
mkdir -p "$MOUNT_POINT"

ansible/tasks/setup-supabase-internal.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
shell: "/tmp/aws/install --update"
3030
become: true
3131

32+
- name: install utilities to manage Amazon EC2 instance storage
33+
become: true
34+
apt:
35+
pkg:
36+
- amazon-ec2-utils
37+
3238
- name: AWS CLI - configure ipv6 support for s3
3339
shell: |
3440
aws configure set default.s3.use_dualstack_endpoint true

0 commit comments

Comments
 (0)