@@ -143,3 +143,136 @@ jobs:
143143 run : |
144144 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
145145
146+ name : Release Single AMI Nix
147+
148+ on :
149+ workflow_dispatch :
150+ inputs :
151+ postgres_version :
152+ description : ' PostgreSQL major version to build (e.g. 15)'
153+ required : true
154+ type : string
155+ branch :
156+ description : ' Branch to run the workflow from'
157+ required : true
158+ type : string
159+ default : ' main'
160+
161+ permissions :
162+ contents : write
163+ id-token : write
164+
165+ jobs :
166+ build :
167+ runs-on : arm-runner
168+ timeout-minutes : 150
169+
170+ steps :
171+ - name : Checkout Repo
172+ uses : actions/checkout@v3
173+ with :
174+ ref : ${{ github.event.inputs.branch }}
175+
176+ - name : Get current branch SHA
177+ id : get_sha
178+ run : |
179+ echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
180+ - uses : DeterminateSystems/nix-installer-action@main
181+
182+ - name : Set PostgreSQL version environment variable
183+ run : echo "POSTGRES_MAJOR_VERSION=${{ github.event.inputs.postgres_version }}" >> $GITHUB_ENV
184+
185+ - name : Generate common-nix.vars.pkr.hcl
186+ run : |
187+ PG_VERSION=$(sudo nix run nixpkgs#yq -- '.postgres_release["postgres'${{ env.POSTGRES_MAJOR_VERSION }}'"]' ansible/vars.yml)
188+ PG_VERSION=$(echo "$PG_VERSION" | tr -d '"') # Remove any surrounding quotes
189+ echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
190+ # Ensure there's a newline at the end of the file
191+ echo "" >> common-nix.vars.pkr.hcl
192+ - name : Build AMI stage 1
193+ env :
194+ POSTGRES_MAJOR_VERSION : ${{ env.POSTGRES_MAJOR_VERSION }}
195+ run : |
196+ packer init amazon-arm64-nix.pkr.hcl
197+ GIT_SHA=${{ steps.get_sha.outputs.sha }}
198+ 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
199+ - name : Build AMI stage 2
200+ env :
201+ POSTGRES_MAJOR_VERSION : ${{ env.POSTGRES_MAJOR_VERSION }}
202+ run : |
203+ packer init stage2-nix-psql.pkr.hcl
204+ GIT_SHA=${{ steps.get_sha.outputs.sha }}
205+ POSTGRES_MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
206+ 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
207+ - name : Grab release version
208+ id : process_release_version
209+ run : |
210+ VERSION=$(cat common-nix.vars.pkr.hcl | sed -e 's/postgres-version = "\(.*\)"/\1/g')
211+ echo "version=$VERSION" >> $GITHUB_OUTPUT
212+ - name : Create nix flake revision tarball
213+ run : |
214+ GIT_SHA=${{ steps.get_sha.outputs.sha }}
215+ MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
216+ mkdir -p "/tmp/pg_upgrade_bin/${MAJOR_VERSION}"
217+ echo "$GIT_SHA" >> "/tmp/pg_upgrade_bin/${MAJOR_VERSION}/nix_flake_version"
218+ tar -czf "/tmp/pg_binaries.tar.gz" -C "/tmp/pg_upgrade_bin" .
219+ - name : configure aws credentials - staging
220+ uses : aws-actions/configure-aws-credentials@v4
221+ with :
222+ role-to-assume : ${{ secrets.DEV_AWS_ROLE }}
223+ aws-region : " us-east-1"
224+
225+ - name : Upload software manifest to s3 staging
226+ run : |
227+ cd ansible
228+ ansible-playbook -i localhost \
229+ -e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
230+ -e "internal_artifacts_bucket=${{ secrets.ARTIFACTS_BUCKET }}" \
231+ -e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
232+ manifest-playbook.yml
233+ - name : Upload nix flake revision to s3 staging
234+ run : |
235+ 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
236+ - name : configure aws credentials - prod
237+ uses : aws-actions/configure-aws-credentials@v4
238+ with :
239+ role-to-assume : ${{ secrets.PROD_AWS_ROLE }}
240+ aws-region : " us-east-1"
241+
242+ - name : Upload software manifest to s3 prod
243+ run : |
244+ cd ansible
245+ ansible-playbook -i localhost \
246+ -e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
247+ -e "internal_artifacts_bucket=${{ secrets.PROD_ARTIFACTS_BUCKET }}" \
248+ -e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
249+ manifest-playbook.yml
250+
251+ - name : Upload nix flake revision to s3 prod
252+ run : |
253+ 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
254+ - name : Create release
255+ uses : softprops/action-gh-release@v2
256+ with :
257+ name : ${{ steps.process_release_version.outputs.version }}
258+ tag_name : ${{ steps.process_release_version.outputs.version }}
259+ target_commitish : ${{ steps.get_sha.outputs.sha }}
260+
261+ - name : Slack Notification on Failure
262+ if : ${{ failure() }}
263+ uses : rtCamp/action-slack-notify@v2
264+ env :
265+ SLACK_WEBHOOK : ${{ secrets.SLACK_NOTIFICATIONS_WEBHOOK }}
266+ SLACK_USERNAME : ' gha-failures-notifier'
267+ SLACK_COLOR : ' danger'
268+ SLACK_MESSAGE : ' Building Postgres AMI failed'
269+ SLACK_FOOTER : ' '
270+
271+ - name : Cleanup resources after build
272+ if : ${{ always() }}
273+ run : |
274+ 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
275+ - name : Cleanup resources on build cancellation
276+ if : ${{ cancelled() }}
277+ run : |
278+ 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