Skip to content
This repository was archived by the owner on Nov 2, 2023. It is now read-only.

Commit 6e0cca7

Browse files
authored
Merge pull request #297 from dbca-wa/296-a-mount-to-bind-them-all
New: docker-compose bind mount to transfer db
2 parents 5df9e58 + 7905107 commit 6e0cca7

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ node_modules/
1212
build/
1313
.vscode/.git/
1414
.vscode/
15+
transfer/

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ public/javascripts/build.js
1010
tmp/
1111
node_modules/
1212
build/
13-
.vscode/
13+
.vscode/
14+
transfer/

BUILDING.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,45 @@ git pull
104104
docker-compose up -d --build
105105
```
106106

107+
### Transfer database snapshots
108+
Both `docker-compose` files mount a transfer directory.
109+
On the host, `docker-compose` is run from the cloned Build repository.
110+
A folder `transfer` is created inside the cloned repository, which is mounted inside the `postgres` container as `/var/transfer`.
111+
112+
This bind mount can be used to either transfer a database dump from the host (or another machine) into the Docker container,
113+
or transfer a database dump from the container to the host (or another machine).
114+
115+
```
116+
root@build-staging:/srv/odkbuild/current# pg_dump -h localhost -U odkbuild -d odkbuild -W -Fc > transfer/db.dump
117+
```
118+
119+
To restore the database dump into the container:
120+
121+
```
122+
# Find the container name: build_odkbuild_1
123+
> docker-compose ps
124+
Name Command State Ports
125+
---------------------------------------------------------------------------------------------------------
126+
build_build2xlsform_1 docker-entrypoint.sh node ... Up 0.0.0.0:8686->8686/tcp,:::8686->8686/tcp
127+
build_odkbuild_1 ./contrib/wait-for-it.sh p ... Up 0.0.0.0:9393->9393/tcp,:::9393->9393/tcp
128+
build_postgres_1 docker-entrypoint.sh postgres Up 5432/tcp
129+
130+
# Attach to the running container
131+
> docker exec -it build_postgres_1 /bin/bash -c "export TERM=xterm; exec bash"
132+
133+
# Option 1: Restore a database dump
134+
root@308c22617da1:/# pg_restore -U odkbuild -f /var/transfer/db.dump
135+
136+
# Option 2: Save a database dump
137+
root@308c22617da1:/# pg_dump -U odkbuild -Fc > /var/transfer/db.dump
138+
```
139+
140+
From the host system, the database dump is now accessible as `transfer/db.dump` in the cloned Build source repository.
141+
142+
```
143+
root@build-staging:/srv/odkbuild/current# pg_restore -h localhost -U odkbuild -d odkbuild -W < transfer/db.dump
144+
```
145+
107146
## Source install
108147
The following sections document how to install Build and its dependencies from source.
109148

docker-compose.dev.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
# and build the local version of ODK Build from the Dockerfile.
33
# Use this file to test ODK Build during development.
44
# Run: docker-compose -f docker-compose.dev.yml up -d --build
5+
# The bind mount "transfer" serves to transfer database snapshots in and out of the container.
6+
# This is useful to migrate deployment from source to docker-compose.
57
version: "3"
68
services:
79
postgres:
810
image: "postgres:14.1"
911
volumes:
1012
- odkbuild:/var/lib/postgresql/data
13+
- ./transfer:/var/transfer:rw
1114
environment:
1215
POSTGRES_USER: odkbuild
1316
POSTGRES_PASSWORD: odkbuild
@@ -33,4 +36,4 @@ services:
3336
# healthcheck:
3437
# test: [ "CMD-SHELL", "nc -z localhost 9393 || exit 1" ]
3538
volumes:
36-
odkbuild:
39+
odkbuild:

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ services:
88
image: "postgres:14.1"
99
volumes:
1010
- odkbuild:/var/lib/postgresql/data
11+
- ./transfer:/var/transfer:rw
1112
environment:
1213
POSTGRES_USER: odkbuild
1314
POSTGRES_PASSWORD: odkbuild

0 commit comments

Comments
 (0)