Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Build and publish a QEMU image artifact #1430

Merged
merged 98 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
549f9eb
fix: account for `public` grantee
soedirgo Sep 26, 2024
c83b1c6
fix(ci): respect postgresVersion input (#1237)
soedirgo Sep 26, 2024
5671a39
feat: bump gotrue version to v2.162.0 (#1241)
kangmingtay Sep 28, 2024
a2f1ff8
fix: only grant pg_read_all_data if it exists (#1242)
soedirgo Sep 30, 2024
d71ec5f
fix(15.6): account for pg_stat_monitor major version upgrade (#1247)
pcnc Oct 2, 2024
8706e3a
chore: release updates to run physical backup as a service to 15.6 im…
dragarcia Oct 2, 2024
1d1396e
fix(15.6/pg_upgrade): retry commands within the cleanup step; wait un…
pcnc Oct 2, 2024
320305e
fix(15.6/upgrades): collision when patching wrappers lib locations fo…
pcnc Oct 2, 2024
d264b9d
feat: bump auth 2.162.1 on 15.6 (#1256)
hf Oct 3, 2024
5177fa3
fix(15.6): disable pg_stat_monitor (#1260)
pcnc Oct 4, 2024
ce2eb0c
fix(15.6): disable pg_stat_monitor (#1262)
pcnc Oct 4, 2024
9062da4
feat: bump gotrue to v2.162.2 (#1264)
kangmingtay Oct 7, 2024
0c52b1f
chore: add timescaledb 2.9.1; wrappers upgrade fix; wrappers & plv8 n…
pcnc Oct 15, 2024
ba417af
chore(15.6): bump pg version (#1273)
pcnc Oct 15, 2024
82152fa
feat: bump auth to v2.163.0 on 15.6 (#1275)
hf Oct 15, 2024
1912ed8
fix: restart PG during pre-upgrade steps to shed hanging connections …
pcnc Oct 16, 2024
3cf6055
fix(upgrades): wrappers 4.2.0 -> wrappers 4.2.0 (#1278)
pcnc Oct 17, 2024
054dbc1
fix: handle supabase_admin authenticator membership snowflake
soedirgo Oct 21, 2024
fb024e8
feat: add auth v2.163.1 to 15.6 (#1283)
hf Oct 22, 2024
223952b
feat: bump gotrue to v2.163.2 (#1287)
kangmingtay Oct 23, 2024
2d658fc
pg_net 0.11 on 15.6 release branch (#1290)
olirice Oct 24, 2024
a5e5919
fix: don't copy custom extension scripts during pg_upgrade (#1291)
pcnc Oct 25, 2024
1211077
fix: add recursive flag to custom extension script directory delete (…
pcnc Oct 25, 2024
407d41a
[GEN-11027] chore: reserve a fixed amount of blocks for the data volu…
pcnc Oct 30, 2024
19ac493
fix: grant predefined roles post-upgrade
soedirgo Oct 31, 2024
21d3823
fix: add more roles to reserved_roles & reserved_memberships (#1303)
soedirgo Oct 31, 2024
1273c41
feat: update envoy lds config with auth jwks, oidc URLs, strip `sb-op…
hf Nov 1, 2024
936713c
chore: udpate package repo for salt (#1307)
dragarcia Nov 4, 2024
5350420
fix: use sudo for apt-get commands
soedirgo Nov 6, 2024
9e285dd
Update pg net to 0.13.0 on pg 15.6 branch (#1315)
olirice Nov 8, 2024
a627e17
chore: cleanup pgbouncer.get_auth ownership accordingly
dragarcia Nov 6, 2024
4b0e661
chore: standardize
dragarcia Nov 6, 2024
a3cce04
chore: try a qemu build
darora Nov 7, 2024
4c2aa5b
chore: avoid using ansible globbing
darora Nov 13, 2024
ea0abae
revert stage2 changes
darora Nov 25, 2024
41a4f14
preserve AMI build process
darora Nov 25, 2024
c7696d3
chore: check ec2ic perms if not in qemu mode
darora Nov 25, 2024
98a87b5
chore: further ami build things
darora Nov 26, 2024
841505a
chore: ship qcow2 image instead of raw
darora Nov 26, 2024
36510ea
chore: cleanup + start building nix artifacts on qemu branches
darora Nov 27, 2024
03eb5cf
chore: add rudimentary docs on the QEMU artifact
darora Nov 27, 2024
fc741e2
chore: upgrade to latest adminapi release
darora Nov 27, 2024
6a233ca
chore: first pass at adding details to the docs
dragarcia Nov 28, 2024
9fc808b
chore: update doc on steps when running within the cluster
dragarcia Nov 29, 2024
78e7b0d
Update qemu_artifact.md
darora Nov 29, 2024
46c5c51
chore: add image built on alpine with some qemu deps
darora Jan 31, 2025
c9c3be4
chore: upgrade to latest alpine
darora Jan 31, 2025
a21b88a
Merge remote-tracking branch 'origin/develop' into da/merging-qemu
darora Feb 1, 2025
a582a0c
chore: remove temporary changes that are no longer necessary
darora Feb 1, 2025
5658e78
chore: upgrade to latest awscli release
darora Feb 1, 2025
67bc2c9
fix: define postgres major version
darora Feb 1, 2025
035dc13
fix: more new vars
darora Feb 1, 2025
85c7e82
fix: yet another pg var
darora Feb 1, 2025
2cf0be4
Merge remote-tracking branch 'origin/develop' into da/merging-qemu
darora Feb 1, 2025
bcf0e0e
chore: initial version of GHA to build qemu artifact
darora Feb 2, 2025
277f761
.
darora Feb 2, 2025
aa07a38
.
darora Feb 2, 2025
a65a8c5
.
darora Feb 2, 2025
4823c8a
chore: install system dependencies
darora Feb 2, 2025
6ad5807
chore: pass in pg version var correctly
darora Feb 2, 2025
09fecce
enable logs
darora Feb 2, 2025
b9fd20b
.
darora Feb 2, 2025
bdbd500
.
darora Feb 2, 2025
2f0f1be
chore: temporarily disable KVM to test sw emulation performance
darora Feb 2, 2025
cb9ffbd
chore: specify number of CPU cores
darora Feb 2, 2025
2965425
trigger build
darora Feb 4, 2025
e1b27e4
Revert "chore: temporarily disable KVM to test sw emulation performance"
darora Feb 4, 2025
0e96fe8
chore: use native runners
darora Feb 4, 2025
7528325
update apt sources
darora Feb 4, 2025
3034704
.
darora Feb 4, 2025
66c7850
attempt to enable kvm
darora Feb 4, 2025
3a37d03
.
darora Feb 4, 2025
f964393
chore; REVERT this later
darora Feb 4, 2025
23fbb98
.
darora Feb 4, 2025
2f36aab
Revert "chore; REVERT this later"
darora Feb 4, 2025
8d0ef7a
chore: remove path output
darora Feb 4, 2025
a24e13f
.
darora Feb 4, 2025
cf3b0ec
chore: install packer since we're experimenting with a base image
darora Feb 4, 2025
9ad8432
reenable host cpu
darora Feb 4, 2025
dc080fc
.
darora Feb 4, 2025
add5d2b
try publishing
darora Feb 4, 2025
4877903
cleanup
darora Feb 4, 2025
e423ffc
.
darora Feb 4, 2025
08e6311
fix
darora Feb 4, 2025
44f8563
.
darora Feb 4, 2025
b245fc2
.
darora Feb 4, 2025
8c478bd
.
darora Feb 4, 2025
8d5d14a
test using builtin deps
darora Feb 4, 2025
75b76b7
Revert "test using builtin deps"
darora Feb 4, 2025
e8d5da4
.
darora Feb 4, 2025
ec51f42
simplify
darora Feb 4, 2025
a7496be
.
darora Feb 4, 2025
1b23658
context
darora Feb 4, 2025
45a2f3e
fix: correct tag
darora Feb 4, 2025
44f115d
Merge remote-tracking branch 'origin/develop' into da/merging-qemu
darora Feb 5, 2025
e53bd62
chore: cleanup instructions for building image
darora Feb 5, 2025
bbd589f
chore: run scripts through an auto-formatter
darora Feb 7, 2025
000ab44
Merge remote-tracking branch 'origin/develop' into da/merging-qemu
darora Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ami-release-nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ jobs:
run: |
packer init amazon-arm64-nix.pkr.hcl
GIT_SHA=${{github.sha}}
# why is postgresql_major defined here instead of where the _three_ other postgresql_* variables are defined?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samrose not sure if you know?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darora this var is used in ansible, which in turn is run by packer, and so that is the most likely reason it was set here

git grep postgresql_major
.github/workflows/ami-release-nix.yml:          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
.github/workflows/testinfra-nix.yml:          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=" -var "postgres-version=${{ steps.random.outputs.random_string }}" -var "region=ap-southeast-1" -var 'ami_regions=["ap-southeast-1"]' -var "force-deregister=true" -var "ansible_arguments=-e postgresql_major=${POSTGRES_MAJOR_VERSION}" amazon-arm64-nix.pkr.hcl
CONTRIBUTING.md:ADD "https://github.com/supabase/pg_graphql/releases/download/v${pg_graphql_release}/pg_graphql-v${pg_graphql_release}-pg${postgresql_major}-${TARGETARCH}-linux-gnu.deb" \
Dockerfile-15:ARG postgresql_major=15
Dockerfile-15:ARG postgresql_release=${postgresql_major}.1
Dockerfile-orioledb-17:ARG postgresql_major=17-orioledb
Dockerfile-orioledb-17:ARG postgresql_release=${postgresql_major}.1
ansible/tasks/internal/collect-pg-binaries.yml:    path: /tmp/pg_binaries/{{ postgresql_major }}/
ansible/tasks/internal/collect-pg-binaries.yml:    src: /usr/lib/postgresql/{{ postgresql_major }}/{{ item }}/
ansible/tasks/internal/collect-pg-binaries.yml:    dest: /tmp/pg_binaries/{{ postgresql_major }}/{{ item }}/
ansible/tasks/internal/collect-pg-binaries.yml:    dest: /tmp/pg_binaries/{{ postgresql_major }}/lib/
ansible/tasks/internal/collect-pg-binaries.yml:    dest: /tmp/pg_binaries/{{ postgresql_major }}/lib/
ansible/tasks/internal/collect-pg-binaries.yml:    dest: /tmp/pg_binaries/{{ postgresql_major }}/lib/libpq.so.5
ansible/tasks/internal/collect-pg-binaries.yml:    src: /usr/share/postgresql/{{ postgresql_major }}/
ansible/tasks/internal/collect-pg-binaries.yml:    dest: /tmp/pg_binaries/{{ postgresql_major }}/share/
ansible/tasks/setup-postgres.yml:    name: postgresql-{{ postgresql_major }}={{ postgresql_release }}-1.pgdg20.04+1
ansible/tasks/setup-postgres.yml:    cmd: ln -s /usr/lib/postgresql/{{ postgresql_major }}/bin /usr/lib/postgresql/bin
ansible/tasks/setup-postgrest.yml:    repo: "deb http://apt.postgresql.org/pub/repos/apt/ focal-pgdg {{ postgresql_major }}"
ansible/tasks/setup-postgrest.yml:    repo: "deb http://apt.postgresql.org/pub/repos/apt/ focal-pgdg {{ postgresql_major }}"

Those are all of the places where it's used in ansible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some parts of ansible build that use postgresql_major, and some that use the full version of postgres. If you think there is a way to refactor and change that into just using the version, I am in favor of that.

Otherwise, this was the pattern in vars.yml

postgres_major:
  - "15"
  - "orioledb-17"

# Full version strings for each major version
postgres_release:
  postgresorioledb-17: "17.0.1.032-orioledb"
  postgres15: "15.8.1.036"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or if you just think it might be better to move that line to another spot where other vars are defined, probably it won't be an issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's probably some easy minor cleanup we can do to ensure a little bit more consistency in how they're passed in, e.g. by getting rid of ansible_arguments and populating that from the underlying variables...will take a look at it

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

- name: Build AMI stage 2
Expand Down
185 changes: 185 additions & 0 deletions .github/workflows/qemu-image-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
name: Build QEMU image

on:
push:
branches:
- develop
- release/*
paths:
- '.github/workflows/qemu-image-build.yml'
- 'qemu-arm64-nix.pkr.hcl'
- 'common-nix.vars.pkr.hcl'
- 'ansible/vars.yml'
workflow_dispatch:

jobs:
prepare:
runs-on: ubuntu-latest
outputs:
postgres_versions: ${{ steps.set-versions.outputs.postgres_versions }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- uses: DeterminateSystems/nix-installer-action@main

- name: Set PostgreSQL versions - only builds pg15 atm
id: set-versions
run: |
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[0]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
echo "postgres_versions=$VERSIONS" >> $GITHUB_OUTPUT

build:
needs: prepare
strategy:
matrix:
postgres_version: ${{ fromJson(needs.prepare.outputs.postgres_versions) }}
runs-on: arm-native-runner
timeout-minutes: 150
permissions:
contents: write
packages: write
id-token: write

steps:
- name: Checkout Repo
uses: actions/checkout@v3

- uses: DeterminateSystems/nix-installer-action@main

- name: Run checks if triggered manually
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
SUFFIX=$(sudo nix run nixpkgs#yq -- ".postgres_release[\"postgres${{ matrix.postgres_version }}\"]" ansible/vars.yml | sed -E 's/[0-9\.]+(.*)$/\1/')
if [[ -z $SUFFIX ]] ; then
echo "Version must include non-numeric characters if built manually."
exit 1
fi

- name: enable KVM support
run: |
sudo chown runner /dev/kvm
sudo chmod 666 /dev/kvm

- name: Set PostgreSQL version environment variable
run: echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> $GITHUB_ENV

- name: Generate common-nix.vars.pkr.hcl
run: |
curl -L https://github.com/mikefarah/yq/releases/download/v4.45.1/yq_linux_arm64 -o yq && chmod +x yq
PG_VERSION=$(./yq '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
PG_VERSION=$(echo $PG_VERSION | tr -d '"') # Remove any surrounding quotes
echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
echo 'postgres-major-version = "'$POSTGRES_MAJOR_VERSION'"' >> common-nix.vars.pkr.hcl
# Ensure there's a newline at the end of the file
echo "" >> common-nix.vars.pkr.hcl

# TODO (darora): not quite sure why I'm having to uninstall and re-install these deps, but the build fails w/o this
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get remove -y qemu-efi-aarch64 cloud-image-utils qemu-system-arm qemu-utils
sudo apt-get install -y qemu-efi-aarch64 cloud-image-utils qemu-system-arm qemu-utils

- name: Build QEMU artifact
run: |
make init
GIT_SHA=${{github.sha}}
export PACKER_LOG=1
packer build -var "git_sha=${GIT_SHA}" -var-file="common-nix.vars.pkr.hcl" qemu-arm64-nix.pkr.hcl

- name: Grab release version
id: process_release_version
run: |
VERSION=$(cat common-nix.vars.pkr.hcl | sed -e 's/postgres-version = "\(.*\)"/\1/g')
echo "version=$VERSION" >> $GITHUB_OUTPUT

# - name: Create nix flake revision tarball
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaving some things commented out for now - will be needed later

# run: |
# GIT_SHA=${{github.sha}}
# MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}

# mkdir -p "/tmp/pg_upgrade_bin/${MAJOR_VERSION}"
# echo "$GIT_SHA" >> "/tmp/pg_upgrade_bin/${MAJOR_VERSION}/nix_flake_version"
# tar -czf "/tmp/pg_binaries.tar.gz" -C "/tmp/pg_upgrade_bin" .

- name: configure aws credentials - staging
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.DEV_AWS_ROLE }}
aws-region: "us-east-1"

- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public

- name: Build, tag, and push docker image to Amazon ECR Public
env:
REGISTRY: public.ecr.aws/w9p6e7k7
REGISTRY_ALIAS: supabase
REPOSITORY: postgres-vm-image
IMAGE_TAG: ${{ steps.process_release_version.outputs.version }}
run: |
docker build -f Dockerfile-kubernetes -t $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG .
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG

# - name: Upload software manifest to s3 staging
# run: |
# cd ansible
# ansible-playbook -i localhost \
# -e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
# -e "internal_artifacts_bucket=${{ secrets.ARTIFACTS_BUCKET }}" \
# -e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
# manifest-playbook.yml

# - name: Upload nix flake revision to s3 staging
# run: |
# 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

# - name: configure aws credentials - prod
# uses: aws-actions/configure-aws-credentials@v4
# with:
# role-to-assume: ${{ secrets.PROD_AWS_ROLE }}
# aws-region: "us-east-1"

# - name: Upload software manifest to s3 prod
# run: |
# cd ansible
# ansible-playbook -i localhost \
# -e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
# -e "internal_artifacts_bucket=${{ secrets.PROD_ARTIFACTS_BUCKET }}" \
# -e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
# manifest-playbook.yml

# - name: Upload nix flake revision to s3 prod
# run: |
# 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

# - name: Create release
# uses: softprops/action-gh-release@v1
# with:
# name: ${{ steps.process_release_version.outputs.version }}
# tag_name: ${{ steps.process_release_version.outputs.version }}
# target_commitish: ${{github.sha}}

# - name: Slack Notification on Failure
# if: ${{ failure() }}
# uses: rtCamp/action-slack-notify@v2
# env:
# SLACK_WEBHOOK: ${{ secrets.SLACK_NOTIFICATIONS_WEBHOOK }}
# SLACK_USERNAME: 'gha-failures-notifier'
# SLACK_COLOR: 'danger'
# SLACK_MESSAGE: 'Building Postgres AMI failed'
# SLACK_FOOTER: ''

- name: Cleanup resources after build
if: ${{ always() }}
run: |
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

- name: Cleanup resources on build cancellation
if: ${{ cancelled() }}
run: |
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
9 changes: 9 additions & 0 deletions Dockerfile-kubernetes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM alpine:3.21

ADD ./output-cloudimg/packer-cloudimg /disk/focal.qcow2

RUN apk add --no-cache qemu-system-aarch64 qemu-img openssh-client nftables cloud-utils-localds aavmf
# dev stuff
# RUN apk add --no-cache iproute2

CMD exec /bin/sh -c "trap : TERM INT; sleep 9999999999d & wait"
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
UPSTREAM_NIX_GIT_SHA := $(shell git rev-parse HEAD)
GIT_SHA := $(shell git describe --tags --always --dirty)

init: qemu-arm64-nix.pkr.hcl
packer init qemu-arm64-nix.pkr.hcl

output-cloudimg/packer-cloudimg: ansible qemu-arm64-nix.pkr.hcl
packer build -var "git_sha=$(UPSTREAM_NIX_GIT_SHA)" qemu-arm64-nix.pkr.hcl

disk/focal-raw.img: output-cloudimg/packer-cloudimg
mkdir -p disk
sudo qemu-img convert -O raw output-cloudimg/packer-cloudimg disk/focal-raw.img

alpine-image: output-cloudimg/packer-cloudimg
sudo nerdctl build . -t supabase-postgres-test:$(GIT_SHA) -f ./Dockerfile-kubernetes

clean:
rm -rf output-cloudimg

.PHONY: alpine-image init clean
2 changes: 1 addition & 1 deletion amazon-arm64-nix.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ build {
]
use_env_var_file = true
script = "ebssurrogate/scripts/surrogate-bootstrap-nix.sh"
execute_command = "sudo -S sh -c '. {{.EnvVarFile}} && {{.Path}}'"
execute_command = "sudo -S sh -c '. {{.EnvVarFile}} && cd /tmp/ansible-playbook && {{.Path}}'"
start_retry_timeout = "5m"
skip_clean = true
}
Expand Down
Loading
Loading