Skip to content

Commit c8a676f

Browse files
committed
chore(testinfra): initial ami test
1 parent ea32053 commit c8a676f

File tree

4 files changed

+369
-11
lines changed

4 files changed

+369
-11
lines changed

.github/workflows/testinfra.yml

+9-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ jobs:
2525

2626
- name: Run aio integration tests
2727
run: |
28-
pip3 install docker pytest pytest-testinfra
28+
# TODO: use poetry for pkg mgmt
29+
pip3 install boto3 boto3-stubs[essential] docker ec2instanceconnectcli pytest pytest-testinfra[paramiko,docker] requests
2930
pytest -vv testinfra/test_all_in_one.py
3031
3132
test-ami:
@@ -59,12 +60,6 @@ jobs:
5960
with:
6061
endpoint: builders
6162

62-
- uses: docker/login-action@v3
63-
with:
64-
registry: ghcr.io
65-
username: ${{ github.actor }}
66-
password: ${{ secrets.GITHUB_TOKEN }}
67-
6863
- uses: docker/build-push-action@v5
6964
with:
7065
load: true
@@ -118,14 +113,20 @@ jobs:
118113
tar xvf "$layer" -C ansible/files/postgres --strip-components 1
119114
done
120115
116+
# Packer doesn't support skipping registering the AMI for the ebssurrogate
117+
# builder, so we register an AMI with a fixed name and run tests on an
118+
# instance launched from that
119+
# https://github.com/hashicorp/packer/issues/4899
121120
- name: Build AMI
122121
run: |
123122
GIT_SHA=${{github.sha}}
124123
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.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.pkr.hcl
125124
126125
- name: Run tests
127126
run: |
128-
echo TODO
127+
# TODO: use poetry for pkg mgmt
128+
pip3 install boto3 boto3-stubs[essential] docker ec2instanceconnectcli pytest pytest-testinfra[paramiko,docker] requests
129+
pytest -vv testinfra/test_ami.py
129130
130131
- name: Cleanup resources on build cancellation
131132
if: ${{ cancelled() }}

testinfra/README.md

+52-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,64 @@
22

33
## Prerequisites
44

5+
- Docker
6+
- Packer
7+
- yq
8+
- Python deps:
9+
510
```sh
6-
pip3 install docker pytest pytest-testinfra requests
11+
pip3 install boto3 boto3-stubs[essential] docker ec2instanceconnectcli pytest pytest-testinfra[paramiko,docker] requests
712
```
813

914
## Running locally
1015

1116
```sh
17+
set -euo pipefail
1218
# cwd: repo root
1319
# docker must be running
14-
pytest -vv testinfra/*.py
20+
21+
# build extensions & pg binaries
22+
docker buildx build \
23+
$(yq 'to_entries | map(select(.value|type == "!!str")) | map(" --build-arg " + .key + "=" + .value) | join("")' 'ansible/vars.yml') \
24+
--target=extensions \
25+
--tag=supabase/postgres:extensions \
26+
--platform=linux/arm64 \
27+
--load \
28+
.
29+
mkdir -p /tmp/extensions ansible/files/extensions
30+
docker save supabase/postgres:extensions | tar xv -C /tmp/extensions
31+
for layer in /tmp/extensions/*/layer.tar; do
32+
tar xvf "$layer" -C ansible/files/extensions --strip-components 1
33+
done
34+
docker buildx build \
35+
--build-arg ubuntu_release=focal \
36+
--build-arg ubuntu_release_no=20.04 \
37+
--build-arg postgresql_major=15 \
38+
--build-arg postgresql_release=15.1 \
39+
--build-arg CPPFLAGS=-mcpu=neoverse-n1 \
40+
--file=docker/Dockerfile \
41+
--target=pg-deb \
42+
--tag=supabase/postgres:deb \
43+
--platform=linux/arm64 \
44+
--load \
45+
.
46+
mkdir -p /tmp/build ansible/files/postgres
47+
docker save supabase/postgres:deb | tar xv -C /tmp/build
48+
for layer in /tmp/build/*/layer.tar; do
49+
tar xvf "$layer" -C ansible/files/postgres --strip-components 1
50+
done
51+
52+
# build AMI
53+
AWS_PROFILE=supabase-dev packer build \
54+
-var-file=development-arm.vars.pkr.hcl \
55+
-var-file=common.vars.pkr.hcl \
56+
-var "ansible_arguments=" \
57+
-var "postgres-version=ci-ami-test" \
58+
-var "region=ap-southeast-1" \
59+
-var 'ami_regions=["ap-southeast-1"]' \
60+
-var "force-deregister=true" \
61+
amazon-arm64.pkr.hcl
62+
63+
# run tests
64+
AWS_PROFILE=supabase-dev pytest -vv -s testinfra/test_*.py
1565
```

testinfra/test_all_in_one.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# scope='session' uses the same container for all the tests;
2525
# scope='function' uses a new container per test function.
2626
@pytest.fixture(scope="session")
27-
def host(request):
27+
def host():
2828
# We build the image with the Docker CLI in path instead of using docker-py
2929
# (official Docker SDK for Python) because the latter doesn't use BuildKit,
3030
# so things like `ARG TARGETARCH` don't work:

0 commit comments

Comments
 (0)