6

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

2 Answers 2

1

I found in gitlab documentation details about postgres service configuration

https://docs.gitlab.com/ee/ci/services/postgres.html?fbclid=IwAR1eDlOQ4ACn6zqw1auIetB07JRcCGi1Pjl-hpfGBM45ujvkImm6fHSSbgg

The db url should contain the name of host postgres instead of localhost.

Sign up to request clarification or add additional context in comments.

2 Comments

I've been fighting it for hours. Can you share an exact configuration? I tried "jdbc:postgresql://postgres/dbname" in application.properties but still get the same error.
I tried "jdbc:postgresql://postgres:5432/dbname" too.
0

I found gitlab-runner is running the postgresql docker image as postgres and this is working changing jdbc:postgresql://localhost:5432/dbname into jdbc:postgresql://postgres:5432/dbname.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.