Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
8432172
feat: nix-ami-changes
samrose Jun 24, 2024
a96b678
chore: version bump
samrose Jun 24, 2024
ef1f339
chore: remap branch for ami build
samrose Jun 24, 2024
a622d4a
chore: bump version
samrose Jun 24, 2024
41957bc
chore: bump version to trigger build
samrose Jun 24, 2024
02583d0
feat: use /var/lib/postgresql as home for postgres user
samrose Jun 24, 2024
7fc4fb7
fix: makre sure bashrc exists
samrose Jun 25, 2024
d4ac912
fix: minor refactor
samrose Jun 25, 2024
e8293f6
chore: moving to a different PR
samrose Jun 25, 2024
7aa342b
chore: bump version and remove deprecated workflow
samrose Jun 25, 2024
bc625aa
feat: parallel testinfra-nix just for ami test
samrose Jun 25, 2024
1623a4a
chore: testing just testinfra-nix workflow
samrose Jun 25, 2024
be5999f
chore: re-run build
samrose Jun 25, 2024
dad5839
chore: re-trigger testinfra
samrose Jun 25, 2024
108797a
fix: wait for AMI to reach available state
samrose Jun 25, 2024
9663718
fix: use ami id in stage 3 testinfra ami-test
samrose Jun 25, 2024
1441590
fix: env vars
samrose Jun 25, 2024
f263a3a
chore: bump version
samrose Jun 25, 2024
3b49c7c
chore: restore packer build
samrose Jun 26, 2024
2c05810
chore: create a parallel test
samrose Jun 26, 2024
4fbf6c7
chore: bump version
samrose Jun 26, 2024
8dcd294
fix: capture and use ami name
samrose Jun 26, 2024
8c76c04
fix: aws regions
samrose Jun 26, 2024
89c15a5
chore: capture ami name
samrose Jun 26, 2024
817aa27
chore: force_deregister all ami prior to create new
samrose Jun 26, 2024
87d286f
fix: pass same ami name each time
samrose Jun 26, 2024
93c3890
fix: manage concurrency of testinfra builds
samrose Jun 26, 2024
d2c802c
fix: no args on stage 2
samrose Jun 26, 2024
f719e66
fix: re-intro original testinfra
samrose Jun 26, 2024
a0add7f
Revert "fix: re-intro original testinfra"
samrose Jun 26, 2024
e018907
chore: push to re-trigger build
samrose Jun 26, 2024
3285ed5
chore: update instance name
samrose Jun 26, 2024
3b988a5
fix: location of pg_isready binary
samrose Jul 1, 2024
9e84ae2
fix: re-intro conventional ami infra test + more symlinks where expected
samrose Jul 1, 2024
765ad9d
fix: dealing with symlink creation issues
samrose Jul 1, 2024
adb7fe3
fix: try concurrency rules on on all large builds
samrose Jul 1, 2024
42ef79d
chore; try with no concurrency rules
samrose Jul 1, 2024
d5b4643
chore: rerun
samrose Jul 1, 2024
e18c74f
feat: consolidate ansible and use vars to toggle AMI builds
samrose Jul 3, 2024
5717efd
fix: resolving merge conflict
samrose Jul 3, 2024
ddc6b1d
chore: merge conflict
samrose Jul 3, 2024
83fd3ed
Revert "chore: merge conflict"
samrose Jul 3, 2024
9dbca39
fix: update ansible location for script
samrose Jul 3, 2024
5a65cdc
fix: ansible consolidated location
samrose Jul 3, 2024
89c6831
fix: set up modes on system-setup
samrose Jul 3, 2024
97a6748
fix: set vars
samrose Jul 3, 2024
16d5e40
fix: python True and False in extra_vars
samrose Jul 3, 2024
9c59812
fix: adj vars
samrose Jul 4, 2024
ccfbffa
fix: set all ami vars
samrose Jul 4, 2024
02f7f4e
fix: args as json
samrose Jul 4, 2024
7460e47
fix: nixpkg_mode
samrose Jul 4, 2024
e3860ec
fix: refining mode rules
samrose Jul 4, 2024
625a2cc
fix: consolidate create dirs
samrose Jul 4, 2024
fb05966
fix: cleaning up modes
samrose Jul 4, 2024
8c76bda
fix: systemd psql service reload targets
samrose Jul 4, 2024
a83bc8b
fix: starting postgres issues
samrose Jul 4, 2024
86f39bd
fix: timing for pgsodium_getkey script
samrose Jul 4, 2024
6ee402e
fix: packer file upload on stage 2
samrose Jul 4, 2024
9460d75
fix: consolidation of ansible location
samrose Jul 5, 2024
197a2e3
fix: stage2 fix hostname
samrose Jul 5, 2024
56327cc
fix: limit stage that tasks run on
samrose Jul 5, 2024
510afe1
fix: setting hosts only on stage 2 nix ami
samrose Jul 5, 2024
dd16965
fix: rewrite hosts in ansible to allow for re-use of playbook file
samrose Jul 5, 2024
eebfcf6
chore: trigger checks
samrose Jul 5, 2024
002cd32
fix: pgsodium getkey is different for deb vs nix builds
samrose Jul 5, 2024
d165ffa
fix: consolidated files location
samrose Jul 5, 2024
feb0db6
fix: on stage2 postgres server is already started at this point
samrose Jul 5, 2024
87891cc
fix: without env vars
samrose Jul 5, 2024
98d91c3
fix: vars on the right mode
samrose Jul 6, 2024
86a129f
fix: dedupe
samrose Jul 6, 2024
831ef50
fix: locales
samrose Jul 6, 2024
c96e28c
fix: locales
samrose Jul 6, 2024
6303303
chore: try step with no env vars
samrose Jul 6, 2024
d6a4851
fix: no need to start pg at this point stage2
samrose Jul 6, 2024
062b236
fix: yaml
samrose Jul 6, 2024
39908ea
fix: more cleanup of modes
samrose Jul 6, 2024
03f41ed
fix: snapd already absent at this point + consolidate tasks
samrose Jul 6, 2024
5659c84
fix: already absent at this point
samrose Jul 6, 2024
0cf650c
fix: service not present at this stage
samrose Jul 6, 2024
cfa0f78
fix: disable different services for first boot depending on mode
samrose Jul 6, 2024
8361e23
fix: pg already restarted at this point in stage 2
samrose Jul 6, 2024
3c2dd37
fix: no start on stage2
samrose Jul 7, 2024
026fa3e
fix: try to start in stage2
samrose Jul 7, 2024
ece9df0
chore: include env vars for stage2
samrose Jul 7, 2024
b12a001
fix: stop before starting
samrose Jul 7, 2024
46af795
fix: debpkg mode only
samrose Jul 7, 2024
0c83c35
fix: should use conventional path
samrose Jul 8, 2024
2de4497
fix: need to locale-gen prior to initdb
samrose Jul 8, 2024
4f8e7a5
fix: nix build needs .env
samrose Jul 8, 2024
b5d6813
fix: stage2 treatment of pgsodium_getket
samrose Jul 9, 2024
828d474
chore: re-introduce permission checks via osquery
samrose Jul 9, 2024
4090305
fix: correct the path to files
samrose Jul 9, 2024
bcd79e7
feat: wip Docker psql bundle base image from Nix
samrose Jul 9, 2024
62447d8
feat: nix-based docker postgres docker image
samrose Jul 9, 2024
6a1c041
feat: parallel nix pg_upgrade test WIP run
samrose Jul 10, 2024
cb28ca2
fix: ref the correct common vars
samrose Jul 10, 2024
452a7e3
fix: do not dl scripts from s3
samrose Jul 10, 2024
212c4cd
chore: work out nix version of entrypoint
samrose Jul 10, 2024
6801a76
fix: increase retries
samrose Jul 10, 2024
eaa997e
fix: no other entrypoint needed just to start the container
samrose Jul 10, 2024
6a27f0b
fix: working with entrypoint file
samrose Jul 10, 2024
f11f87a
fix: try again without extra entrypoint script
samrose Jul 11, 2024
dedf508
fix: timeout instead of retries
samrose Jul 11, 2024
d0fa970
fix: internal port currenty 5435
samrose Jul 11, 2024
e4f861e
fix: match ports
samrose Jul 11, 2024
82746c6
fix: also match port on call to pg_isready
samrose Jul 11, 2024
93170c1
feat: intro next step
samrose Jul 11, 2024
f6d68d9
fix: just write to stdout stderr for now
samrose Jul 11, 2024
bb9c5ba
test: checking contents of dir
samrose Jul 11, 2024
bd622cf
chore: re-run after publishing full docker image
samrose Jul 11, 2024
a5f9841
test: port 5432
samrose Jul 11, 2024
08f2372
test: tmp disable
samrose Jul 11, 2024
195ca7c
test: now use entrypoint-nix.sh
samrose Jul 11, 2024
3ab8d72
test: debug logging
samrose Jul 11, 2024
5fd5e35
test: just start postgres
samrose Jul 11, 2024
0b32269
test: w/o su postgres
samrose Jul 11, 2024
33f35fa
test: no entrypoint
samrose Jul 11, 2024
1369547
test: flags
samrose Jul 11, 2024
ab1cbe6
test: try without initdb arg
samrose Jul 11, 2024
7c421b2
test: revert port
samrose Jul 11, 2024
9cac484
test: run migrate.sh
samrose Jul 11, 2024
486e708
test: dbg migrate
samrose Jul 11, 2024
5f0d4bb
test: adj running in entrypoint
samrose Jul 11, 2024
31095c9
test: matching parity with existing docker method
samrose Jul 11, 2024
a071cde
test: entrypoint re-intro
samrose Jul 11, 2024
7f0e3e9
test: trying gosu on sed
samrose Jul 11, 2024
2d01076
test: use perl instead
samrose Jul 11, 2024
d6dfc6e
test: for now trying an alternate image for testing
samrose Jul 11, 2024
2aa3233
test: run initial pg_prove tests
samrose Jul 11, 2024
e07591c
test: may need client
samrose Jul 11, 2024
a031fe3
test: align ports
samrose Jul 11, 2024
00c1576
test: add next step in testing
samrose Jul 11, 2024
494967b
test: run the rest
samrose Jul 11, 2024
2af8e67
test: revising pg_upgrade test to work with nix-built psql bundle
samrose Jul 12, 2024
f75374d
test: run what works for now
samrose Jul 12, 2024
0de673e
test: rm for now
samrose Jul 12, 2024
e8ec133
test: include in testing image
samrose Jul 12, 2024
a61baf9
test: lets try to install the psql_15 from this checkout
samrose Jul 15, 2024
0397f69
fix: matching quote
samrose Jul 15, 2024
cc133e7
test: re-run after image re-deployed
samrose Jul 15, 2024
bcf1ff2
test: add the actual run of pg_upgrade initiate
samrose Jul 15, 2024
0815c43
test: try to run the rest of pg_upgrade test
samrose Jul 16, 2024
8456e3d
fix: right path to script
samrose Jul 16, 2024
f7c1454
test: mod complete script to testing conditions
samrose Jul 16, 2024
b0fd4ef
feat: start of AIO Dockerfile
samrose Jul 22, 2024
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
120 changes: 120 additions & 0 deletions .github/workflows/ami-release-nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Release AMI Nix

