Skip to content

Commit bcf0e0e

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

File tree

2 files changed

+174
-1
lines changed

2 files changed

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