diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9167495cc..5490871ab 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -144,6 +144,15 @@ $ make test-database-up $ make test ``` +By default the container name is `boundary-sql-tests`. +This can be changed in the same way as the port: + +``` +$ export TEST_CONTAINER_NAME="custom-name" +$ make test-database-up +$ docker logs custom-name +``` + The default docker image is built using the `postgres:11` base image. The image can be changed using a make option to test against other versions: diff --git a/internal/db/sqltest/Makefile b/internal/db/sqltest/Makefile index 04731bb21..a05dadd79 100644 --- a/internal/db/sqltest/Makefile +++ b/internal/db/sqltest/Makefile @@ -21,6 +21,8 @@ POSTGRES_DOCKER_IMAGE := $(POSTGRES_DOCKER_IMAGE_BASE):$(PG_DOCKER_TAG) PG_TAP_DOCKER_IMAGE_BASE ?= subzerocloud/pgtap PG_TAP_DOCKER_IMAGE := $(PG_TAP_DOCKER_IMAGE_BASE):$(PG_TAP_DOCKER_TAG) +SQL_TEST_CONTAINER_NAME ?= boundary-sql-tests + # re-write paths for docker dockerized_tests = $(patsubst tests/%,/test/%,$(TESTS)) @@ -29,7 +31,7 @@ test: @echo Using $(POSTGRES_DOCKER_IMAGE) @echo Using $(PG_TAP_DOCKER_IMAGE) @docker run -d \ - --name boundary-sql-tests \ + --name $(SQL_TEST_CONTAINER_NAME) \ -e POSTGRES_PASSWORD=boundary \ -e POSTGRES_USER=boundary \ -e POSTGRES_DB=boundary \ @@ -38,7 +40,7 @@ test: $(POSTGRES_DOCKER_IMAGE) @docker run -it --rm \ --name test \ - --link boundary-sql-tests:db \ + --link $(SQL_TEST_CONTAINER_NAME):db \ -e DATABASE=boundary \ -e HOST=db \ -e PORT=5432 \ @@ -47,12 +49,12 @@ test: -e TESTS="$(PROVE_OPTS) $(dockerized_tests)" \ -v "$(CWD)/tests":/test \ $(PG_TAP_DOCKER_IMAGE); \ - (ret=$$?; docker stop boundary-sql-tests &>/dev/null && docker rm -v boundary-sql-tests &>/dev/null && exit $$ret) + (ret=$$?; docker stop $(SQL_TEST_CONTAINER_NAME) &>/dev/null && docker rm -v $(SQL_TEST_CONTAINER_NAME) &>/dev/null && exit $$ret) database-up: @echo Using $(POSTGRES_DOCKER_IMAGE) @docker run -d \ - --name boundary-sql-tests \ + --name $(SQL_TEST_CONTAINER_NAME) \ -e POSTGRES_PASSWORD=boundary \ -e POSTGRES_USER=boundary \ -e POSTGRES_DB=boundary \ @@ -64,7 +66,7 @@ run-tests: @echo Using $(PG_TAP_DOCKER_IMAGE) @docker run -it --rm \ --name test \ - --link boundary-sql-tests:db \ + --link $(SQL_TEST_CONTAINER_NAME):db \ -e DATABASE=boundary \ -e HOST=db \ -e PORT=5432 \ @@ -75,7 +77,7 @@ run-tests: $(PG_TAP_DOCKER_IMAGE) clean: - docker stop boundary-sql-tests || true - docker rm -v boundary-sql-tests || true + docker stop $(SQL_TEST_CONTAINER_NAME) || true + docker rm -v $(SQL_TEST_CONTAINER_NAME) || true .PHONY: all clean test database-up run-tests diff --git a/testing/dbtest/docker/Makefile b/testing/dbtest/docker/Makefile index 93734b9f0..0d4ff3d99 100644 --- a/testing/dbtest/docker/Makefile +++ b/testing/dbtest/docker/Makefile @@ -8,6 +8,7 @@ IMAGE_NAME=postgres IMAGE_TAG ?= $(REGISTRY_NAME)/$(IMAGE_NAME):11-alpine PG_OPTS ?= TEST_DB_PORT ?= 5432 +TEST_CONTAINER_NAME ?= boundary-sql-tests # Generate targets from dockerfiles dockerfiles = $(wildcard Dockerfile.*) @@ -29,7 +30,7 @@ database-up: @echo "Additional postgres configuration: $(PG_OPTS)" @docker run \ $(DOCKER_ARGS) \ - --name boundary-sql-tests \ + --name $(TEST_CONTAINER_NAME) \ -p $(TEST_DB_PORT):5432 \ -e POSTGRES_PASSWORD=boundary \ -e POSTGRES_USER=boundary \ @@ -40,11 +41,12 @@ database-up: $(IMAGE_TAG) \ -c 'config_file=/etc/postgresql/postgresql.conf' \ $(PG_OPTS) 1> /dev/null + @echo "Container name: $(TEST_CONTAINER_NAME)" @echo "Test database available at: 127.0.0.1:$(TEST_DB_PORT)" @echo "For database logs run:" - @echo " docker logs boundary-sql-tests" + @echo " docker logs $(TEST_CONTAINER_NAME)" clean: - docker stop boundary-sql-tests || true - docker rm -v boundary-sql-tests || true + docker stop $(TEST_CONTAINER_NAME) || true + docker rm -v $(TEST_CONTAINER_NAME) || true .PHONY: all docker-build database-up ${docker-builds} ${docker-publishes} clean