Skip to content

Commit 1e1cbd7

Browse files
committed
publish a docker image with the buildin db
1 parent 7a0fd1e commit 1e1cbd7

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3"
22
services:
33
database:
4-
image: transport_db
4+
image: antoinede/transport_data_gouv_dev_database
55
volumes:
66
- pgdata:/var/lib/postgresql/data
77
environment:

docker/database/Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM mdillon/postgis:11-alpine
2+
3+
# PATH to the clever cloud backup file
4+
ARG BACKUP_PATH
5+
6+
ENV POSTGRES_DB transport_repo
7+
8+
COPY restore_db.sh /docker-entrypoint-initdb.d/
9+
COPY create_test_db.sh /docker-entrypoint-initdb.d/
10+
COPY ${BACKUP_PATH} /db_backup
11+
12+

docker/database/create_test_db.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
# create test database
3+
createdb transport_test

docker/database/readme.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Script to build a database docker image
2+
3+
To build the image run:
4+
5+
`docker build -t transport_data_gouv_dev_database --build-arg BACKUP_PATH=<path_to_the_backup_file> .`
6+
7+
Note: backup file needs to be in the directory.
8+
9+
If you want to push it to dockerhub (change the destination image name if needed):
10+
11+
`docker login`
12+
13+
`docker tag transport_data_gouv_dev_database antoinede/transport_data_gouv_dev_database:latest`
14+
15+
`docker push antoinede/transport_data_gouv_dev_database:latest`

docker/database/restore_db.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash -x
2+
3+
DB_NAME="transport_repo"
4+
BACKUP_PATH="/db_backup"
5+
6+
# the pg_restore fail for some obscure reasons, but the import seems to be ok
7+
pg_restore --dbname=$DB_NAME --format=c --no-owner --clean $BACKUP_PATH || true
8+
9+
# add a check
10+
nb_datasets=`psql -qtAX $DB_NAME -c "select count(*) from dataset;"`
11+
12+
if [[ $nb_datasets -eq 0 ]]; then
13+
echo "no datasets loaded, something is strange"
14+
exit 1
15+
fi

0 commit comments

Comments
 (0)