From 857d12c7da7a7d18f9a9dd2d6f645fed27781b2d Mon Sep 17 00:00:00 2001 From: Olivier DOSSMANN Date: Tue, 12 Jan 2016 15:42:05 +0100 Subject: [PATCH] [IMP] Complete create() function in Docker launch script --- config | 3 +++ launch.sh | 29 ++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/config b/config index ba7eebb..77ed5cc 100644 --- a/config +++ b/config @@ -2,3 +2,6 @@ PROJECT_DIR="/home/olivier/gissmo_project" +POSTGRES_VERSION="9.5" +POSTGRES_DOCKER_NAME="gissmo_db" +DB_VOLUME_NAME="dbdata" diff --git a/launch.sh b/launch.sh index 730e8e3..fe83dc4 100755 --- a/launch.sh +++ b/launch.sh @@ -8,6 +8,8 @@ GIT_URL="git@github.com:eost/gissmo.git" GIT_BRANCH="dev" # Default Git Branch GIT_DIR_NAME="gissmo" DOCKERFILE_NAME="Dockerfile" +DB_DIR="/dbdata" +POSTGRES_VERSION="9.5" ## User . config || exit 1 @@ -40,8 +42,8 @@ not_implemented() { show_help() { echo "$PROGRAM [COMMAND]" echo -e " Where COMMAND is one of:" - echo -e " - create " - echo -e " - init " + echo -e " - create Create postgreSQL database volume and postgreSQL Docker container" + echo -e " - init Create project directory as python virtual environment, fetch git repository and install Python dependancies" echo -e " - restore " echo -e " - start " echo -e " - stop " @@ -64,9 +66,30 @@ check_command() { 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() { + test_create 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() {