diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b1d643f..acdccef 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,7 +37,8 @@ test: POSTGRES_DB: monolith POSTGRES_USER: monolith POSTGRES_PASSWORD: monolith_it - LAB_MONOLITH_DB_IP: postgres + LAB_MONOLITH_DB_HOST: postgres + LAB_MONOLITH_DB_PORT: "5432" LAB_MONOLITH_DB_PASSWORD: monolith_it script: - ./gradlew -g /cache/.gradle check \ No newline at end of file diff --git a/README.md b/README.md index ebfea68..e823b4c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # Getting Started 1. Install Docker. -2. Set up an environment variable `LAB_MONOLITH_DB_IP` and assign the docker host's IP. +2. Set up an environment variable `LAB_MONOLITH_DB_HOST` and assign the docker host's IP, + set `LAB_MONOLITH_DB_PORT` to some free port, e.g. 5432. For docker machine type `docker-machine env` and the value of `$DOCKER_HOST`, otherwise `localhost` is probably correct. diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 05eb0f1..c788c2b 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect spring.datasource.driverClassName=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://${LAB_MONOLITH_DB_IP}:15432/monolith +spring.datasource.url=jdbc:postgresql://${LAB_MONOLITH_DB_HOST}:${LAB_MONOLITH_DB_PORT}/monolith spring.datasource.username=monolith spring.datasource.password=${LAB_MONOLITH_DB_PASSWORD} diff --git a/start-db.sh b/start-db.sh index 7b4868d..028d734 100644 --- a/start-db.sh +++ b/start-db.sh @@ -1,18 +1,30 @@ #!/bin/bash + [[ -n "$DOCKER_HOST" ]] && echo "DOCKER_HOST: $DOCKER_HOST" -if [[ ! -n "$LAB_MONOLITH_DB_IP" ]]; then - echo 'ERROR: LAB_MONOLITH_DB_IP is not set.' + +if [[ ! -n "$LAB_MONOLITH_DB_HOST" ]]; then + echo 'ERROR: LAB_MONOLITH_DB_HOST is not set.' exit 1 else - echo "LAB_MONOLITH_DB_IP: $LAB_MONOLITH_DB_IP" + echo "LAB_MONOLITH_DB_HOST: $LAB_MONOLITH_DB_HOST" fi + +if [[ ! -n "$LAB_MONOLITH_DB_PORT" ]]; then + echo 'ERROR: LAB_MONOLITH_DB_PORT is not set.' + exit 1 +else + echo "LAB_MONOLITH_DB_PORT: $LAB_MONOLITH_DB_PORT" +fi + if [[ ! -n "$LAB_MONOLITH_DB_PASSWORD" ]]; then echo 'ERROR: LAB_MONOLITH_DB_PASSWORD is not set.' exit 1 fi -echo 'Starting database for integration tests...' + +echo 'Starting database...' + docker run --rm --name monolith-postgres\ - -p 15432:5432\ + -p $LAB_MONOLITH_DB_PORT:5432\ -e POSTGRES_USER=monolith\ -e POSTGRES_PASSWORD=$LAB_MONOLITH_DB_PASSWORD\ -d postgres:9