Skip to content

Commit e80b54c

Browse files
authored
Merge pull request #14 from ruxwez/implement-runtime-tests
Refactor Dockerfile and workflows for build and runtime testing
2 parents 0aac34c + 20c18a4 commit e80b54c

11 files changed

Lines changed: 50 additions & 11 deletions

File tree

.docker/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARG POSTGRES_VERSION=17
22

3-
FROM docker.io/golang:1.26-alpine AS builder
3+
FROM mirror.gcr.io/golang:1.26-alpine AS builder
44

55
WORKDIR /app
66

@@ -11,7 +11,7 @@ COPY . .
1111

1212
RUN go build -o main .
1313

14-
FROM docker.io/postgres:${POSTGRES_VERSION}
14+
FROM mirror.gcr.io/postgres:${POSTGRES_VERSION}
1515

1616
WORKDIR /opt/app
1717

.docker/runtime-test.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
POSTGRES_VERSION="${POSTGRES_VERSION:-18}"
6+
IMAGE="${IMAGE:-postgres-extensor-runtime-test}"
7+
CONTAINER_NAME="${CONTAINER_NAME:-postgres-extensor-runtime-test-$$}"
8+
9+
trap 'docker rm -f "${CONTAINER_NAME}" >/dev/null 2>&1 || true' EXIT
10+
11+
if [ "${SKIP_BUILD:-false}" != "true" ]; then
12+
docker build -f .docker/Dockerfile -t "${IMAGE}" --build-arg POSTGRES_VERSION="${POSTGRES_VERSION}" .
13+
fi
14+
15+
docker run -d --rm --name "${CONTAINER_NAME}" -e POSTGRES_PASSWORD=postgres "${IMAGE}" >/dev/null
16+
17+
echo "Waiting for PostgreSQL to start..."
18+
until docker exec "${CONTAINER_NAME}" pg_isready -U postgres >/dev/null 2>&1; do
19+
sleep 1
20+
done
21+
22+
echo "Running SQL tests..."
23+
docker exec -i "${CONTAINER_NAME}" psql -v ON_ERROR_STOP=1 -U postgres < .docker/runtime-test.sql
24+
echo "Tests passed successfully!"

.docker/runtime-test.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE EXTENSION IF NOT EXISTS vector;
2+
CREATE EXTENSION IF NOT EXISTS pgmq;
3+
CREATE EXTENSION IF NOT EXISTS postgis;
4+
5+
SELECT extname FROM pg_extension WHERE extname IN ('vector','pgmq','postgis');
6+
SELECT name FROM pg_available_extensions WHERE name IN ('pg_stat_statements');

.github/workflows/docker-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
postgres_version: ["latest", "18", "17", "16", "15", "14", "13"]
14+
postgres_version: ["latest", "18", "17", "16", "15", "14"]
1515
fail-fast: false
1616

1717
steps:

.github/workflows/pr-test.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: ubuntu-latest
1919
strategy:
2020
matrix:
21-
postgres_version: ["latest", "18", "17", "16", "15", "14", "13"]
21+
postgres_version: ["latest", "18", "17", "16", "15", "14"]
2222
platform: ["linux/amd64"]
2323
fail-fast: false
2424

@@ -41,7 +41,7 @@ jobs:
4141
file: .docker/Dockerfile
4242
platforms: ${{ matrix.platform }}
4343
push: false
44-
load: false
44+
load: true
4545
tags: |
4646
pr-test/${{ github.repository }}:postgres-${{ matrix.postgres_version }}-pr${{ github.event.pull_request.number }}
4747
build-args: |
@@ -55,6 +55,12 @@ jobs:
5555
echo "Built (multi-arch) for POSTGRES_VERSION=${{ matrix.postgres_version }} PLATFORM=${{ matrix.platform }}"
5656
echo "Tag used: pr-test/${{ github.repository }}:postgres-${{ matrix.postgres_version }}-pr${{ github.event.pull_request.number }}"
5757
58+
- name: Run runtime test
59+
env:
60+
SKIP_BUILD: "true"
61+
IMAGE: pr-test/${{ github.repository }}:postgres-${{ matrix.postgres_version }}-pr${{ github.event.pull_request.number }}
62+
run: bash .docker/runtime-test.sh
63+
5864
# Job resumen que agrupa todos los builds de la matriz
5965
build-complete:
6066
name: All builds passed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
PG_VERSION ?= 18
22

3-
.PHONY: test build
3+
.PHONY: test build runtime-test
44

55
test:
66
docker build -f .docker/Dockerfile.test -t postgres-extensor-test .
77
-docker rmi postgres-extensor-test > /dev/null
88

99
build:
1010
docker build -f .docker/Dockerfile -t ruxwez/postgres:$(PG_VERSION) --build-arg POSTGRES_VERSION=$(PG_VERSION) .
11+
12+
runtime-test:
13+
POSTGRES_VERSION=$(PG_VERSION) bash .docker/runtime-test.sh

extensions/builddeps_install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
var buildDepsInstall = plyd.New(
1111
"build-deps-install",
1212
plyd.NewHandlersList(
13-
plyd.NewHandler(">=13.0.0, <19.0.0", func(ins *instance.InstanceInfo) error {
13+
plyd.NewHandler(">=14.0.0, <19.0.0", func(ins *instance.InstanceInfo) error {
1414
if err := plyd.Run("apt-get update -qq"); err != nil {
1515
return err
1616
}

extensions/builddeps_remove.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
var buildDepsRemove = plyd.New(
1111
"build-deps-remove",
1212
plyd.NewHandlersList(
13-
plyd.NewHandler(">=13.0.0, <19.0.0", func(ins *instance.InstanceInfo) error {
13+
plyd.NewHandler(">=14.0.0, <19.0.0", func(ins *instance.InstanceInfo) error {
1414
if err := plyd.Run(fmt.Sprintf(
1515
"apt-get remove -y -qq git make gcc postgresql-server-dev-%s",
1616
ins.PostgreSQL.Mayor,

extensions/pgvector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
var pgvector = plyd.New(
1111
"pgvector",
1212
plyd.NewHandlersList(
13-
plyd.NewHandler(">=13.0.0, <19.0.0", func(ins *instance.InstanceInfo) error {
13+
plyd.NewHandler(">=14.0.0, <19.0.0", func(ins *instance.InstanceInfo) error {
1414
err := plyd.Run(
1515
"git clone --branch v0.8.2 --depth 1 " +
1616
"https://github.com/pgvector/pgvector.git /tmp/pgvector",

extensions/postgis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
var postgis = plyd.New(
1111
"postgis",
1212
plyd.NewHandlersList(
13-
plyd.NewHandler(">=13.0.0, <19.0.0", func(ins *instance.InstanceInfo) error {
13+
plyd.NewHandler(">=14.0.0, <19.0.0", func(ins *instance.InstanceInfo) error {
1414
pkg := fmt.Sprintf("postgresql-%s-postgis-3", ins.PostgreSQL.Mayor)
1515
if err := plyd.Run(fmt.Sprintf("apt-get install -y -qq %s", pkg)); err != nil {
1616
return err

0 commit comments

Comments
 (0)