April 3, 2019
Fill Gitlab-CI Postgres Database Service with SQL
We all love the Gitlab-CI and it’s docker support, also the services are a nice feature to get a database into your pipeline task.
But recently we had the issue that we need to prefill the given postgres:latest service with some sql data for testing.
For ubuntu based docker images, there is a easy solution:
- apt update
- apt install -y postgresql-client
- env PGPASSWORD=yourPassword psql -h postgres -U postgres -w postgres < path/to/your/initial.sql
For other base images based on debian or alpine, you mabye need apk add as an apt install equivalent to get the correct postgres-client.
Beware the variables for the postgres db service and the values in the psql call need to match.
For the psql reference see: https://www.postgresql.org/docs/current/app-psql.html