[IMP] Complete create() function in Docker launch script

This commit is contained in:
Olivier DOSSMANN 2016-01-12 15:42:05 +01:00
parent f58f99a0d7
commit 857d12c7da
2 changed files with 29 additions and 3 deletions

3
config
View File

@ -2,3 +2,6 @@
PROJECT_DIR="/home/olivier/gissmo_project" PROJECT_DIR="/home/olivier/gissmo_project"
POSTGRES_VERSION="9.5"
POSTGRES_DOCKER_NAME="gissmo_db"
DB_VOLUME_NAME="dbdata"

View File

@ -8,6 +8,8 @@ GIT_URL="git@github.com:eost/gissmo.git"
GIT_BRANCH="dev" # Default Git Branch GIT_BRANCH="dev" # Default Git Branch
GIT_DIR_NAME="gissmo" GIT_DIR_NAME="gissmo"
DOCKERFILE_NAME="Dockerfile" DOCKERFILE_NAME="Dockerfile"
DB_DIR="/dbdata"
POSTGRES_VERSION="9.5"
## User ## User
. config || exit 1 . config || exit 1
@ -40,8 +42,8 @@ not_implemented() {
show_help() { show_help() {
echo "$PROGRAM [COMMAND]" echo "$PROGRAM [COMMAND]"
echo -e " Where COMMAND is one of:" echo -e " Where COMMAND is one of:"
echo -e " - create " echo -e " - create Create postgreSQL database volume and postgreSQL Docker container"
echo -e " - init " echo -e " - init Create project directory as python virtual environment, fetch git repository and install Python dependancies"
echo -e " - restore " echo -e " - restore "
echo -e " - start " echo -e " - start "
echo -e " - stop " echo -e " - stop "
@ -64,9 +66,30 @@ check_command() {
exit 1 exit 1
} }
test_create() {
docker_cmd=`which docker`
if test -z "$docker_cmd"; then
error_and_quit "Docker command not found. Install docker or fill in the PATH."
fi
if test -z "$DB_DIR"; then
error_and_quit "No database directory given (DB_DIR in config file)."
fi
if test -z "$DB_VOLUME_NAME"; then
error_and_quit "No database volume name given (DB_VOLUME_NAME in config file)."
fi
if test -z "$POSTGRES_VERSION"; then
error_and_quit "No postgres version given (POSTGRES_VERSION in config file)."
fi
if test -z "$POSTGRES_DOCKER_NAME"; then
error_and_quit "You need a name for your Docker database container (POSTGRES_DOCKER_NAME in config file)."
fi
}
create() { create() {
test_create
init init
not_implemented $docker_cmd create -v "${DB_DIR}:/var/lib/postgresql/data" --name "${DB_VOLUME_NAME}" "postgres:${POSTGRES_VERSION}" || error_and_quit "Initial database 'docker create' failed."
$docker_cmd run -d --volumes-from "${DB_VOLUME_NAME}" --name "${POSTGRES_DOCKER_NAME}" "postgres:${POSTGRES_VERSION}" || error_and_quit "Launching database docker container failed."
} }
init() { init() {