Skip to content

Commit 081a563

Browse files
committed
feat: add test-before-push to CI pipeline
- Rename build-and-release to build-test-release - Build Docker image locally first, then test before pushing - Add PostgreSQL health checks: pg_isready, version check, extension listing, basic SQL CRUD test - Update nix evaluation to use psql_17_slim/bin (matching new Alpine Dockerfile) - Only push to GHCR after all tests pass
1 parent 3088d5d commit 081a563

1 file changed

Lines changed: 61 additions & 28 deletions

File tree

.github/workflows/ci-kilobase-runner.yaml

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ jobs:
3131
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
3232
max-jobs = 4
3333
34-
- name: Evaluate PG17 derivation
35-
run: nix build --dry-run .#packages.x86_64-linux."psql_17/bin" --accept-flake-config
34+
- name: Evaluate PG17 slim derivation
35+
run: nix build --dry-run .#packages.x86_64-linux."psql_17_slim/bin" --accept-flake-config
3636

3737
detect-version:
3838
runs-on: ubuntu-latest
@@ -75,7 +75,7 @@ jobs:
7575
echo "changed=true" >> $GITHUB_OUTPUT
7676
fi
7777
78-
build-and-release:
78+
build-test-release:
7979
needs: [check, detect-version]
8080
if: |
8181
github.event_name == 'workflow_dispatch' ||
@@ -111,33 +111,66 @@ jobs:
111111
username: ${{ github.actor }}
112112
password: ${{ secrets.GITHUB_TOKEN }}
113113

114-
- name: Get build args from vars.yml
115-
id: args
114+
# Step 1: Build locally (no push yet)
115+
- name: Build Docker image locally
116116
run: |
117-
nix run nixpkgs#nushell -- -c '
118-
open ansible/vars.yml
119-
| items { |key value| {name: $key, item: $value} }
120-
| where { |it| ($it.item | describe) == "string" }
121-
| each { |it| $"($it.name)=($it.item)" }
122-
| str join "\n"
123-
| save --append $env.GITHUB_OUTPUT
124-
'
125-
126-
- name: Build and push Docker image
127-
uses: docker/build-push-action@v5
128-
with:
129-
push: true
130-
build-args: |
131-
${{ steps.args.outputs.result }}
132-
target: production
133-
tags: |
134-
ghcr.io/${{ needs.detect-version.outputs.owner }}/postgres:${{ needs.detect-version.outputs.tag }}
135-
ghcr.io/${{ needs.detect-version.outputs.owner }}/postgres:latest
136-
platforms: linux/amd64
137-
cache-from: type=gha,scope=${{ github.ref_name }}-pg17-kbve
138-
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-pg17-kbve
139-
file: Dockerfile-17
117+
docker build \
118+
-f Dockerfile-17 \
119+
-t pg-test:17 \
120+
--target production \
121+
.
122+
123+
# Step 2: Test the image
124+
- name: Start PostgreSQL container
125+
run: |
126+
docker run -d \
127+
--name pg-test-17 \
128+
-e POSTGRES_PASSWORD=testpass \
129+
-e POSTGRES_HOST_AUTH_METHOD=trust \
130+
-p 5432:5432 \
131+
pg-test:17
132+
133+
- name: Wait for PostgreSQL to be ready
134+
run: |
135+
echo "Waiting for PostgreSQL to start..."
136+
for i in $(seq 1 30); do
137+
if docker exec pg-test-17 pg_isready -U postgres -h localhost 2>/dev/null; then
138+
echo "PostgreSQL is ready"
139+
exit 0
140+
fi
141+
echo "Attempt $i/30 - waiting..."
142+
sleep 2
143+
done
144+
echo "PostgreSQL failed to start"
145+
docker logs pg-test-17
146+
exit 1
147+
148+
- name: Run PostgreSQL health checks
149+
run: |
150+
echo "=== PostgreSQL version ==="
151+
docker exec pg-test-17 psql -U supabase_admin -d postgres -c "SELECT version();"
140152
153+
echo "=== Installed extensions ==="
154+
docker exec pg-test-17 psql -U supabase_admin -d postgres -c "SELECT name, default_version FROM pg_available_extensions ORDER BY name;"
155+
156+
echo "=== Test basic SQL ==="
157+
docker exec pg-test-17 psql -U supabase_admin -d postgres -c "CREATE TABLE test_health (id serial PRIMARY KEY, data text); INSERT INTO test_health (data) VALUES ('ok'); SELECT * FROM test_health; DROP TABLE test_health;"
158+
159+
- name: Cleanup test container
160+
if: always()
161+
run: docker rm -f pg-test-17 || true
162+
163+
# Step 3: Push to GHCR (only after tests pass)
164+
- name: Tag and push Docker image
165+
run: |
166+
OWNER="${{ needs.detect-version.outputs.owner }}"
167+
TAG="${{ needs.detect-version.outputs.tag }}"
168+
docker tag pg-test:17 "ghcr.io/${OWNER}/postgres:${TAG}"
169+
docker tag pg-test:17 "ghcr.io/${OWNER}/postgres:latest"
170+
docker push "ghcr.io/${OWNER}/postgres:${TAG}"
171+
docker push "ghcr.io/${OWNER}/postgres:latest"
172+
173+
# Step 4: Create release
141174
- name: Create GitHub Release
142175
uses: softprops/action-gh-release@v1
143176
with:

0 commit comments

Comments
 (0)