9494 POSTGRES_MAJOR_VERSION : ${{ env.POSTGRES_MAJOR_VERSION }}
9595 run : |
9696 GIT_SHA=${{github.sha}}
97- nix run github:supabase/postgres/${GIT_SHA}#packer -- init ${{ matrix.arch.packer_template }}
98- nix run github:supabase/postgres/${GIT_SHA}#packer -- build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${EXECUTION_ID}" -var-file="${{ matrix.arch.vars_file }}" -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"]' -var "ami_name=${{ matrix.arch.ami_name }}" ${{ matrix.arch.packer_template }}
9997
100- - name : Find stage 1 AMI
101- run : |
102- GIT_SHA=${{github.sha}}
10398 PG_VERSION=$(sed -n 's/postgres-version = "\(.*\)"/\1/p' common-nix.vars.pkr.hcl)
10499 REGION="us-east-1"
105100
@@ -117,12 +112,28 @@ jobs:
117112 --output text)
118113
119114 if [ -z "$STAGE1_AMI_ID" ] || [ "$STAGE1_AMI_ID" = "None" ]; then
120- echo "ERROR: Failed to find stage 1 AMI"
121- exit 1
115+ echo "Did not find stage1 AMI - building it"
116+ nix run github:supabase/postgres/${GIT_SHA}#packer -- init ${{ matrix.arch.packer_template }}
117+ nix run github:supabase/postgres/${GIT_SHA}#packer -- build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${EXECUTION_ID}" -var-file="${{ matrix.arch.vars_file }}" -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"]' -var "ami_name=${{ matrix.arch.ami_name }}" ${{ matrix.arch.packer_template }}
118+ STAGE1_AMI_ID=$(aws ec2 describe-images \
119+ --region "$REGION" \
120+ --owners self \
121+ --filters \
122+ "Name=tag:postgresVersion,Values=${PG_VERSION}-stage1" \
123+ "Name=tag:sourceSha,Values=${GIT_SHA}" \
124+ "Name=state,Values=available" \
125+ "Name=architecture,Values=${{ matrix.arch.ami_arch_filter }}" \
126+ --query 'Images[0].ImageId' \
127+ --output text)
128+ if [ -z "$STAGE1_AMI_ID" ] || [ "$STAGE1_AMI_ID" = "None" ]; then
129+ echo "Failed to find stage1 AMI right after building it"
130+ exit 1
131+ fi
122132 fi
123133
124134 echo "Found stage 1 AMI: $STAGE1_AMI_ID"
125135 echo "STAGE1_AMI_ID=$STAGE1_AMI_ID" >> "$GITHUB_ENV"
136+ exit 0
126137
127138 - name : Build AMI stage 2
128139 env :
0 commit comments