Skip to content

Commit bb5a7e1

Browse files
authored
Merge branch 'develop' into etienne/sec-493-switch-pg_hba-to-use-include-directive
2 parents 96ba894 + 752dd55 commit bb5a7e1

131 files changed

Lines changed: 4041 additions & 2354 deletions

File tree

Some content is hidden

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

.claude/skills/pg-security-release-analysis/SKILL.md

Lines changed: 327 additions & 0 deletions
Large diffs are not rendered by default.

.github/actions/build-ami/action.yml

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,27 @@ name: Build AMI
22
description: Build both stage 1 and stage 2 AMIs
33

44
inputs:
5-
postgres_version:
6-
description: 'PostgreSQL major version (e.g., 15)'
7-
required: true
8-
region:
9-
description: 'AWS region'
5+
ami_name_prefix:
6+
description: 'Prefix for the AMI name'
107
required: true
118
ami_regions:
129
description: 'AMI regions as JSON array (e.g., ["us-east-1"])'
1310
required: true
11+
arch:
12+
description: Architecture to build AMI for (amd64|arm64)
13+
required: true
1414
git_sha:
1515
description: 'Git SHA for this build'
1616
required: true
17-
ami_name_prefix:
18-
description: 'Prefix for the AMI name'
19-
required: false
20-
default: 'supabase-postgres'
17+
instance_type:
18+
description: 'EC2 instance type for the build'
19+
required: true
20+
postgres_version:
21+
description: 'PostgreSQL major version (e.g., 15)'
22+
required: true
23+
region:
24+
description: 'AWS region'
25+
required: true
2126