on:
# push:
# branches:
# - sam/nix-and-conventional-ami
# - '.github/workflows/ami-release-nix.yml'
# - 'common-nix.vars.pkr.hcl'
workflow_dispatch:

jobs:
build:
strategy:
matrix:
include:
- runner: arm-runner
arch: arm64
ubuntu_release: focal
ubuntu_version: 20.04
mcpu: neoverse-n1
runs-on: ${{ matrix.runner }}
timeout-minutes: 150
permissions:
contents: write
packages: write
id-token: write

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

- name: Run checks if triggered manually
if: ${{ github.event_name == 'workflow_dispatch' }}
# Update `ci.yaml` too if changing constraints.
run: |
SUFFIX=$(sed -E 's/postgres-version = "[0-9\.]+(.*)"/\1/g' common-nix.vars.pkr.hcl)
if [[ -z $SUFFIX ]] ; then
echo "Version must include non-numeric characters if built manually."
exit 1
fi

# extensions are build in nix prior to this step
# so we can just use the binaries from the nix store
# for postgres, extensions and wrappers

- name: Build AMI stage 1
run: |
packer init amazon-arm64-nix.pkr.hcl
GIT_SHA=${{github.sha}}
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=" amazon-arm64-nix.pkr.hcl

- name: Build AMI stage 2
run: |
packer init stage2-nix-psql.pkr.hcl
GIT_SHA=${{github.sha}}
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" stage2-nix-psql.pkr.hcl

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

