Skip to content

Commit b8e6d12

Browse files
authored
Merge branch 'develop' into PSQL-773
2 parents 28408df + 0842286 commit b8e6d12

File tree

181 files changed

+201143
-562
lines changed

Some content is hidden

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

181 files changed

+201143
-562
lines changed

.github/actionlint.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
self-hosted-runner:
2+
labels:
3+
- aarch64-darwin
4+
- aarch64-linux
5+
- blacksmith-32vcpu-ubuntu-2404
6+
- blacksmith-2vcpu-ubuntu-2404
7+
- blacksmith-2vcpu-ubuntu-2404-arm
8+
- blacksmith-4vcpu-ubuntu-2404
9+
- large-linux-arm
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Build AMI
2+
description: Build both stage 1 and stage 2 AMIs
3+
4+
inputs:
5+
postgres_version:
6+
description: 'PostgreSQL major version (e.g., 15)'
7+
required: true
8+
region:
9+
description: 'AWS region'
10+
required: true
11+
ami_regions:
12+
description: 'AMI regions as JSON array (e.g., ["us-east-1"])'
13+
required: true
14+
git_sha:
15+
description: 'Git SHA for this build'
16+
required: true
17+
ami_name_prefix:
18+
description: 'Prefix for the AMI name'
19+
required: false
20+
default: 'supabase-postgres'
21+
22+
outputs:
23+
stage2_ami_id:
24+
description: 'The AMI ID of the stage 2 build'
25+
value: ${{ steps.build-stage2.outputs.stage2_ami_id }}
26+
postgres_release_version:
27+
description: 'The PostgreSQL release version'
28+
value: ${{ steps.generate-vars.outputs.version }}
29+
execution_id:
30+
description: 'The execution ID for this build'
31+
value: ${{ steps.set-execution-id.outputs.execution_id }}
32+
33+
runs:
34+
using: "composite"
35+
steps:
36+
- name: Set execution ID
37+
id: set-execution-id
38+
shell: bash
39+
run: |
40+
EXECUTION_ID="${{ github.run_id }}-${{ inputs.postgres_version }}"
41+
echo "EXECUTION_ID=$EXECUTION_ID" >> $GITHUB_ENV
42+
echo "execution_id=$EXECUTION_ID" >> $GITHUB_OUTPUT
43+
44+
- name: Generate common-nix.vars.pkr.hcl
45+
id: generate-vars
46+
shell: bash
47+
run: |
48+
PG_VERSION=$(nix run nixpkgs#yq -- -r '.postgres_release["postgres${{ inputs.postgres_version }}"]' ansible/vars.yml)
49+
echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
50+
echo "" >> common-nix.vars.pkr.hcl
51+
git add -f common-nix.vars.pkr.hcl
52+
echo "version=$PG_VERSION" >> $GITHUB_OUTPUT
53+
54+
- name: Build AMI stage 1
55+
shell: bash
56+
env:
57+
POSTGRES_MAJOR_VERSION: ${{ inputs.postgres_version }}
58+
POSTGRES_VERSION: ${{ steps.generate-vars.outputs.version }}
59+
AWS_MAX_ATTEMPTS: 10
60+
AWS_RETRY_MODE: adaptive
61+
AWS_REGION: ${{ inputs.region }}
62+
run: |
63+
nix run .#build-ami -- stage1 \
64+
-var "git-head-version=${{ inputs.git_sha }}" \
65+
-var "packer-execution-id=${{ env.EXECUTION_ID }}" \
66+
-var "ansible_arguments=-e postgresql_major=${{ inputs.postgres_version }}" \
67+
-var 'ami_regions=${{ inputs.ami_regions }}' \
68+
amazon-arm64-nix.pkr.hcl
69+
70+
- name: Build AMI stage 2
71+
id: build-stage2
72+
shell: bash
73+
env:
74+
POSTGRES_MAJOR_VERSION: ${{ inputs.postgres_version }}
75+
POSTGRES_VERSION: ${{ steps.generate-vars.outputs.version }}
76+
PACKER_EXECUTION_ID: ${{ env.EXECUTION_ID }}
77+
AWS_MAX_ATTEMPTS: 10
78+
AWS_RETRY_MODE: adaptive
79+
AWS_REGION: ${{ inputs.region }}
80+
run: |
81+
nix run .#build-ami -- stage2 \
82+
-var "git-head-version=${{ inputs.git_sha }}" \
83+
-var "packer-execution-id=${{ env.EXECUTION_ID }}" \
84+
-var "postgres_major_version=${{ inputs.postgres_version }}" \
85+
-var "ami_name=${{ inputs.ami_name_prefix }}" \
86+
-var "git_sha=${{ inputs.git_sha }}" \
87+
stage2-nix-psql.pkr.hcl

.github/actions/nix-install-ephemeral/action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ inputs:
55
description: 'Whether to push build outputs to the Nix binary cache'
66
required: false
77
default: 'false'
8+
aws-region:
9+
description: 'AWS region for the Nix binary cache S3 bucket'
10+
required: false
11+
default: 'us-east-1'
812
runs:
913
using: 'composite'
1014
steps:
@@ -13,7 +17,7 @@ runs:
1317
if: ${{ inputs.push-to-cache == 'true' }}
1418
with:
1519
role-to-assume: ${{ env.DEV_AWS_ROLE }}
16-
aws-region: "us-east-1"
20+
aws-region: ${{ inputs.aws-region }}
1721
output-credentials: true
1822
role-duration-seconds: 7200
1923
- name: Setup AWS credentials for Nix
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: 'Configure Nix on self hosted runners'
2+
description: 'Sets up AWS credentials to push to the Nix binary cache'
3+
inputs:
4+
aws-role-duration:
5+
description: 'AWS role session duration in seconds'
6+
required: false
7+
default: '18000'
8+
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: aws-creds
13+
uses: aws-actions/configure-aws-credentials@v4.3.1
14+
with:
15+
disable-retry: true
16+
aws-region: us-east-2
17+
role-to-assume: arn:aws:iam::436098097459:role/nix-artifacts-deploy-role # supabase-dev
18+
role-session-name: gha-oidc-${{ github.run_id }}
19+
role-duration-seconds: ${{ inputs.aws-role-duration }}
20+
21+
- name: Write creds files
22+
shell: bash
23+
run: |
24+
umask 006
25+
cat > /etc/nix/aws/nix-aws-credentials <<EOF
26+
[ci-uploader]
27+
aws_access_key_id = ${AWS_ACCESS_KEY_ID}
28+
aws_secret_access_key = ${AWS_SECRET_ACCESS_KEY}
29+
aws_session_token = ${AWS_SESSION_TOKEN}
30+
EOF

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

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
uses: supabase/postgres/.github/actions/shared-checkout@HEAD
2828
with:
2929
ref: ${{ github.event.inputs.branch }}
30+
3031
- name: aws-creds
3132
uses: aws-actions/configure-aws-credentials@v4
3233
with:
@@ -38,56 +39,35 @@ jobs:
3839
- name: Get current branch SHA
3940
id: get_sha
4041
run: |
41-
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
42+
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
4243
4344
- name: Install nix
44-
uses: cachix/install-nix-action@v27
45+
uses: ./.github/actions/nix-install-ephemeral
4546
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=
50-
51-
- name: Set PostgreSQL version environment variable
52-
run: |
53-
echo "POSTGRES_MAJOR_VERSION=${{ github.event.inputs.postgres_version }}" >> $GITHUB_ENV
54-
echo "EXECUTION_ID=${{ github.run_id }}-${{ matrix.postgres_version }}" >> $GITHUB_ENV
55-
56-
- name: Generate common-nix.vars.pkr.hcl
57-
run: |
58-
PG_VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ env.POSTGRES_MAJOR_VERSION }}'"]' ansible/vars.yml)
59-
PG_VERSION=$(echo "$PG_VERSION" | tr -d '"') # Remove any surrounding quotes
60-
echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
61-
# Ensure there's a newline at the end of the file
62-
echo "" >> common-nix.vars.pkr.hcl
63-
64-
- name: Build AMI stage 1
47+
push-to-cache: 'true'
6548
env:
66-
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
67-
run: |
68-
GIT_SHA=${{ steps.get_sha.outputs.sha }}
69-
nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
70-
nix run github:supabase/postgres/${GIT_SHA}#packer -- build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${EXECUTION_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
49+
DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }}
50+
NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }}
7151

