@@ -17,66 +17,52 @@ permissions:
1717 contents : read
1818 id-token : write
1919
20+ env :
21+ POSTGRES_VERSIONS : ' ["17"]'
22+
2023jobs :
21- prepare :
22- runs-on : ubuntu-latest
23- outputs :
24- postgres_versions : ${{ steps.set-versions.outputs.postgres_versions }}
25- steps :
26- - name : Checkout Repo
27- uses : supabase/postgres/.github/actions/shared-checkout@HEAD
2824
29- - name : Set PostgreSQL versions - only builds pg17 atm
30- id : set-versions
31- run : |
32- VERSIONS=$(yq '.postgres_major[1]' ansible/vars.yml | jq -R -s -c 'split("\n")[:-1]')
33- echo "postgres_versions=$VERSIONS" >> "$GITHUB_OUTPUT"
34-
35- check-existing-image :
36- needs : prepare
37- runs-on : ubuntu-latest
38- outputs :
39- image_exists : ${{ steps.check-image.outputs.image_exists }}
25+ build :
26+ strategy :
27+ matrix :
28+ postgres_version : ${{ fromJson(env.POSTGRES_VERSIONS) }}
29+ runs-on : arm-native-runner
30+ timeout-minutes : 150
31+ permissions :
32+ contents : write
33+ packages : write
34+ id-token : write
35+
4036 steps :
4137 - name : Checkout Repo
4238 uses : supabase/postgres/.github/actions/shared-checkout@HEAD
4339
40+ - name : Configure AWS credentials for image check
41+ uses : aws-actions/configure-aws-credentials@v4
42+ with :
43+ role-to-assume : ${{ secrets.CONTROL_PLANE_DEV_ROLE }}
44+ aws-region : " us-east-1"
45+
4446 - name : Check if image already exists in ECR
4547 id : check-image
4648 env :
4749 AWS_REGION : us-east-1
4850 REPOSITORY : postgres-vm-image
4951 run : |
50- VERSION=$(yq '.postgres_release["postgres' ${{ fromJson(needs.prepare.outputs.postgres_versions) }}' "]' ansible/vars.yml | tr -d '"')
52+ VERSION=$(yq '.postgres_release["postgres${{ matrix.postgres_version }}"]' ansible/vars.yml | tr -d '"')
5153 if aws ecr describe-images --repository-name "$REPOSITORY" --image-ids imageTag="$VERSION" --region "$AWS_REGION" 2>/dev/null; then
5254 echo "::notice title=Qemu image::Image with tag $VERSION already exists. Skipping build. Please update the version in ansible/vars.yml if you want to upload a new image."
53- echo "image_exists =true" >> "$GITHUB_OUTPUT"
55+ echo "skip =true" >> "$GITHUB_OUTPUT"
5456 else
5557 echo "Image with tag $VERSION does not exist. Proceeding with build."
56- echo "image_exists =false" >> "$GITHUB_OUTPUT"
58+ echo "skip =false" >> "$GITHUB_OUTPUT"
5759 fi
5860
59- build :
60- needs : [prepare, check-existing-image]
61- if : ${{ needs.check-existing-image.outputs.image_exists == 'false' }}
62- strategy :
63- matrix :
64- postgres_version : ${{ fromJson(needs.prepare.outputs.postgres_versions) }}
65- runs-on : arm-native-runner
66- timeout-minutes : 150
67- permissions :
68- contents : write
69- packages : write
70- id-token : write
71-
72- steps :
73- - name : Checkout Repo
74- uses : supabase/postgres/.github/actions/shared-checkout@HEAD
75-
7661 - uses : DeterminateSystems/nix-installer-action@main
62+ if : steps.check-image.outputs.skip == 'false'
7763
7864 - name : Run checks if triggered manually
79- if : ${{ github.event_name == 'workflow_dispatch' }}
65+ if : ${{ github.event_name == 'workflow_dispatch' && steps.check-image.outputs.skip == 'false' }}
8066 run : |
8167 SUFFIX=$(yq ".postgres_release[\"postgres${{ matrix.postgres_version }}\"]" ansible/vars.yml | sed -E 's/[0-9\.]+(.*)$/\1/')
8268 if [[ -z $SUFFIX ]] ; then
@@ -85,16 +71,19 @@ jobs:
8571 fi
8672
8773 - name : enable KVM support
74+ if : steps.check-image.outputs.skip == 'false'
8875 run : |
8976 sudo chown runner /dev/kvm
9077 sudo chmod 666 /dev/kvm
9178
9279 - name : Set PostgreSQL version environment variable
80+ if : steps.check-image.outputs.skip == 'false'
9381 run : |
9482 echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> "$GITHUB_ENV"
9583 echo "EXECUTION_ID=${{ github.run_id }}-${{ matrix.postgres_version }}" >> "$GITHUB_ENV"
9684
9785 - name : Generate common-nix.vars.pkr.hcl
86+ if : steps.check-image.outputs.skip == 'false'
9887 run : |
9988 curl -L https://github.com/mikefarah/yq/releases/download/v4.45.1/yq_linux_arm64 -o yq && chmod +x yq
10089 PG_VERSION=$(./yq '.postgres_release["postgres${{ matrix.postgres_version }}"]' ansible/vars.yml)
@@ -106,41 +95,41 @@ jobs:
10695
10796 # TODO (darora): not quite sure why I'm having to uninstall and re-install these deps, but the build fails w/o this
10897 - name : Install dependencies
98+ if : steps.check-image.outputs.skip == 'false'
10999 run : |
110100 sudo apt-get update
111101 sudo apt-get remove -y qemu-efi-aarch64 cloud-image-utils qemu-system-arm qemu-utils
112102 sudo apt-get install -y qemu-efi-aarch64 cloud-image-utils qemu-system-arm qemu-utils
113103
114104 - name : Build QEMU artifact
105+ if : steps.check-image.outputs.skip == 'false'
115106 run : |
116107 make init
117108 GIT_SHA=${{github.sha}}
118109 export PACKER_LOG=1
119110 packer build -var "git_sha=${GIT_SHA}" -var-file="common-nix.vars.pkr.hcl" qemu-arm64-nix.pkr.hcl
120111
121112 - name : Grab release version
113+ if : steps.check-image.outputs.skip == 'false'
122114 id : process_release_version
123115 run : |
124116 VERSION=$(sed -e 's/postgres-version = "\(.*\)"/\1/g' common-nix.vars.pkr.hcl)
125117 echo "version=$VERSION" >> "$GITHUB_OUTPUT"
126118
127- - name : configure aws credentials - staging
128- uses : aws-actions/configure-aws-credentials@v4
129- with :
130- role-to-assume : ${{ secrets.CONTROL_PLANE_DEV_ROLE }}
131- aws-region : " us-east-1"
132-
133119 - name : Login to Amazon ECR
120+ if : steps.check-image.outputs.skip == 'false'
134121 id : login-ecr-private-dev
135122 uses : aws-actions/amazon-ecr-login@v2
136123
137124 - name : Build image
125+ if : steps.check-image.outputs.skip == 'false'
138126 env :
139127 IMAGE_TAG : ${{ steps.process_release_version.outputs.version }}
140128 run : |
141129 docker build -f Dockerfile-kubernetes -t "postgres:$IMAGE_TAG" .
142130
143131 - name : Push docker image to Amazon ECR
132+ if : steps.check-image.outputs.skip == 'false'
144133 env :
145134 REGISTRY : 812073016711.dkr.ecr.us-east-1.amazonaws.com
146135 REPOSITORY : postgres-vm-image
@@ -151,16 +140,19 @@ jobs:
151140
152141 # TODO (darora): temporarily also push to prod account from here - add a guard to only publish proper tagged releases to prod?
153142 - name : configure aws credentials - prod
143+ if : steps.check-image.outputs.skip == 'false'
154144 uses : aws-actions/configure-aws-credentials@v4
155145 with :
156146 role-to-assume : ${{ secrets.CONTROL_PLANE_PROD_ROLE }}
157147 aws-region : " us-east-1"
158148
159149 - name : Login to Amazon ECR
150+ if : steps.check-image.outputs.skip == 'false'
160151 id : login-ecr-private-prod
161152 uses : aws-actions/amazon-ecr-login@v2
162153
163154 - name : Push docker image to Amazon ECR
155+ if : steps.check-image.outputs.skip == 'false'
164156 env :
165157 REGISTRY : 156470330064.dkr.ecr.us-east-1.amazonaws.com
166158 REPOSITORY : postgres-vm-image
0 commit comments