- 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: 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 }}" \
manifest-playbook.yml


#Our self hosted github runner already has permissions to publish images
#but they're limited to only that;
#so if we want s3 access we'll need to config credentials with the below steps
# (which overwrites existing perms) after the ami build

- 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 }}" \
manifest-playbook.yml



- 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 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 -n 1 -I {} aws ec2 terminate-instances --instance-ids {}
6 changes: 5 additions & 1 deletion .github/workflows/nix-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ jobs:
steps:

- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref || github.ref }}
fetch-depth: 0
fetch-tags: true
- name: aws-creds
uses: aws-actions/configure-aws-credentials@v4
with:
Expand Down
52 changes: 0 additions & 52 deletions .github/workflows/nix-cache-upload.yml

This file was deleted.

142 changes: 142 additions & 0 deletions .github/workflows/test-pg-upgrade-nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: Test pg_upgrade

on:
push:
branches:
- develop
- pcnc/auto-pg_upgrade-testing
- sam/nix-docker-build
workflow_dispatch:

permissions:
id-token: write

jobs:
test:
strategy:
matrix:
base_pg_version:
- 15.6.1.90-nix-staged
runs-on: arm-runner
timeout-minutes: 30
defaults:
run:
working-directory: ./tests/pg_upgrade
env:
PGPORT: 5478
PGPASSWORD: postgres
PGDATABASE: postgres
PGUSER: supabase_admin
PGHOST: localhost
PG_MAJOR_VERSION: 15
IS_CI: true
container: pg_upgrade_test
steps:
- uses: actions/checkout@v3

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

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

