@@ -25,18 +25,13 @@ jobs:
2525 uses : supabase/postgres/.github/actions/shared-checkout@HEAD
2626
2727 - name : Install nix
28- uses : cachix/install-nix-action@v27
29- with :
30- install_url : https://releases.nixos.org/nix/nix-2.29.1/install
31- extra_nix_config : |
32- substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
33- trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
28+ uses : ./.github/actions/nix-install-ephemeral
3429
3530 - name : Set PostgreSQL versions
3631 id : set-versions
3732 run : |
38- VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
39- echo "postgres_versions=$VERSIONS" >> $GITHUB_OUTPUT
33+ VERSIONS=$(nix run nixpkgs#yq -- -r '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
34+ echo "postgres_versions=$VERSIONS" >> " $GITHUB_OUTPUT"
4035
4136 build :
4237 needs : prepare
5146 steps :
5247 - name : Checkout Repo
5348 uses : supabase/postgres/.github/actions/shared-checkout@HEAD
49+ with :
50+ push-to-cache : ' true'
51+
5452 - name : aws-creds
5553 uses : aws-actions/configure-aws-credentials@v4
5654 with :
6058 role-duration-seconds : 7200
6159
6260 - name : Install nix
63- uses : cachix/install-nix-action@v27
64- with :
65- install_url : https://releases.nixos.org/nix/nix-2.29.1/install
66- extra_nix_config : |
67- substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
68- trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
61+ uses : ./.github/actions/nix-install-ephemeral
6962
7063 - name : Run checks if triggered manually
7164 if : ${{ github.event_name == 'workflow_dispatch' }}
@@ -76,47 +69,25 @@ jobs:
7669 exit 1
7770 fi
7871
79- - name : Set PostgreSQL version environment variable
80- run : |
81- echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> $GITHUB_ENV
82- echo "EXECUTION_ID=${{ github.run_id }}-${{ matrix.postgres_version }}" >> $GITHUB_ENV
83-
84- - name : Generate common-nix.vars.pkr.hcl
85- run : |
86- PG_VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
87- PG_VERSION=$(echo "$PG_VERSION" | tr -d '"') # Remove any surrounding quotes
88- echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
89- # Ensure there's a newline at the end of the file
90- echo "" >> common-nix.vars.pkr.hcl
91-
92- - name : Build AMI stage 1
93- env :
94- POSTGRES_MAJOR_VERSION : ${{ env.POSTGRES_MAJOR_VERSION }}
95- run : |
96- GIT_SHA=${{github.sha}}
97- nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
98- # why is postgresql_major defined here instead of where the _three_ other postgresql_* variables are defined?
99- 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}" -var "region=us-east-1" -var 'ami_regions=["us-east-1"]' amazon-arm64-nix.pkr.hcl
100-
101- - name : Build AMI stage 2
102- env :
103- POSTGRES_MAJOR_VERSION : ${{ env.POSTGRES_MAJOR_VERSION }}
104- run : |
105- GIT_SHA=${{github.sha}}
106- nix run github:supabase/postgres/${GIT_SHA}#packer -- init stage2-nix-psql.pkr.hcl
107- POSTGRES_MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
108- 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" -var "region=us-east-1" -var 'ami_regions=["us-east-1"]' stage2-nix-psql.pkr.hcl
72+ - name : Build AMI
73+ id : build-ami
74+ uses : ./.github/actions/build-ami
75+ with :
76+ postgres_version : ${{ matrix.postgres_version }}
77+ region : us-east-1
78+ ami_regions : ' ["us-east-1"]'
79+ git_sha : ${{ github.sha }}
10980
11081 - name : Grab release version
11182 id : process_release_version
11283 run : |
113- VERSION=$(cat common-nix.vars.pkr.hcl | sed -e 's/postgres-version = "\(.*\)"/\1/g')
114- echo "version=$VERSION" >> $GITHUB_OUTPUT
84+ VERSION="${{ steps.build-ami.outputs.postgres_release_version }}"
85+ echo "version=$VERSION" >> " $GITHUB_OUTPUT"
11586
11687 - name : Create nix flake revision tarball
11788 run : |
11889 GIT_SHA=${{github.sha}}
119- MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
90+ MAJOR_VERSION=${{ matrix.postgres_version }}
12091
12192 mkdir -p "/tmp/pg_upgrade_bin/${MAJOR_VERSION}"
12293 echo "$GIT_SHA" >> "/tmp/pg_upgrade_bin/${MAJOR_VERSION}/nix_flake_version"
@@ -134,7 +105,7 @@ jobs:
134105 ansible-playbook -i localhost \
135106 -e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
136107 -e "internal_artifacts_bucket=${{ secrets.ARTIFACTS_BUCKET }}" \
137- -e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
108+ -e "postgres_major_version=${{ matrix.postgres_version }}" \
138109 manifest-playbook.yml
139110
140111 - name : Upload nix flake revision to s3 staging
@@ -155,7 +126,7 @@ jobs:
155126 ansible-playbook -i localhost \
156127 -e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
157128 -e "internal_artifacts_bucket=${{ secrets.PROD_ARTIFACTS_BUCKET }}" \
158- -e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
129+ -e "postgres_major_version=${{ matrix.postgres_version }}" \
159130 manifest-playbook.yml
160131
161132 - name : Upload nix flake revision to s3 prod
@@ -184,9 +155,11 @@ jobs:
184155 - name : Cleanup resources after build
185156 if : ${{ always() }}
186157 run : |
158+ EXECUTION_ID="${{ steps.build-ami.outputs.execution_id }}"
187159 aws ec2 --region us-east-1 describe-instances --filters "Name=tag:packerExecutionId,Values=${EXECUTION_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -r aws ec2 terminate-instances --region us-east-1 --instance-ids
188160
189161 - name : Cleanup resources on build cancellation
190162 if : ${{ cancelled() }}
191163 run : |
164+ EXECUTION_ID="${{ steps.build-ami.outputs.execution_id }}"
192165 aws ec2 --region us-east-1 describe-instances --filters "Name=tag:packerExecutionId,Values=${EXECUTION_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -r aws ec2 terminate-instances --region us-east-1 --instance-ids
0 commit comments