fix #41: Docker support
This commit is contained in:
parent
8121b68579
commit
031b0b9233
11 changed files with 114 additions and 1 deletions
7
.dockerignore
Normal file
7
.dockerignore
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
.DS_Store
|
||||||
|
node_modules/
|
||||||
|
__pycache__
|
||||||
|
npm-debug*.log
|
||||||
|
*.py[cod]
|
||||||
|
*.so
|
||||||
|
.editorconfig
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
||||||
.DS_Store
|
.DS_Store
|
||||||
node_modules/
|
node_modules/
|
||||||
|
__pycache__
|
||||||
dist/
|
dist/
|
||||||
npm-debug*.log
|
npm-debug*.log
|
||||||
ssl/*.pem
|
ssl/*.pem
|
||||||
|
|
26
Dockerfile
Normal file
26
Dockerfile
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
FROM node
|
||||||
|
LABEL \
|
||||||
|
maintainer="Davide Alberani <da@erlug.linux.it>" \
|
||||||
|
vendor="RaspiBO"
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get -y --no-install-recommends install \
|
||||||
|
nodejs \
|
||||||
|
npm \
|
||||||
|
python3-pymongo \
|
||||||
|
python3-tornado && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY . /ibt2
|
||||||
|
|
||||||
|
WORKDIR /ibt2/
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
npm install && \
|
||||||
|
nodejs build/build.js && \
|
||||||
|
rm -rf node_modules
|
||||||
|
|
||||||
|
ENTRYPOINT ["./ibt2.py", "--mongo_url=mongodb://mongo", "--debug"]
|
14
docker-compose.yml
Normal file
14
docker-compose.yml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
ibt2:
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
depends_on:
|
||||||
|
- mongo
|
||||||
|
mongo:
|
||||||
|
image: "mongo:latest"
|
||||||
|
volumes:
|
||||||
|
- data:/data/db
|
||||||
|
volumes:
|
||||||
|
data:
|
9
docker-tools/Dockerfile
Normal file
9
docker-tools/Dockerfile
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
FROM mongo:latest
|
||||||
|
LABEL \
|
||||||
|
maintainer="Davide Alberani <da@erlug.linux.it>" \
|
||||||
|
vendor="RaspiBO"
|
||||||
|
|
||||||
|
VOLUME ["/data"]
|
||||||
|
|
||||||
|
COPY run.sh /
|
||||||
|
ENTRYPOINT ["/run.sh"]
|
4
docker-tools/dump.sh
Executable file
4
docker-tools/dump.sh
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
docker build -t ibt2-dump-and-restore .
|
||||||
|
docker run --name ibt2-dump --rm --network="ibt2_default" -v `pwd`:/data --link=ibt2_ibt2-mongo_1:ibt2-mongo ibt2-dump-and-restore --dump
|
4
docker-tools/restore.sh
Executable file
4
docker-tools/restore.sh
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
docker build -t ibt2-dump-and-restore .
|
||||||
|
docker run --name ibt2-restore --rm --network="ibt2_default" -v `pwd`:/data --link=ibt2_ibt2-mongo_1:ibt2-mongo ibt2-dump-and-restore --restore $1
|
30
docker-tools/run.sh
Executable file
30
docker-tools/run.sh
Executable file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ $# -lt 1 ] ; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cmd="$1"
|
||||||
|
|
||||||
|
if [ "${cmd}" = "--shell" ] ; then
|
||||||
|
echo "INFO: opening shell..."
|
||||||
|
mongo --host mongo ibt2
|
||||||
|
elif [ "${cmd}" = "--dump" ] ; then
|
||||||
|
echo "INFO: dumping..."
|
||||||
|
mongodump --host mongo --out /tmp/ --db ibt2 || (echo "ERROR: unable to dump the database" ; exit 10)
|
||||||
|
cd /tmp
|
||||||
|
tar cfz /data/ibt2-dump-`date +'%Y-%m-%dT%H:%M:%S'`.tgz ibt2
|
||||||
|
elif [ "${cmd}" = "--restore" ] ; then
|
||||||
|
if [ -z "$2" ] ; then
|
||||||
|
echo "ERROR: missing argument to --restore"
|
||||||
|
exit 20
|
||||||
|
fi
|
||||||
|
echo "INFO: restoring $2..."
|
||||||
|
tar xfz "/data/$2" -C /tmp || (echo "ERROR: error unpacking file" ; exit 21)
|
||||||
|
mongo --host mongo ibt2 --eval "db.dropDatabase()" || (echo "ERROR: error dropping the database" ; exit 22)
|
||||||
|
mongorestore --host mongo -d ibt2 /tmp/ibt2
|
||||||
|
else
|
||||||
|
echo "ERROR: command not recognized: use --dump or --restore dumps/file.tgz"
|
||||||
|
exit 30
|
||||||
|
fi
|
||||||
|
|
4
docker-tools/shell.sh
Executable file
4
docker-tools/shell.sh
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
docker build -t ibt2-dump-and-restore .
|
||||||
|
docker run -it --name ibt2-shell --rm --network="ibt2_default" -v `pwd`:/data --link=ibt2_ibt2-mongo_1:ibt2-mongo ibt2-dump-and-restore --shell
|
14
docs/DOCKER.md
Normal file
14
docs/DOCKER.md
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# Docker container
|
||||||
|
|
||||||
|
ibt2 requires MongoDB to run.
|
||||||
|
|
||||||
|
You can use docker-compose.yml to have a complete environment. Run: `docker-compose up --build`
|
||||||
|
|
||||||
|
The data is stored in the *ibt2_data* volume: do not cancel it.
|
||||||
|
|
||||||
|
In the *docker-tools* directory there is a set of tools to build and run another container to dump and restore the database; you need the docker-compose running, to execute them. From that directory you can:
|
||||||
|
|
||||||
|
- **dump.sh**: dump the current database in a file like *ibt2-dump-2017-11-28T21:57:43.tgz*
|
||||||
|
- **restore.sh**: *ibt2-dump-2017-11-28T21:57:43.tgz*: restore the given dump. Notice that the current database is completely removed, so DO NOT restore a dump if you don't have a backup of the current data
|
||||||
|
- **shell.sh**: open a shell for the database
|
||||||
|
|
2
monco.py
2
monco.py
|
@ -105,7 +105,7 @@ class Monco(object):
|
||||||
"""
|
"""
|
||||||
self._url = url
|
self._url = url
|
||||||
self._dbName = dbName
|
self._dbName = dbName
|
||||||
self.connect(url)
|
self.connect()
|
||||||
|
|
||||||
def connect(self, dbName=None, url=None):
|
def connect(self, dbName=None, url=None):
|
||||||
"""Connect to the database.
|
"""Connect to the database.
|
||||||
|
|
Loading…
Reference in a new issue