# - name: copy needed scripts
# run: cp -r ../../nix/tools/pg_upgrade_scripts scripts/

- run: docker context create builders
- uses: docker/setup-buildx-action@v2
with:
endpoint: builders
driver-opts: image=moby/buildkit:v0.11.6
buildkitd-flags: --debug

- name: Start Postgres
run: |
docker rm -f "$container" || true
docker run --name "$container" --env-file .env \
-v "$(pwd)/scripts:/tmp/upgrade" \
--entrypoint "/tmp/upgrade/entrypoint-nix.sh" -d \
-p ${PGPORT}:5432 \
"samrose/postgresql-15-aarch64-linux-pg-upgrade-test:${{ matrix.base_pg_version }}"
docker logs "$container"

- name: Check container status
run: |
docker ps -a
docker inspect "$container" --format '{{.State.Status}}'
docker inspect "$container" --format '{{.State.ExitCode}}'

- name: Install psql
run: |
sudo apt update
sudo apt install -y --no-install-recommends postgresql-client

- name: Install pg_prove
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends perl cpanminus
sudo cpanm -n App::cpanminus
sudo cpanm -n TAP::Parser::SourceHandler::pgTAP
env:
SHELL: /bin/bash
PERL_MM_USE_DEFAULT: 1
PERL_MM_NONINTERACTIVE: 1

- name: Wait for healthy database
run: |
start_time=$(date +%s)
timeout=600 # 10 minutes in seconds

