1

On Gitlab-CI I set up a postgres service for my database and would like to inspect the config file of it. For this I let postgres return the location of the config file but when I go to that directory, it is empty. How can I access it?

.gitlab-ci.yaml:

image: maven:3.5.3-jdk-8

services:
  - postgres

variables:
  POSTGRES_DB: custom_db
  POSTGRES_USER: custom_user
  POSTGRES_PASSWORD: custom_pass

connect:
  image: postgres
  script:
  - export PGPASSWORD=$POSTGRES_PASSWORD
  - psql -h "postgres" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT 'OK' AS status;"
  - psql -h "postgres" -U "$POSTGRES_USER" -d "$POSTGRES_DB"  -c "SHOW config_file;"
  - cd  /var/lib/postgresql/data
  - dir
  - ls -a
  - cat postgresql.conf

The respective job output:

Running with gitlab-runner 11.8.0 (4745a6f3)
  on docker-auto-scale 72989761
Using Docker executor with image postgres ...
Starting service postgres:latest ...
Pulling docker image postgres:latest ...
Using docker image sha256:30bf4f039abe0affe9fe4f07a13b00ea959299510626d650c719fb10c4f41470 for postgres:latest ...
Waiting for services to be up and running...
Pulling docker image postgres ...
Using docker image sha256:30bf4f039abe0affe9fe4f07a13b00ea959299510626d650c719fb10c4f41470 for postgres ...
Running on runner-72989761-project-7829066-concurrent-0 via runner-72989761-srm-1551974294-08e28deb...
Cloning repository...
Cloning into '/builds/kimtang/SpringBootTimeWithSwagger'...
Checking out 1399a232 as master...
Skipping Git submodules setup
$ export PGPASSWORD=$POSTGRES_PASSWORD
$ psql -h "postgres" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT 'OK' AS status;"
 status 
--------
 OK
(1 row)

$ psql -h "postgres" -U "$POSTGRES_USER" -d "$POSTGRES_DB"  -c "SHOW config_file;"
               config_file                
------------------------------------------
 /var/lib/postgresql/data/postgresql.conf
(1 row)

$ cd  /var/lib/postgresql/data
$ dir
$ ls -a
.
..
$ cat postgresql.conf
cat: postgresql.conf: No such file or directory
ERROR: Job failed: exit code 1

Why does it state it is in /var/lib/postgresql/data but then can not be found?

3
  • select * from pg_settings? Commented Mar 7, 2019 at 20:06
  • This just returns the file destination/name but not the content of the file. Commented Mar 14, 2019 at 12:43
  • 1
    That view will contain the "content" of the file. Every configuration parameter shows up there - even with the name of the file where it was defined and the line number inside that file Commented Mar 14, 2019 at 12:54

1 Answer 1

1

You're connected to a remote docker instance via psql and you're checking a local directory. If you really want to check what's going on on the service docker image then ssh into the worker and then use the docker exec -i -t <container_name> /bin/sh command to log into the container. You will have to make the job run for a long time though so put some sleep in there.

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

3 Comments

Thank you for your answer! I just dont quite understand how to ssh into the worker. Is the worker then the image? Is there any way to return the adresses of running images in the gitlab-ci.yaml? Because if I try to use commands such as docker, it states it is not installed, while it is clearly using docker to run the image. Any help is very appreciated, thank you
@Kim Let's assume I wrote runner instead of worker, okay? You have a server, that server has runner installed and runner runs your jobs which run in docker images. If you use shared-runners on gitlab.org instead of your own you can't do it. Or you could just pull the docker image to your local machine and inspect it there.
Thank you! That helped.

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.