Hi,
I have been trying to create a postgres db container to run integration tests. Is there away i can execute a shell script to do some inital schema set up? I tried using the command tag, but nothing was getting executed. Calling a docker-compose be a option? If so whats the right syntax for calling that?
services:
database:
image: postgres
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
- POSTGRES_DB=db-name
command:
- ./setUp.sh
pipeline:
build:
image: library/openjdk:8-jdk
commands:
- ./gradlew clean build
Also will be be able to access the db with the ip address 127.0.0.1?
this block would fail in drone and / or docker compose as well. The problem is that the postgres image expects the command block to be used to send command line flags to postgres (like -B 100 -A 0
, etc)
services:
database:
image: postgres
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
- POSTGRES_DB=db-name
- command:
- - ./setUp.sh
Instead you can create a step in your build pipeline that connects to postgres using the command line utility to load a script or perform database setup, etc. I would expect it to look something like this:
services:
database:
image: postgres
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
- POSTGRES_DB=db-name
pipeline:
+ setup:
+ image: postgres
+ environment:
+ - POSTGRES_USER=user
+ - POSTGRES_PASSWORD=password
+ - POSTGRES_DB=db-name
+ commands:
+ - psql -h db-name -U user ......
build:
image: openjdk:8-jdk
commands:
- ./gradlew clean build
Please note that this is just an example and probably won’t work exactly as written, but hopefully this helps point you in the right direction.
Cheers