I am creating a test stage in my GitLab ci in which I create a container for Postgres DB. I will need to inspect the container and use the IP address as database URL in my flask application:
Here is a pseudo-code of what I want to do:
test:
stage: test
script:
- echo "testing"
- docker run -d -p 5434:5432 --rm --name pg_test_container --env-file test_database.env postgres:latest
- db_host=docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' pg_test_container
- echo db_host
- ...
- ...
- ...
- ...
- docker stop pg_test_container
tags:
- test
How should I rewrite this part to make it work and set it to an env variable for me:
db_host=docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' pg_test_container
I will need to use it to create the DATABASE_URL
:
DATABASE_URL='postgresql://postgres:1234@db_host:5434/pg_db'