From 8605fc7117bdee401517fcedf490d6a8c85bfe20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kate=20D=C3=B6en?= Date: Tue, 13 Jul 2021 11:13:13 +0200 Subject: [PATCH] Make testing easier with docker --- Makefile | 6 +++++- tests/Dockerfile | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/Dockerfile diff --git a/Makefile b/Makefile index 7cec5dc..a53d1d9 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,11 @@ tmessy = -svv targs = --cov-report term-missing --cov migra test: - $(tcommand) $(tmessy) $(targs) tests + docker build -t migra-postgres --build-arg LOCAL_USER=$$USER - < tests/Dockerfile + $(eval ID := $(shell docker run -d -p 5432:5432 migra-postgres)) + $(tcommand) $(tmessy) $(targs) tests || true + docker stop $(ID) + docker rm $(ID) stest: $(tcommand) $(tmessy) $(targs) tests diff --git a/tests/Dockerfile b/tests/Dockerfile new file mode 100644 index 0000000..a58871e --- /dev/null +++ b/tests/Dockerfile @@ -0,0 +1,8 @@ +FROM postgres:13-alpine + +ENV POSTGRES_HOST_AUTH_METHOD=trust +ENV POSTGRES_USER=postgres +ARG LOCAL_USER + +RUN printf "psql --username ${POSTGRES_USER} --command=\"CREATE USER ${LOCAL_USER} CREATEDB CREATEROLE;\"" > /docker-entrypoint-initdb.d/10-create-users.sh +RUN printf "psql --username ${POSTGRES_USER} --command=\"CREATE DATABASE ${LOCAL_USER};\"" > /docker-entrypoint-initdb.d/20-create-database.sh