72-
- name: Build AMI stage 2
73-
env:
74-
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
75-
run: |
76-
GIT_SHA=${{ steps.get_sha.outputs.sha }}
77-
nix run github:supabase/postgres/${GIT_SHA}#packer -- init stage2-nix-psql.pkr.hcl
78-
POSTGRES_MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
79-
nix run github:supabase/postgres/${GIT_SHA}#packer -- build -var "git_sha=${GIT_SHA}" -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${EXECUTION_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
52+
- name: Build AMI
53+
id: build-ami
54+
uses: ./.github/actions/build-ami
55+
with:
56+
postgres_version: ${{ github.event.inputs.postgres_version }}
57+
region: us-east-1
58+
ami_regions: '["us-east-1"]'
59+
git_sha: ${{ steps.get_sha.outputs.sha }}
8060

8161
- name: Grab release version
8262
id: process_release_version
8363
run: |
84-
VERSION=$(cat common-nix.vars.pkr.hcl | sed -e 's/postgres-version = "\(.*\)"/\1/g')
85-
echo "version=$VERSION" >> $GITHUB_OUTPUT
64+
VERSION="${{ steps.build-ami.outputs.postgres_release_version }}"
65+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
8666
8767
- name: Create nix flake revision tarball
8868
run: |
8969
GIT_SHA=${{ steps.get_sha.outputs.sha }}
90-
MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
70+
MAJOR_VERSION=${{ github.event.inputs.postgres_version }}
9171
9272
mkdir -p "/tmp/pg_upgrade_bin/${MAJOR_VERSION}"
9373
echo "$GIT_SHA" >> "/tmp/pg_upgrade_bin/${MAJOR_VERSION}/nix_flake_version"
@@ -105,7 +85,7 @@ jobs:
10585
ansible-playbook -i localhost \
10686
-e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
10787
-e "internal_artifacts_bucket=${{ secrets.ARTIFACTS_BUCKET }}" \
108-
-e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
88+
-e "postgres_major_version=${{ github.event.inputs.postgres_version }}" \
10989
manifest-playbook.yml
11090
11191
- name: Upload nix flake revision to s3 staging
@@ -126,7 +106,7 @@ jobs:
126106
ansible-playbook -i localhost \
127107
-e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
128108
-e "internal_artifacts_bucket=${{ secrets.PROD_ARTIFACTS_BUCKET }}" \
129-
-e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
109+
-e "postgres_major_version=${{ github.event.inputs.postgres_version }}" \
130110
manifest-playbook.yml
131111
132112
- name: Upload nix flake revision to s3 prod
@@ -155,10 +135,12 @@ jobs:
155135
- name: Cleanup resources after build
156136
if: ${{ always() }}
157137
run: |
138+
EXECUTION_ID="${{ steps.build-ami.outputs.execution_id }}"
158139
aws ec2 describe-instances --filters "Name=tag:packerExecutionId,Values=${EXECUTION_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -r aws ec2 terminate-instances --instance-ids
159140
160141
- name: Cleanup resources on build cancellation
161142
if: ${{ cancelled() }}
162143
run: |
144+
EXECUTION_ID="${{ steps.build-ami.outputs.execution_id }}"
163145
aws ec2 describe-instances --filters "Name=tag:packerExecutionId,Values=${EXECUTION_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -r aws ec2 terminate-instances --instance-ids
164146

0 commit comments

Comments
 (0)