Custom Postgres Service connection fails in test step
.gitlab-ci.yml
.ci-test:
stage: Core
image: docker.mycompany.com/my-repo:${IMAGE_TAG}-ci
tags:
- k8s-runner
variables:
GIT_STRATEGY: none
IS_CI_TEST: 1
TESTING: 1
DB_USER: 'myusername'
DB_PASS: 'mypassword'
TEST_DB_HOST: 'test-db-host'
TEST_DB_NAME: 'test-db-name'
TEST_DB: 'postgresql://$DB_USER:$DB_PASS@$TEST_DB_HOST/$TEST_DB_NAME'
before_script:
- cd /usr/src/my-repo
Run Misc Tests:
extends:
- .ci-test
services:
- name: docker.mycompany.com/testdb:current
alias: test-db-host
script:
- env | grep DB | sort
- pg_isready -d $TEST_DB
Error Case
The environment variables that are printed are what I expect; however, the final script
step results in
$ pg_isready -d $TEST_DB
test-db-host:5432 - no response
I expect the service to be accessible at this point.
Versioning
Running with gitlab-runner 15.1.0 (76984217)
on gitlab-runner-5b47cd79d-xtrmd Cx6KC7sf
Preparing the "kubernetes" executor
Troubleshooting So Far
Some of the lines of inquiry I’ve pursued up to this point…
Image Issues?
I have run this image locally and found it to be as expected, including being accessible and properly configured/migrated with
docker run -d --rm docker.mycompany.com/myrepo:current && pg_isready -d postgresql://myusername:mypassword@localhost/aledade
localhost:5432 - accepting connections
and running psql -c '\l+'
agains this local container shows me the structure I expect, so I am reasonably confident that the image itself is correct.
I have also tried setting the postgres
connection variables POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB
in the service definition (though this is demonstrably unnecessary in the local environment, since they are set in the image itself)
Connection String + Service Alias
- I have
echo
ed the runtime value ofTEST_DB
and found it to match my expectations. The printed result ofpg_isready
is clearly respecting the value in the connection string. - I have gotten a successful connection to a base image,
postgres:11
using the same pattern of access. - I’ve gotten the same result from setting
TEST_DB_HOST
to both thealias
andname
of the service.