Skip to content

Commit 91b446d

Browse files
committed
refactor: simplify qemu image build workflow by removing prepare job
Run image existence check into build job and use environment variable for PostgreSQL versions instead of separate prepare step.
1 parent 73c767e commit 91b446d

File tree

1 file changed

+33
-45
lines changed

1 file changed

+33
-45
lines changed

.github/workflows/qemu-image-build.yml

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,65 +18,47 @@ permissions:
1818
id-token: write
1919

2020
jobs:
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
21+
build:
22+
strategy:
23+
matrix:
24+
postgres_version: [17]
25+
runs-on: arm-native-runner
26+
timeout-minutes: 150
27+
permissions:
28+
contents: write
29+
packages: write
30+
id-token: write
2831

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 }}
4032
steps:
4133
- name: Checkout Repo
4234
uses: supabase/postgres/.github/actions/shared-checkout@HEAD
4335

36+
- name: Configure AWS credentials for image check
37+
uses: aws-actions/configure-aws-credentials@v4
38+
with:
39+
role-to-assume: ${{ secrets.CONTROL_PLANE_DEV_ROLE }}
40+
aws-region: "us-east-1"
41+
4442
- name: Check if image already exists in ECR
4543
id: check-image
4644
env:
4745
AWS_REGION: us-east-1
4846
REPOSITORY: postgres-vm-image
4947
run: |
50-
VERSION=$(yq '.postgres_release["postgres'${{ fromJson(needs.prepare.outputs.postgres_versions) }}'"]' ansible/vars.yml | tr -d '"')
48+
VERSION=$(yq '.postgres_release["postgres${{ matrix.postgres_version }}"]' ansible/vars.yml | tr -d '"')
5149
if aws ecr describe-images --repository-name "$REPOSITORY" --image-ids imageTag="$VERSION" --region "$AWS_REGION" 2>/dev/null; then
5250
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"
51+
echo "skip=true" >> "$GITHUB_OUTPUT"
5452
else
5553
echo "Image with tag $VERSION does not exist. Proceeding with build."
56-
echo "image_exists=false" >> "$GITHUB_OUTPUT"
54+
echo "skip=false" >> "$GITHUB_OUTPUT"
5755
fi
5856
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-
7657
- uses: DeterminateSystems/nix-installer-action@main
58+
if: steps.check-image.outputs.skip == 'false'
7759

7860
- name: Run checks if triggered manually
79-
if: ${{ github.event_name == 'workflow_dispatch' }}
61+
if: ${{ github.event_name == 'workflow_dispatch' && steps.check-image.outputs.skip == 'false' }}
8062
run: |
8163
SUFFIX=$(yq ".postgres_release[\"postgres${{ matrix.postgres_version }}\"]" ansible/vars.yml | sed -E 's/[0-9\.]+(.*)$/\1/')
8264
if [[ -z $SUFFIX ]] ; then
@@ -85,16 +67,19 @@ jobs:
8567
fi
8668
8769
- name: enable KVM support
70+
if: steps.check-image.outputs.skip == 'false'
8871
run: |
8972
sudo chown runner /dev/kvm
9073
sudo chmod 666 /dev/kvm
9174
9275
- name: Set PostgreSQL version environment variable
76+
if: steps.check-image.outputs.skip == 'false'
9377
run: |
9478
echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> "$GITHUB_ENV"
9579
echo "EXECUTION_ID=${{ github.run_id }}-${{ matrix.postgres_version }}" >> "$GITHUB_ENV"
9680
9781
- name: Generate common-nix.vars.pkr.hcl
82+
if: steps.check-image.outputs.skip == 'false'
9883
run: |
9984
curl -L https://github.com/mikefarah/yq/releases/download/v4.45.1/yq_linux_arm64 -o yq && chmod +x yq
10085
PG_VERSION=$(./yq '.postgres_release["postgres${{ matrix.postgres_version }}"]' ansible/vars.yml)
@@ -106,41 +91,41 @@ jobs:
10691
10792
# TODO (darora): not quite sure why I'm having to uninstall and re-install these deps, but the build fails w/o this
10893
- name: Install dependencies
94+
if: steps.check-image.outputs.skip == 'false'
10995
run: |
11096
sudo apt-get update
11197
sudo apt-get remove -y qemu-efi-aarch64 cloud-image-utils qemu-system-arm qemu-utils
11298
sudo apt-get install -y qemu-efi-aarch64 cloud-image-utils qemu-system-arm qemu-utils
11399
114100
- name: Build QEMU artifact
101+
if: steps.check-image.outputs.skip == 'false'
115102
run: |
116103
make init
117104
GIT_SHA=${{github.sha}}
118105
export PACKER_LOG=1
119106
packer build -var "git_sha=${GIT_SHA}" -var-file="common-nix.vars.pkr.hcl" qemu-arm64-nix.pkr.hcl
120107
121108
- name: Grab release version
109+
if: steps.check-image.outputs.skip == 'false'
122110
id: process_release_version
123111
run: |
124112
VERSION=$(sed -e 's/postgres-version = "\(.*\)"/\1/g' common-nix.vars.pkr.hcl)
125113
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
126114
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-
133115
- name: Login to Amazon ECR
116+
if: steps.check-image.outputs.skip == 'false'
134117
id: login-ecr-private-dev
135118
uses: aws-actions/amazon-ecr-login@v2
136119

137120
- name: Build image
121+
if: steps.check-image.outputs.skip == 'false'
138122
env:
139123
IMAGE_TAG: ${{ steps.process_release_version.outputs.version }}
140124
run: |
141125
docker build -f Dockerfile-kubernetes -t "postgres:$IMAGE_TAG" .
142126
143127
- name: Push docker image to Amazon ECR
128+
if: steps.check-image.outputs.skip == 'false'
144129
env:
145130
REGISTRY: 812073016711.dkr.ecr.us-east-1.amazonaws.com
146131
REPOSITORY: postgres-vm-image
@@ -151,16 +136,19 @@ jobs:
151136
152137
# TODO (darora): temporarily also push to prod account from here - add a guard to only publish proper tagged releases to prod?
153138
- name: configure aws credentials - prod
139+
if: steps.check-image.outputs.skip == 'false'
154140
uses: aws-actions/configure-aws-credentials@v4
155141
with:
156142
role-to-assume: ${{ secrets.CONTROL_PLANE_PROD_ROLE }}
157143
aws-region: "us-east-1"
158144

159145
- name: Login to Amazon ECR
146+
if: steps.check-image.outputs.skip == 'false'
160147
id: login-ecr-private-prod
161148
uses: aws-actions/amazon-ecr-login@v2
162149

163150
- name: Push docker image to Amazon ECR
151+
if: steps.check-image.outputs.skip == 'false'
164152
env:
165153
REGISTRY: 156470330064.dkr.ecr.us-east-1.amazonaws.com
166154
REPOSITORY: postgres-vm-image

0 commit comments

Comments
 (0)