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"
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