From c5d430ee9b9082d30a5b33cb89aaa60e0c69df1a Mon Sep 17 00:00:00 2001 From: Olivier DOSSMANN Date: Tue, 26 Jan 2016 18:48:02 +0100 Subject: [PATCH] [ADD] Launch script: export command to have a dump of postgreSQL --- TODO | 9 ++++++++- launch.sh | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index b0704ca..e8b9432 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,13 @@ # Scripts +## À faire + + * Faire un script qui lance l'environnement complet pour le test et les lance + +## Terminés + * Faire un script de déploiement Docker : * avec un dump possible de la base * des variables OBLIGATOIRES pour définir le répertoire dans lequel sera la base, la version postgres à utiliser et la version Gissmo courante + le fichier Docker - * Faire un script qui lance l'environnement complet pour le test et les lance + * DUMP pour le script via : docker run -it --rm --volume $PWD/:/tmp/ --link gissmo_db:db postgres:9.5 bash -c 'exec pg_dump -F c -h "$DB_PORT_5432_TCP_ADDR" -p "$DB_PORT_5432_TCP_PORT" -U postgres postgres > /tmp/gissmo-$(date +"%Y.%m.%d-%H%M").dump' + diff --git a/launch.sh b/launch.sh index 8e79f88..d726a5d 100755 --- a/launch.sh +++ b/launch.sh @@ -88,6 +88,8 @@ show_help() { echo -e " - dev [arg ...] Mount Git repository directory AS VOLUME for Gissmo Docker container and launch it in 'development' mode" + echo -e " - export Create a compressed postgreSQL database dump + in current directory" echo -e " - init Create project directory as python virtual environment, fetch git repository and install Python dependancies" @@ -112,6 +114,8 @@ check_command() { return 0 elif test $1 == "dev"; then return 0 + elif test $1 == "export"; then + return 0 elif test $1 == "init"; then return 0 elif test $1 == "migrate"; then @@ -189,6 +193,22 @@ another name please set GISSMO_DOCKER_NAME in configuration file." fi } +test_export() { + # Check postgreSQL Docker container exists and is launched. + test_postgresql_launched + if [ $? -eq 1 ]; then + $docker_cmd start ${POSTGRES_DOCKER_NAME} + fi +} + +export() { + # Check all variables are availables + test_create + # Then check some specific things for dump method + test_export + $docker_cmd run -it --rm --volume $PWD/:/tmp/ --link ${POSTGRES_DOCKER_NAME}:db postgres:${POSTGRES_VERSION} bash -c 'exec pg_dump -F c -h "$DB_PORT_5432_TCP_ADDR" -p "$DB_PORT_5432_TCP_PORT" -U postgres postgres > /tmp/gissmo-`date +"%Y.%m.%d.%H%M"`-'${GISSMO_VERSION}'.dump' || error_and_quit "Failed to export Gissmo database." +} + init() { # check directory existence if ! test -d "$PROJECT_DIR"; then