2227
outputs:
2328
stage2_ami_id:
@@ -33,6 +38,13 @@ outputs:
3338
runs:
3439
using: "composite"
3540
steps:
41+
- name: Verify arch
42+
shell: bash
43+
run: |
44+
case ${{ inputs.arch }} in
45+
amd64 | arm64) ;;
46+
*) echo "Unknown arch input, expected:(amd64|arm64) got:${{ inputs.arch }}" >&2 && exit 1 ;;
47+
esac
3648
- name: Set execution ID
3749
id: set-execution-id
3850
shell: bash
@@ -60,12 +72,12 @@ runs:
6072
AWS_RETRY_MODE: adaptive
6173
AWS_REGION: ${{ inputs.region }}
6274
run: |
63-
nix run .#build-ami -- stage1 \
75+
nix run .#build-ami -- stage1 ${{ inputs.arch }} \
6476
-var "git-head-version=${{ inputs.git_sha }}" \
6577
-var "packer-execution-id=${{ env.EXECUTION_ID }}" \
6678
-var "ansible_arguments=-e postgresql_major=${{ inputs.postgres_version }}" \
6779
-var 'ami_regions=${{ inputs.ami_regions }}' \
68-
amazon-arm64-nix.pkr.hcl
80+
amazon-${{ inputs.arch }}-nix.pkr.hcl
6981
7082
- name: Build AMI stage 2
7183
id: build-stage2
@@ -78,10 +90,11 @@ runs:
7890
AWS_RETRY_MODE: adaptive
7991
AWS_REGION: ${{ inputs.region }}
8092
run: |
81-
nix run .#build-ami -- stage2 \
93+
nix run .#build-ami -- stage2 ${{ inputs.arch }} \
8294
-var "git-head-version=${{ inputs.git_sha }}" \
8395
-var "packer-execution-id=${{ env.EXECUTION_ID }}" \
8496
-var "postgres_major_version=${{ inputs.postgres_version }}" \
8597
-var "ami_name=${{ inputs.ami_name_prefix }}" \
8698
-var "git_sha=${{ inputs.git_sha }}" \
99+
-var "instance_type=${{ inputs.instance_type }}" \
87100
stage2-nix-psql.pkr.hcl
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: 'Nix build with retry'
2+
description: |
3+
Runs `nix build --accept-flake-config -L` and retries on transient network
4+
errors (codeload.github.com 5xx, DNS, TLS, connection resets). Genuine build
5+
failures exit immediately without retrying.
6+
inputs:
7+
attr:
8+
description: 'The flake attribute to build, including the leading `.#`, e.g. `.#psql_17_cli_portable`'
9+
required: true
10+
extra-args:
11+
description: 'Additional arguments inserted between `-L` and the attribute, e.g. `--system aarch64-linux`'
12+
required: false
13+
default: ''
14+
attempts:
15+
description: 'Maximum number of attempts'
16+
required: false
17+
default: '3'
18+
initial-delay-seconds:
19+
description: 'Backoff before the second attempt; doubled before each subsequent attempt'
20+
required: false
21+
default: '30'
22+
23+
runs:
24+
using: 'composite'
25+
steps:
26+
- name: nix build (with retry)
27+
shell: bash
28+
env:
29+
ATTR: ${{ inputs.attr }}
30+
EXTRA_ARGS: ${{ inputs.extra-args }}
31+
ATTEMPTS: ${{ inputs.attempts }}
32+
INITIAL_DELAY: ${{ inputs.initial-delay-seconds }}
33+
run: |
34+
set -uo pipefail
35+
36+
log_file=$(mktemp)
37+
trap 'rm -f "$log_file"' EXIT
38+
39+
# Patterns that indicate a transient network/upstream failure rather
40+
# than a real build error. Keep conservative — false positives waste
41+
# CI minutes by re-running deterministic build failures.
42+
transient_re='HTTP error 5[0-9][0-9]|error: unable to download|Failed to open archive|Connection (reset|refused|timed out)|Couldn'\''t resolve host|Could not resolve host|unexpected end[- ]of[- ]file|SSL connection|TLS connection|Resource temporarily unavailable|Temporary failure in name resolution'
43+
44+
delay="$INITIAL_DELAY"
45+
rc=0
46+
for attempt in $(seq 1 "$ATTEMPTS"); do
47+
echo "::group::nix build attempt ${attempt}/${ATTEMPTS}: ${ATTR} ${EXTRA_ARGS}"
48+
# Stream to console AND capture for post-hoc pattern matching.
49+
# PIPESTATUS preserves nix's exit code through the tee.
50+
nix build --accept-flake-config -L ${EXTRA_ARGS} "${ATTR}" 2>&1 | tee "$log_file"
51+
rc=${PIPESTATUS[0]}
52+
echo "::endgroup::"
53+
54+
if [ "$rc" -eq 0 ]; then
55+
exit 0
56+
fi
57+
58+
if [ "$attempt" -ge "$ATTEMPTS" ]; then
59+
echo "::error::nix build failed after ${attempt} attempt(s) (exit ${rc})"
60+
exit "$rc"
61+
fi
62+
63+
if grep -qE "$transient_re" "$log_file"; then
64+
echo "::warning::Transient error on attempt ${attempt}; sleeping ${delay}s then retrying"
65+
sleep "$delay"
66+
delay=$((delay * 2))
67+
else
68+
echo "::error::nix build failed with non-transient error on attempt ${attempt} (exit ${rc}); not retrying"
69+
exit "$rc"
70+
fi
71+
done
72+
73+
# Defensive — loop should always exit via one of the branches above.
74+
exit "$rc"

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

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,21 @@ on:
1212
required: true
1313
type: string
1414
default: 'main'
15+
arch:
16+
description: 'Architecture to build'
17+
required: true
18+
type: choice
19+
options:
20+
- arm64
21+
- amd64
1522

1623
permissions:
1724
contents: write
1825
id-token: write
1926

2027
jobs:
2128
build:
22-
runs-on: large-linux-arm
29+
runs-on: ${{ github.event.inputs.arch == 'amd64' && 'blacksmith-2vcpu-ubuntu-2404' || 'large-linux-arm' }}
2330
timeout-minutes: 150
2431

