@@ -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+ env :
52+ DEV_AWS_ROLE : ${{ secrets.DEV_AWS_ROLE }}
53+ NIX_SIGN_SECRET_KEY : ${{ secrets.NIX_SIGN_SECRET_KEY }}
54+
5455 - name : aws-creds
5556 uses : aws-actions/configure-aws-credentials@v4
5657 with :
6061 role-duration-seconds : 7200
6162
6263 - 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=
64+ uses : ./.github/actions/nix-install-ephemeral
6965
7066 - name : Run checks if triggered manually
7167 if : ${{ github.event_name == 'workflow_dispatch' }}
@@ -76,47 +72,25 @@ jobs:
7672 exit 1
7773 fi
7874
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
75+ - name : Build AMI
76+ id : build-ami
77+ uses : ./.github/actions/build-ami
78+ with :
79+ postgres_version : ${{ matrix.postgres_version }}
80+ region : us-east-1
81+ ami_regions : ' ["us-east-1"]'
82+ git_sha : ${{ github.sha }}
10983
11084 - name : Grab release version
11185 id : process_release_version
11286 run : |
113- VERSION=$(cat common-nix.vars.pkr.hcl | sed -e 's/postgres-version = "\(.*\)"/\1/g')
114- echo "version=$VERSION" >> $GITHUB_OUTPUT
87+ VERSION="${{ steps.build-ami.outputs.postgres_release_version }}"
88+ echo "version=$VERSION" >> " $GITHUB_OUTPUT"
11589
11690 - name : Create nix flake revision tarball
11791 run : |
11892 GIT_SHA=${{github.sha}}
119- MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
93+ MAJOR_VERSION=${{ matrix.postgres_version }}
12094
12195 mkdir -p "/tmp/pg_upgrade_bin/${MAJOR_VERSION}"
12296 echo "$GIT_SHA" >> "/tmp/pg_upgrade_bin/${MAJOR_VERSION}/nix_flake_version"
@@ -134,7 +108,7 @@ jobs:
134108 ansible-playbook -i localhost \
135109 -e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
136110 -e "internal_artifacts_bucket=${{ secrets.ARTIFACTS_BUCKET }}" \
137- -e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
111+ -e "postgres_major_version=${{ matrix.postgres_version }}" \
138112 manifest-playbook.yml
139113
140114 - name : Upload nix flake revision to s3 staging
@@ -155,7 +129,7 @@ jobs:
155129 ansible-playbook -i localhost \
156130 -e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
157131 -e "internal_artifacts_bucket=${{ secrets.PROD_ARTIFACTS_BUCKET }}" \
158- -e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
132+ -e "postgres_major_version=${{ matrix.postgres_version }}" \
159133 manifest-playbook.yml
160134
161135 - name : Upload nix flake revision to s3 prod
@@ -184,9 +158,11 @@ jobs:
184158 - name : Cleanup resources after build
185159 if : ${{ always() }}
186160 run : |
161+ EXECUTION_ID="${{ steps.build-ami.outputs.execution_id }}"
187162 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
188163
189164 - name : Cleanup resources on build cancellation
190165 if : ${{ cancelled() }}
191166 run : |
167+ EXECUTION_ID="${{ steps.build-ami.outputs.execution_id }}"
192168 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