I have following stage in gitlab yml file.
integration-tests:
image: mydocker-hub-id/mvn-intergration-tests-image:latest
stage: test
services:
- postgres
script:
- export PGPASSWORD=$POSTGRES_PASSWORD
- psql -h "postgres" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT 'OK' AS status;"
- cd source_code
- pg_isready
- mvn verify -P test-ci -DskipUTs=true
When job is executed for command pg_isready I have response 5432 no response. When tests are executed from each intergration test I have error:
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Image used in this stage is built based on postgres image which has additionally installed maven and java 11.
What could be the issue that spring application cannot connect with postgres server. Command postgres --version displays proper version. Also command
"psql -h "postgres" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT 'OK' AS status;"
returns the OK result.
Spring db connection in app.properties is following:
spring.datasource.url=jdbc:postgresql://localhost:5432/test