2532
steps:
@@ -41,6 +48,25 @@ jobs:
4148
run: |
4249
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
4350
51+
- name: Set arch-specific variables
52+
id: arch_vars
53+
run: |
54+
ARCH="${{ github.event.inputs.arch }}"
55+
echo "arch=$ARCH" >>"$GITHUB_OUTPUT"
56+
if [ "$ARCH" = "amd64" ]; then
57+
{
58+
echo "ami_name_prefix=supabase-postgres-x86"
59+
echo "arch_suffix=-x86"
60+
echo "instance_type=c6i.4xlarge"
61+
} >> "$GITHUB_OUTPUT"
62+
else
63+
{
64+
echo "ami_name_prefix=supabase-postgres"
65+
echo "arch_suffix="
66+
echo "instance_type=c6g.4xlarge"
67+
} >> "$GITHUB_OUTPUT"
68+
fi
69+
4470
- name: Install nix
4571
uses: ./.github/actions/nix-install-ephemeral
4672
with:
@@ -55,8 +81,11 @@ jobs:
5581
with:
5682
postgres_version: ${{ github.event.inputs.postgres_version }}
5783
region: us-east-1
84+
ami_name_prefix: ${{ steps.arch_vars.outputs.ami_name_prefix }}
5885
ami_regions: '["us-east-1"]'
86+
arch: ${{ steps.arch_vars.outputs.arch }}
5987
git_sha: ${{ steps.get_sha.outputs.sha }}
88+
instance_type: ${{ steps.arch_vars.outputs.instance_type }}
6089

6190
- name: Grab release version
6291
id: process_release_version
@@ -86,13 +115,14 @@ jobs:
86115
-e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
87116
-e "internal_artifacts_bucket=${{ secrets.ARTIFACTS_BUCKET }}" \
88117
-e "postgres_major_version=${{ github.event.inputs.postgres_version }}" \
118+
-e "arch=${{ github.event.inputs.arch }}" \
89119
manifest-playbook.yml
90120
91121
- name: Upload nix flake revision to s3 staging
92122
run: |
93-
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/20.04.tar.gz
94-
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/24.04.tar.gz
95-
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/upgrade_bundle.tar.gz
123+
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}${{ steps.arch_vars.outputs.arch_suffix }}/20.04.tar.gz
124+
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}${{ steps.arch_vars.outputs.arch_suffix }}/24.04.tar.gz
125+
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}${{ steps.arch_vars.outputs.arch_suffix }}/upgrade_bundle.tar.gz
96126
97127
- name: configure aws credentials - prod
98128
uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4.3.1
@@ -107,19 +137,20 @@ jobs:
107137
-e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
108138
-e "internal_artifacts_bucket=${{ secrets.PROD_ARTIFACTS_BUCKET }}" \
109139
-e "postgres_major_version=${{ github.event.inputs.postgres_version }}" \
140+
-e "arch=${{ github.event.inputs.arch }}" \
110141
manifest-playbook.yml
111142
112143
- name: Upload nix flake revision to s3 prod
113144
run: |
114-
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.PROD_ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/20.04.tar.gz
115-
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.PROD_ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/24.04.tar.gz
116-
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.PROD_ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/upgrade_bundle.tar.gz
145+
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.PROD_ARTIFACTS_BUCKET }}/upgrades${{ steps.arch_vars.outputs.arch_suffix }}/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/20.04.tar.gz
146+
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.PROD_ARTIFACTS_BUCKET }}/upgrades${{ steps.arch_vars.outputs.arch_suffix }}/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/24.04.tar.gz
147+
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.PROD_ARTIFACTS_BUCKET }}/upgrades${{ steps.arch_vars.outputs.arch_suffix }}/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/upgrade_bundle.tar.gz
117148
118149
- name: Create release
119150
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
120151
with:
121-
name: ${{ steps.process_release_version.outputs.version }}
122-
tag_name: ${{ steps.process_release_version.outputs.version }}
152+
name: ${{ steps.process_release_version.outputs.version }}${{ steps.arch_vars.outputs.arch_suffix }}
153+
tag_name: ${{ steps.process_release_version.outputs.version }}${{ steps.arch_vars.outputs.arch_suffix }}
123154
target_commitish: ${{ steps.get_sha.outputs.sha }}
124155

125156
- name: Slack Notification on Failure

0 commit comments

Comments
 (0)