Skip to content

Commit 0bbd35a

Browse files
committed
feat: workflow_dispatch release of single version of postgres
1 parent 3fbbd70 commit 0bbd35a

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Release Single AMI Nix
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
postgres_version:
7+
description: 'PostgreSQL major version to build (e.g. 15)'
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: write
13+
id-token: write
14+
15+
jobs:
16+
build:
17+
runs-on: arm-runner
18+
timeout-minutes: 150
19+
20+
steps:
21+
- name: Checkout Repo
22+
uses: actions/checkout@v3
23+
24+
- uses: DeterminateSystems/nix-installer-action@main
25+
26+
- name: Set PostgreSQL version environment variable
27+
run: echo "POSTGRES_MAJOR_VERSION=${{ github.event.inputs.postgres_version }}" >> $GITHUB_ENV
28+
29+
- name: Generate common-nix.vars.pkr.hcl
30+
run: |
31+
PG_VERSION=$(sudo nix run nixpkgs#yq -- '.postgres_release["postgres'${{ env.POSTGRES_MAJOR_VERSION }}'"]' ansible/vars.yml)
32+
PG_VERSION=$(echo "$PG_VERSION" | tr -d '"') # Remove any surrounding quotes
33+
echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
34+
# Ensure there's a newline at the end of the file
35+
echo "" >> common-nix.vars.pkr.hcl
36+
37+
- name: Build AMI stage 1
38+
env:
39+
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
40+
run: |
41+
packer init amazon-arm64-nix.pkr.hcl
42+
GIT_SHA=${{github.sha}}
43+
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
44+
45+
- name: Build AMI stage 2
46+
env:
47+
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
48+
run: |
49+
packer init stage2-nix-psql.pkr.hcl
50+
GIT_SHA=${{github.sha}}
51+
POSTGRES_MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
52+
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
53+
54+
- name: Grab release version
55+
id: process_release_version
56+
run: |
57+
VERSION=$(cat common-nix.vars.pkr.hcl | sed -e 's/postgres-version = "\(.*\)"/\1/g')
58+
echo "version=$VERSION" >> $GITHUB_OUTPUT
59+
60+
- name: Create nix flake revision tarball
61+
run: |
62+
GIT_SHA=${{github.sha}}
63+
MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
64+
65+
mkdir -p "/tmp/pg_upgrade_bin/${MAJOR_VERSION}"
66+
echo "$GIT_SHA" >> "/tmp/pg_upgrade_bin/${MAJOR_VERSION}/nix_flake_version"
67+
tar -czf "/tmp/pg_binaries.tar.gz" -C "/tmp/pg_upgrade_bin" .
68+
69+
- name: configure aws credentials - staging
70+
uses: aws-actions/configure-aws-credentials@v4
71+
with:
72+
role-to-assume: ${{ secrets.DEV_AWS_ROLE }}
73+
aws-region: "us-east-1"
74+
75+
- name: Upload software manifest to s3 staging
76+
run: |
77+
cd ansible
78+
ansible-playbook -i localhost \
79+
-e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
80+
-e "internal_artifacts_bucket=${{ secrets.ARTIFACTS_BUCKET }}" \
81+
-e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
82+
manifest-playbook.yml
83+
84+
- name: Upload nix flake revision to s3 staging
85+
run: |
86+
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
87+
88+
- name: configure aws credentials - prod
89+
uses: aws-actions/configure-aws-credentials@v4
90+
with:
91+
role-to-assume: ${{ secrets.PROD_AWS_ROLE }}
92+
aws-region: "us-east-1"
93+
94+
- name: Upload software manifest to s3 prod
95+
run: |
96+
cd ansible
97+
ansible-playbook -i localhost \
98+
-e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
99+
-e "internal_artifacts_bucket=${{ secrets.PROD_ARTIFACTS_BUCKET }}" \
100+
-e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
101+
manifest-playbook.yml
102+
103+
- name: Upload nix flake revision to s3 prod
104+
run: |
105+
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
106+
107+
- name: Create release
108+
uses: softprops/action-gh-release@v2
109+
with:
110+
name: ${{ steps.process_release_version.outputs.version }}
111+
tag_name: ${{ steps.process_release_version.outputs.version }}
112+
target_commitish: ${{github.sha}}
113+
114+
- name: Slack Notification on Failure
115+
if: ${{ failure() }}
116+
uses: rtCamp/action-slack-notify@v2
117+
env:
118+
SLACK_WEBHOOK: ${{ secrets.SLACK_NOTIFICATIONS_WEBHOOK }}
119+
SLACK_USERNAME: 'gha-failures-notifier'
120+
SLACK_COLOR: 'danger'
121+
SLACK_MESSAGE: 'Building Postgres AMI failed'
122+
SLACK_FOOTER: ''
123+
124+
- name: Cleanup resources after build
125+
if: ${{ always() }}
126+
run: |
127+
aws ec2 describe-instances --filters "Name=tag:packerExecutionId,Values=${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -r aws ec2 terminate-instances --instance-ids
128+
129+
- name: Cleanup resources on build cancellation
130+
if: ${{ cancelled() }}
131+
run: |
132+
aws ec2 describe-instances --filters "Name=tag:packerExecutionId,Values=${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -r aws ec2 terminate-instances --instance-ids

0 commit comments

Comments
 (0)