Added docker-compose support

pull/12/head
Piero Toffanin 2016-09-11 19:52:31 -04:00
rodzic 52723a400e
commit c5ca26e7c1
9 zmienionych plików z 222 dodań i 1 usunięć

3
.gitignore vendored
Wyświetl plik

@ -87,3 +87,6 @@ ENV/
# Rope project settings
.ropeproject
# Initialization flag
.initialized

16
Dockerfile 100644
Wyświetl plik

@ -0,0 +1,16 @@
FROM python:2.7
MAINTAINER Piero Toffanin <pt@masseranolabs.com>
ENV PYTHONUNBUFFERED 1
ENV PYTHONPATH $PYTHONPATH:/webodm
# Prepare directory
RUN mkdir /webodm
WORKDIR /webodm
# Install pip reqs
ADD requirements.txt /webodm/
RUN pip install -r requirements.txt
# Add repository files
ADD . /webodm/

4
db/Dockerfile 100644
Wyświetl plik

@ -0,0 +1,4 @@
FROM postgres:9.5
MAINTAINER Piero Toffanin <pt@masseranolabs.com>
EXPOSE 5432
COPY init.sql /docker-entrypoint-initdb.d/init-db.sql

2
db/init.sql 100644
Wyświetl plik

@ -0,0 +1,2 @@
ALTER USER postgres PASSWORD 'postgres';
CREATE DATABASE webodm_dev;

18
docker-compose.yml 100644
Wyświetl plik

@ -0,0 +1,18 @@
version: '2'
services:
db:
build: ./db
container_name: db
ports:
- "5432:5432"
webapp:
build: .
container_name: webapp
entrypoint: /bin/bash /webodm/wait-for-it.sh db:5432 -- /webodm/start.sh
volumes:
- .:/webodm
ports:
- "8000:8000"
depends_on:
- db
restart: on-failure:10

6
requirements.txt 100644
Wyświetl plik

@ -0,0 +1,6 @@
Django==1.10
anyjson==0.3.3
pillow==3.3.1
psycopg2==2.6.2
pytz==2016.6.1
wsgiref==0.1.2

11
start.sh 100644
Wyświetl plik

@ -0,0 +1,11 @@
#!/bin/bash
if ! [ -a .initialized ]; then
echo First run, migrating...
python manage.py migrate
echo Creating default superuser...
echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@example.com', 'admin')" | python manage.py shell
touch .initialized
fi
python manage.py runserver 0.0.0.0:8000

161
wait-for-it.sh 100644
Wyświetl plik

@ -0,0 +1,161 @@
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available
cmdname=$(basename $0)
echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
usage()
{
cat << USAGE >&2
Usage:
$cmdname host:port [-s] [-t timeout] [-- command args]
-h HOST | --host=HOST Host or IP under test
-p PORT | --port=PORT TCP port under test
Alternatively, you specify the host and port as host:port
-s | --strict Only execute subcommand if the test succeeds
-q | --quiet Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
}
wait_for()
{
if [[ $TIMEOUT -gt 0 ]]; then
echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT"
else
echoerr "$cmdname: waiting for $HOST:$PORT without a timeout"
fi
start_ts=$(date +%s)
while :
do
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
result=$?
if [[ $result -eq 0 ]]; then
end_ts=$(date +%s)
echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"
break
fi
sleep 1
done
return $result
}
wait_for_wrapper()
{
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
if [[ $QUIET -eq 1 ]]; then
timeout $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
else
timeout $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
fi
PID=$!
trap "kill -INT -$PID" INT
wait $PID
RESULT=$?
if [[ $RESULT -ne 0 ]]; then
echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT"
fi
return $RESULT
}
# process arguments
while [[ $# -gt 0 ]]
do
case "$1" in
*:* )
hostport=(${1//:/ })
HOST=${hostport[0]}
PORT=${hostport[1]}
shift 1
;;
--child)
CHILD=1
shift 1
;;
-q | --quiet)
QUIET=1
shift 1
;;
-s | --strict)
STRICT=1
shift 1
;;
-h)
HOST="$2"
if [[ $HOST == "" ]]; then break; fi
shift 2
;;
--host=*)
HOST="${1#*=}"
shift 1
;;
-p)
PORT="$2"
if [[ $PORT == "" ]]; then break; fi
shift 2
;;
--port=*)
PORT="${1#*=}"
shift 1
;;
-t)
TIMEOUT="$2"
if [[ $TIMEOUT == "" ]]; then break; fi
shift 2
;;
--timeout=*)
TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
CLI="$@"
break
;;
--help)
usage
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
done
if [[ "$HOST" == "" || "$PORT" == "" ]]; then
echoerr "Error: you need to provide a host and port to test."
usage
fi
TIMEOUT=${TIMEOUT:-15}
STRICT=${STRICT:-0}
CHILD=${CHILD:-0}
QUIET=${QUIET:-0}
if [[ $CHILD -gt 0 ]]; then
wait_for
RESULT=$?
exit $RESULT
else
if [[ $TIMEOUT -gt 0 ]]; then
wait_for_wrapper
RESULT=$?
else
wait_for
RESULT=$?
fi
fi
if [[ $CLI != "" ]]; then
if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then
echoerr "$cmdname: strict mode, refusing to execute subprocess"
exit $RESULT
fi
exec $CLI
else
exit $RESULT
fi

Wyświetl plik

@ -84,7 +84,7 @@ DATABASES = {
'NAME': 'webodm_dev',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': '127.0.0.1',
'HOST': 'db',
'PORT': '5432',
}
}