while ! docker exec "$container" bash -c "pg_isready -p 5432"; do
current_time=$(date +%s)
elapsed=$((current_time - start_time))

if [ $elapsed -ge $timeout ]; then
echo "Timeout reached after ${elapsed} seconds. Database is not ready."
docker logs "$container"
docker rm -f "$container"
exit 1
fi

echo "Database not ready. Waiting..."
sleep 5
done

echo "Database is ready after ${elapsed} seconds."

- name: Run migrations
run: docker exec "$container" bash -c "/docker-entrypoint-initdb.d/migrate.sh 2>&1"

- name: Run initial tests
run: pg_prove "../../migrations/tests/test.sql"
env:
PERL5LIB: /usr/local/lib/perl5

- name: Apply pre-upgrade fixtures
run: |
psql -f "./tests/98-data-fixtures.sql"
psql -f "./tests/99-fixtures.sql"

- name: Initiate upgrade
run: docker exec "$container" bash -c '/tmp/upgrade/initiate-nix.sh "github:supabase/postgres/sam/nix-docker-build#psql_15/bin" "github:supabase/postgres/develop#psql_15/bin"; exit $?'

- name: Complete pg_upgrade
run: docker exec pg_upgrade_test bash -c '/tmp/upgrade/complete-nix.sh; exit $?'

- name: Run post-upgrade tests
run: |
pg_prove ./tests/01-schema.sql
pg_prove ./tests/02-data.sql
pg_prove ./tests/03-settings.sql

- name: Clean up container
if: ${{ always() }}
continue-on-error: true
run: docker rm -f "$container" || true
67 changes: 67 additions & 0 deletions .github/workflows/testinfra-nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Testinfra Integration Tests Nix

on:
#pull_request:
workflow_dispatch:

jobs:
test-ami-nix:
strategy:
fail-fast: false
matrix:
include:
- runner: arm-runner
arch: arm64
ubuntu_release: focal
ubuntu_version: 20.04
mcpu: neoverse-n1
runs-on: ${{ matrix.runner }}
timeout-minutes: 150
permissions:
contents: write
packages: write
id-token: write

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

- id: args
uses: mikefarah/yq@master
with:
cmd: yq 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' 'ansible/vars.yml'

- run: docker context create builders

- uses: docker/setup-buildx-action@v3
with:
endpoint: builders

- name: Build AMI stage 1
run: |
packer init amazon-arm64-nix.pkr.hcl
GIT_SHA=${{github.sha}}
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=ci-ami-test" -var "region=ap-southeast-1" -var 'ami_regions=["ap-southeast-1"]' -var "force-deregister=true" amazon-arm64-nix.pkr.hcl

- name: Build AMI stage 2
run: |
packer init stage2-nix-psql.pkr.hcl
GIT_SHA=${{github.sha}}
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 "postgres-version=ci-ami-test" -var "region=ap-southeast-1" -var 'ami_regions=["ap-southeast-1"]' -var "force-deregister=true" stage2-nix-psql.pkr.hcl

- name: Run tests
timeout-minutes: 10
run: |
# TODO: use poetry for pkg mgmt
pip3 install boto3 boto3-stubs[essential] docker ec2instanceconnectcli pytest pytest-testinfra[paramiko,docker] requests
pytest -vv -s testinfra/test_ami_nix.py

- name: Cleanup resources on build cancellation
if: ${{ cancelled() }}
run: |
aws ec2 --region ap-southeast-1 describe-instances --filters "Name=tag:packerExecutionId,Values=${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -n 1 -I {} aws ec2 terminate-instances --region ap-southeast-1 --instance-ids {}

- name: Cleanup resources on build cancellation
if: ${{ always() }}
run: |
aws ec2 --region ap-southeast-1 describe-instances --filters "Name=tag:testinfra-run-id,Values=${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -n 1 -I {} aws ec2 terminate-instances --region ap-southeast-1 --instance-ids {} || true
Loading
Loading