Skip to content

Commit 259f2cc

Browse files
committed
chore: initial version of GHA to build qemu artifact
1 parent 2cf0be4 commit 259f2cc

File tree

2 files changed

+177
-1
lines changed

2 files changed

+177
-1
lines changed
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
name: Build QEMU image
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- release/*
8+
- da/merging-qemu
9+
paths:
10+
- '.github/workflows/qemu-image-build.yml'
11+
- 'qemu-arm64-nix.pkr.hcl'
12+
- 'common-nix.vars.pkr.hcl'
13+
- 'ansible/vars.yml'
14+
workflow_dispatch:
15+
16+
jobs:
17+
prepare:
18+
runs-on: ubuntu-latest
19+
outputs:
20+
postgres_versions: ${{ steps.set-versions.outputs.postgres_versions }}
21+
steps:
22+
- name: Checkout Repo
23+
uses: actions/checkout@v3
24+
25+
- uses: DeterminateSystems/nix-installer-action@main
26+
27+
# - name: Set PostgreSQL versions
28+
# id: set-versions
29+
# run: |
30+
# VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
31+
# echo "postgres_versions=$VERSIONS" >> $GITHUB_OUTPUT
32+
- name: Only build PG15 for the moment
33+
run: |
34+
echo 'postgres_versions=["\"15\""]'
35+
36+
build:
37+
needs: prepare
38+
strategy:
39+
matrix:
40+
postgres_version: ${{ fromJson(needs.prepare.outputs.postgres_versions) }}
41+
# include:
42+
# # TODO (darora): change to use non-self-hosted runners, since they now allow nested virtualization
43+
# - runner: arm-runner
44+
# arch: arm64
45+
# ubuntu_release: focal
46+
# ubuntu_version: 20.04
47+
# mcpu: neoverse-n1
48+
runs-on:
49+
group: pg-arm-large
50+
timeout-minutes: 150
51+
permissions:
52+
contents: write
53+
packages: write
54+
id-token: write
55+
56+
steps:
57+
- name: Checkout Repo
58+
uses: actions/checkout@v3
59+
60+
- uses: DeterminateSystems/nix-installer-action@main
61+
62+
# TODO (darora): might need to temporarily disable this
63+
- name: Run checks if triggered manually
64+
if: ${{ github.event_name == 'workflow_dispatch' }}
65+
run: |
66+
SUFFIX=$(sudo nix run nixpkgs#yq -- ".postgres_release[\"postgres${{ matrix.postgres_version }}\"]" ansible/vars.yml | sed -E 's/[0-9\.]+(.*)$/\1/')
67+
if [[ -z $SUFFIX ]] ; then
68+
echo "Version must include non-numeric characters if built manually."
69+
exit 1
70+
fi
71+
72+
- name: Set PostgreSQL version environment variable
73+
run: echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> $GITHUB_ENV
74+
75+
- name: Generate common-nix.vars.pkr.hcl
76+
run: |
77+
PG_VERSION=$(sudo nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
78+
PG_VERSION=$(echo $PG_VERSION | tr -d '"') # Remove any surrounding quotes
79+
echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
80+
echo 'postgres_major_version = "'$POSTGRES_MAJOR_VERSION'"' >> common-nix.vars.pkr.hcl
81+
echo 'postgresql_major = "'$POSTGRES_MAJOR_VERSION'"' >> common-nix.vars.pkr.hcl
82+
# Ensure there's a newline at the end of the file
83+
echo "" >> common-nix.vars.pkr.hcl
84+
85+
- name: Get binaries
86+
run: |
87+
hash
88+
89+
- name: Build QEMU artifact
90+
run: |
91+
make init
92+
GIT_SHA=${{github.sha}}
93+
# TODO (darora): possibly need to install qemu deps here
94+
packer build -var "git_sha=$(UPSTREAM_NIX_GIT_SHA)" -var-file="common-nix.vars.pkr.hcl" qemu-arm64-nix.pkr.hcl
95+
# packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" -var "ansible_arguments=-e postgresql_major=${POSTGRES_MAJOR_VERSION}" amazon-arm64-nix.pkr.hcl
96+
97+
# TODO (darora): publishing things is temporarily disabled
98+
# - name: Grab release version
99+
# id: process_release_version
100+
# run: |
101+
# VERSION=$(cat common-nix.vars.pkr.hcl | sed -e 's/postgres-version = "\(.*\)"/\1/g')
102+
# echo "version=$VERSION" >> $GITHUB_OUTPUT
103+
104+
# - name: Create nix flake revision tarball
105+
# run: |
106+
# GIT_SHA=${{github.sha}}
107+
# MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
108+
109+
# mkdir -p "/tmp/pg_upgrade_bin/${MAJOR_VERSION}"
110+
# echo "$GIT_SHA" >> "/tmp/pg_upgrade_bin/${MAJOR_VERSION}/nix_flake_version"
111+
# tar -czf "/tmp/pg_binaries.tar.gz" -C "/tmp/pg_upgrade_bin" .
112+
113+
# - name: configure aws credentials - staging
114+
# uses: aws-actions/configure-aws-credentials@v4
115+
# with:
116+
# role-to-assume: ${{ secrets.DEV_AWS_ROLE }}
117+
# aws-region: "us-east-1"
118+
119+
# - name: Upload software manifest to s3 staging
120+
# run: |
121+
# cd ansible
122+
# ansible-playbook -i localhost \
123+
# -e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
124+
# -e "internal_artifacts_bucket=${{ secrets.ARTIFACTS_BUCKET }}" \
125+
# -e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
126+
# manifest-playbook.yml
127+
128+
# - name: Upload nix flake revision to s3 staging
129+
# run: |
130+
# aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/20.04.tar.gz
131+
132+
# - name: configure aws credentials - prod
133+
# uses: aws-actions/configure-aws-credentials@v4
134+
# with:
135+
# role-to-assume: ${{ secrets.PROD_AWS_ROLE }}
136+
# aws-region: "us-east-1"
137+
138+
# - name: Upload software manifest to s3 prod
139+
# run: |
140+
# cd ansible
141+
# ansible-playbook -i localhost \
142+
# -e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
143+
# -e "internal_artifacts_bucket=${{ secrets.PROD_ARTIFACTS_BUCKET }}" \
144+
# -e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
145+
# manifest-playbook.yml
146+
147+
# - name: Upload nix flake revision to s3 prod
148+
# run: |
149+
# aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.PROD_ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/20.04.tar.gz
150+
151+
# - name: Create release
152+
# uses: softprops/action-gh-release@v1
153+
# with:
154+
# name: ${{ steps.process_release_version.outputs.version }}
155+
# tag_name: ${{ steps.process_release_version.outputs.version }}
156+
# target_commitish: ${{github.sha}}
157+
158+
# - name: Slack Notification on Failure
159+
# if: ${{ failure() }}
160+
# uses: rtCamp/action-slack-notify@v2
161+
# env:
162+
# SLACK_WEBHOOK: ${{ secrets.SLACK_NOTIFICATIONS_WEBHOOK }}
163+
# SLACK_USERNAME: 'gha-failures-notifier'
164+
# SLACK_COLOR: 'danger'
165+
# SLACK_MESSAGE: 'Building Postgres AMI failed'
166+
# SLACK_FOOTER: ''
167+
168+
- name: Cleanup resources after build
169+
if: ${{ always() }}
170+
run: |
171+
aws ec2 describe-instances --filters "Name=tag:packerExecutionId,Values=${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -r aws ec2 terminate-instances --instance-ids
172+
173+
- name: Cleanup resources on build cancellation
174+
if: ${{ cancelled() }}
175+
run: |
176+
aws ec2 describe-instances --filters "Name=tag:packerExecutionId,Values=${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -r aws ec2 terminate-instances --instance-ids

qemu-arm64-nix.pkr.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ build {
124124

125125
provisioner "shell" {
126126
environment_vars = [
127+
"POSTGRES_MAJOR_VERSION=${var.postgres_major_version}"
127128
"POSTGRES_SUPABASE_VERSION=${var.postgres-version}",
128129
"GIT_SHA=${var.git_sha}",
129-
"POSTGRES_MAJOR_VERSION=15" # TODO (darora): pass this in from vars
130130
]
131131
use_env_var_file = true
132132
script = "ebssurrogate/scripts/qemu-bootstrap-nix.sh"

0 commit comments

Comments
 (0)