Skip to content

Commit 601c3bb

Browse files
authored
chore: improve build cache with multistage docker (#528)
* Update dockerhub-release.yml * chore: add multistage docker build * chore: update test dockerfile * chore: run build on every pr * chore: update postgresql config for extensions * chore: install vault extension * chore: install plv8 * Revert "Update dockerhub-release.yml" This reverts commit 46a2d45. * chore: add initial migration files * chore: use labs syntax for checksum and git ref * chore: use ccache to build plv8 * chore: add pgsodium build stage * chore: rename postgres major arg and cleanup * chore: resolve plv8 package error * chore: run migrations on latest build * chore: optimise build steps * chore: load to local docker engine * chore: merge migrate workflow to build * chore: rearrange test steps * chore: skip cpan tests * chore: add pg_cron database setting * chore: update pgnet to match develop
1 parent 03e1953 commit 601c3bb

File tree

2 files changed

+784
-46
lines changed

2 files changed

+784
-46
lines changed

.github/workflows/test.yml

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,87 +9,92 @@ on:
99

1010
jobs:
1111
build:
12-
if: ${{ github.event_name != 'pull_request' }}
1312
runs-on: ubuntu-latest
13+
timeout-minutes: 180
14+
env:
15+
POSTGRES_PORT: 5478
16+
POSTGRES_PASSWORD: password
1417
steps:
1518
- uses: actions/checkout@v3
19+
- uses: docker/setup-buildx-action@v2
20+
- uses: docker/build-push-action@v3
21+
with:
22+
push: false
23+
load: true
24+
context: ansible
25+
tags: supabase/postgres:latest
26+
cache-from: type=gha
27+
cache-to: type=gha,mode=max
1628

17-
- run: docker compose up --abort-on-container-exit --build
18-
19-
migrate:
20-
runs-on: ubuntu-latest
21-
env:
22-
POSTGRES_PASSWORD: password
29+
- name: Start Postgres
30+
run: |
31+
docker run --rm --pull=never \
32+
-e POSTGRES_PASSWORD=${{ env.POSTGRES_PASSWORD }} \
33+
-p ${{ env.POSTGRES_PORT }}:5432 \
34+
--name supabase_postgres \
35+
-d supabase/postgres:latest
2336
24-
strategy:
25-
matrix:
26-
supabase-version: ["15.1.0.11"]
27-
timeout-minutes: 10
37+
- name: Install dbmate
38+
run: |
39+
curl -fsSL -o /usr/local/bin/dbmate https://github.com/amacneil/dbmate/releases/latest/download/dbmate-linux-amd64
40+
sudo chmod +x /usr/local/bin/dbmate
2841
29-
services:
30-
postgres:
31-
image: supabase/postgres:${{ matrix.supabase-version }}
32-
ports:
33-
- 5478:5432
34-
# Set health checks to wait until postgres has started
35-
options: >-
36-
--health-cmd "pg_isready -U postgres -h localhost"
37-
--health-interval 5s
38-
--health-timeout 5s
39-
--health-retries 10
42+
- name: Install pg_prove
43+
run: sudo cpan -T TAP::Parser::SourceHandler::pgTAP
4044
env:
41-
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
42-
volumes:
43-
# Disable migration by removing from entrypoint
44-
- /dev/null:/docker-entrypoint-initdb.d/migrate.sh
45-
46-
steps:
47-
- name: checkout
48-
uses: actions/checkout@v3
45+
SHELL: /bin/bash
4946

50-
- name: install dbmate
47+
- name: Wait for healthy database
5148
run: |
52-
curl -fsSL -o /usr/local/bin/dbmate https://github.com/amacneil/dbmate/releases/latest/download/dbmate-linux-amd64
53-
sudo chmod +x /usr/local/bin/dbmate
49+
count=0
50+
until [ "$(docker inspect -f '{{.State.Health.Status}}' "$container")" == "healthy" ]; do
51+
exit=$?
52+
count=$((count + 1))
53+
if [ $count -ge "$retries" ]; then
54+
echo "Retry $count/$retries exited $exit, no more retries left."
55+
docker stop -t 2 "$container"
56+
return $exit
57+
fi
58+
sleep 1;
59+
done;
60+
echo "$container container is healthy"
61+
env:
62+
retries: 20
63+
container: supabase_postgres
5464

55-
- name: migrate schema
65+
- name: Migrate schema
5666
run: ./migrations/db/migrate.sh
5767
env:
5868
USE_DBMATE: 1
59-
POSTGRES_PORT: 5478
69+
POSTGRES_PORT: ${{ env.POSTGRES_PORT }}
6070
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
6171

62-
- name: install pg_prove
63-
run: sudo cpan TAP::Parser::SourceHandler::pgTAP
64-
env:
65-
SHELL: /bin/bash
66-
67-
- name: run tests
72+
- name: Run tests
6873
run: pg_prove migrations/tests/test.sql
6974
env:
7075
PGHOST: localhost
71-
PGPORT: 5478
76+
PGPORT: ${{ env.POSTGRES_PORT }}
7277
PGUSER: postgres
7378
PGPASSWORD: ${{ env.POSTGRES_PASSWORD }}
7479

75-
- name: migrations should be idempotent
80+
- name: Check migrations are idempotent
7681
run: |
7782
for sql in ./migrations/db/migrations/*.sql; do
7883
echo "$0: running $sql"
7984
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -f "$sql"
8085
done
8186
env:
8287
PGHOST: localhost
83-
PGPORT: 5478
88+
PGPORT: ${{ env.POSTGRES_PORT }}
8489
PGDATABASE: postgres
8590
PGUSER: supabase_admin
8691
PGPASSWORD: ${{ env.POSTGRES_PASSWORD }}
8792

88-
- name: run tests
93+
- name: Run tests again
8994
run: pg_prove migrations/tests/test.sql
9095
env:
9196
PGHOST: localhost
92-
PGPORT: 5478
97+
PGPORT: ${{ env.POSTGRES_PORT }}
9398
PGUSER: postgres
9499
PGPASSWORD: ${{ env.POSTGRES_PASSWORD }}
95100

0 commit comments

Comments
 (0)