diff --git a/testing/dbtest/docker/Dockerfile.11-alpine b/testing/dbtest/docker/Dockerfile.11-alpine new file mode 100644 index 000000000..f569cac04 --- /dev/null +++ b/testing/dbtest/docker/Dockerfile.11-alpine @@ -0,0 +1,6 @@ +FROM postgres:11-alpine + +ADD init-db.sh /docker-entrypoint-initdb.d/00-init-db.sh +ADD postgresql.conf /etc/postgresql/postgresql.conf + +CMD ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"] diff --git a/testing/dbtest/docker/Dockerfile.12-alpine b/testing/dbtest/docker/Dockerfile.12-alpine new file mode 100644 index 000000000..3ffdb3d35 --- /dev/null +++ b/testing/dbtest/docker/Dockerfile.12-alpine @@ -0,0 +1,6 @@ +FROM postgres:12-alpine + +ADD init-db.sh /docker-entrypoint-initdb.d/00-init-db.sh +ADD postgresql.conf /etc/postgresql/postgresql.conf + +CMD ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"] diff --git a/testing/dbtest/docker/Dockerfile.13-alpine b/testing/dbtest/docker/Dockerfile.13-alpine new file mode 100644 index 000000000..ddab38a16 --- /dev/null +++ b/testing/dbtest/docker/Dockerfile.13-alpine @@ -0,0 +1,6 @@ +FROM postgres:13-alpine + +ADD init-db.sh /docker-entrypoint-initdb.d/00-init-db.sh +ADD postgresql.conf /etc/postgresql/postgresql.conf + +CMD ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"] diff --git a/testing/dbtest/docker/Dockerfile.alpine b/testing/dbtest/docker/Dockerfile.alpine new file mode 100644 index 000000000..1655beab9 --- /dev/null +++ b/testing/dbtest/docker/Dockerfile.alpine @@ -0,0 +1,6 @@ +FROM postgres:alpine + +ADD init-db.sh /docker-entrypoint-initdb.d/00-init-db.sh +ADD postgresql.conf /etc/postgresql/postgresql.conf + +CMD ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"] diff --git a/testing/dbtest/docker/Makefile b/testing/dbtest/docker/Makefile new file mode 100644 index 000000000..f1b8ec515 --- /dev/null +++ b/testing/dbtest/docker/Makefile @@ -0,0 +1,50 @@ +all: docker-build + +CWD := $(shell pwd) +DOCKER_ARGS ?= -d + +REGISTRY_NAME?=docker.io/hashicorpboundary +IMAGE_NAME=postgres +IMAGE_TAG ?= $(REGISTRY_NAME)/$(IMAGE_NAME):11-alpine +PG_OPTS ?= +TEST_DB_PORT ?= 5432 + +# Generate targets from dockerfiles +dockerfiles = $(wildcard Dockerfile.*) +docker-builds = $(patsubst Dockerfile.%,%-build, $(dockerfiles)) +docker-publishes = $(patsubst Dockerfile.%,%-publish, $(dockerfiles)) + +${docker-builds}: %-build: + docker build -t $(REGISTRY_NAME)/$(IMAGE_NAME):$* -f Dockerfile.$* . + +docker-build: ${docker-builds} + +docker-publish: ${docker-publishes} + +${docker-publishes}: %-publish: + docker push $(REGISTRY_NAME)/$(IMAGE_NAME):$* + +database-up: + @echo "Using image: $(IMAGE_TAG)" + @echo "Additional postgres configuration: $(PG_OPTS)" + @docker run \ + $(DOCKER_ARGS) \ + --name boundary-sql-tests \ + -p $(TEST_DB_PORT):5432 \ + -e POSTGRES_PASSWORD=boundary \ + -e POSTGRES_USER=boundary \ + -e POSTGRES_DB=boundary \ + -e PGDATA=/pgdata \ + --mount type=tmpfs,destination=/pgdata \ + -v "$(CWD)/../../../internal/db/schema/migrations/postgres":/migrations \ + $(IMAGE_TAG) \ + -c 'config_file=/etc/postgresql/postgresql.conf' \ + $(PG_OPTS) 1> /dev/null + @echo "Test database available at: 127.0.0.1:$(TEST_DB_PORT)" + @echo "For database logs run:" + @echo " docker logs boundary-sql-test" +clean: + docker stop boundary-sql-tests || true + docker rm -v boundary-sql-tests || true + +.PHONY: all docker-build database-up ${docker-builds} ${docker-publishes} clean diff --git a/testing/dbtest/docker/init-db.sh b/testing/dbtest/docker/init-db.sh new file mode 100755 index 000000000..ae18f8edc --- /dev/null +++ b/testing/dbtest/docker/init-db.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +set -e +shopt -s globstar + +psql -v "ON_ERROR_STOP=1" --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -q <