Skip to content

Commit ea32053

Browse files
committed
chore(testinfra): scaffold ami tests
1 parent bb7efb4 commit ea32053

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

.github/workflows/testinfra.yml

+105-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
workflow_dispatch:
66

77
jobs:
8-
build:
8+
test-all-in-one:
99
strategy:
1010
matrix:
1111
include:
@@ -27,3 +27,107 @@ jobs:
2727
run: |
2828
pip3 install docker pytest pytest-testinfra
2929
pytest -vv testinfra/test_all_in_one.py
30+
31+
test-ami:
32+
strategy:
33+
matrix:
34+
include:
35+
- runner: arm-runner
36+
arch: arm64
37+
ubuntu_release: focal
38+
ubuntu_version: 20.04
39+
mcpu: neoverse-n1
40+
runs-on: ${{ matrix.runner }}
41+
timeout-minutes: 150
42+
permissions:
43+
contents: write
44+
packages: write
45+
id-token: write
46+
47+
steps:
48+
- name: Checkout Repo
49+
uses: actions/checkout@v4
50+
51+
- id: args
52+
uses: mikefarah/yq@master
53+
with:
54+
cmd: yq 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' 'ansible/vars.yml'
55+
56+
- run: docker context create builders
57+
58+
- uses: docker/setup-buildx-action@v3
59+
with:
60+
endpoint: builders
61+
62+
- uses: docker/login-action@v3
63+
with:
64+
registry: ghcr.io
65+
username: ${{ github.actor }}
66+
password: ${{ secrets.GITHUB_TOKEN }}
67+
68+
- uses: docker/build-push-action@v5
69+
with:
70+
load: true
71+
build-args: |
72+
${{ steps.args.outputs.result }}
73+
target: extensions
74+
tags: supabase/postgres:extensions
75+
platforms: linux/${{ matrix.arch }}
76+
cache-from: |
77+
type=gha,scope=${{ github.ref_name }}-extensions
78+
type=gha,scope=${{ github.base_ref }}-extensions
79+
type=gha,scope=develop-extensions
80+
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-extensions
81+
82+
- name: Extract built packages
83+
run: |
84+
mkdir -p /tmp/extensions ansible/files/extensions
85+
docker save supabase/postgres:extensions | tar xv -C /tmp/extensions
86+
for layer in /tmp/extensions/*/layer.tar; do
87+
tar xvf "$layer" -C ansible/files/extensions --strip-components 1
88+
done
89+
90+
- id: version
91+
run: echo "${{ steps.args.outputs.result }}" | grep "postgresql" >> "$GITHUB_OUTPUT"
92+
93+
- name: Build Postgres deb
94+
uses: docker/build-push-action@v5
95+
with:
96+
load: true
97+
file: docker/Dockerfile
98+
target: pg-deb
99+
build-args: |
100+
ubuntu_release=${{ matrix.ubuntu_release }}
101+
ubuntu_release_no=${{ matrix.ubuntu_version }}
102+
postgresql_major=${{ steps.version.outputs.postgresql_major }}
103+
postgresql_release=${{ steps.version.outputs.postgresql_release }}
104+
CPPFLAGS=-mcpu=${{ matrix.mcpu }}
105+
tags: supabase/postgres:deb
106+
platforms: linux/${{ matrix.arch }}
107+
cache-from: |
108+
type=gha,scope=${{ github.ref_name }}-deb
109+
type=gha,scope=${{ github.base_ref }}-deb
110+
type=gha,scope=develop-deb
111+
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-deb
112+
113+
- name: Extract Postgres deb
114+
run: |
115+
mkdir -p /tmp/build ansible/files/postgres
116+
docker save supabase/postgres:deb | tar xv -C /tmp/build
117+
for layer in /tmp/build/*/layer.tar; do
118+
tar xvf "$layer" -C ansible/files/postgres --strip-components 1
119+
done
120+
121+
- name: Build AMI
122+
run: |
123+
GIT_SHA=${{github.sha}}
124+
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
125+
126+
- name: Run tests
127+
run: |
128+
echo TODO
129+
130+
- name: Cleanup resources on build cancellation
131+
if: ${{ cancelled() }}
132+
run: |
133+
aws ec2 --region ap-southeast-1 describe-instances --filters "Name=tag:packerExecutionId,Values=${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -I {} aws ec2 terminate-instances --instance-ids {}

amazon-arm64.pkr.hcl

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ variable "packer-execution-id" {
8787
default = "unknown"
8888
}
8989

90+
variable "force-deregister" {
91+
type = bool
92+
default = false
93+
}
94+
9095
# source block
9196
source "amazon-ebssurrogate" "source" {
9297
profile = "${var.profile}"
@@ -99,6 +104,7 @@ source "amazon-ebssurrogate" "source" {
99104
instance_type = "c6g.4xlarge"
100105
region = "${var.region}"
101106
#secret_key = "${var.aws_secret_key}"
107+
force_deregister = var.force-deregister
102108

103109
# Use latest official ubuntu focal ami owned by Canonical.
104110
source_ami_filter {

0 commit comments

Comments
 (0)