[IMP] Launch script: Add 'dev' command to launch a development Gissmo

Docker container with git repository mounted as a volume.
This commit is contained in:
Olivier DOSSMANN 2016-01-13 10:01:44 +01:00
parent d14c25648c
commit 8f7009597e

View File

@ -58,10 +58,11 @@ show_help() {
echo "$PROGRAM [COMMAND]"
echo -e " Where ${green}COMMAND${reset} is one of:"
echo -e " - create Create postgreSQL database volume and postgreSQL Docker container"
echo -e " - dev Mount git repository directory as volume for Gissmo Docker container and launch it in 'development' mode"
echo -e " - init Create project directory as python virtual environment, fetch git repository and install Python dependancies"
echo -e " - migrate Launch migration command: python manage.py migrate"
echo -e " - restore dump Restore the given dump"
echo -e " - start args Launch Gissmo Docker container (created by 'create' command) with a name given in GISSMO_DOCKER_NAME variable"
echo -e " - start args Launch Gissmo Docker container (created by 'create' command) with a name given in GISSMO_DOCKER_NAME variable. args is optional."
echo -e " - stop Stop Gissmo Docker container which name is GISSMO_DOCKER_NAME variable content"
# TODO: Add clean() command to STOP and DELETE Gissmo Docker container
# TODO: Add clean_db() command to STOP and DELETE postgreSQL Docker container
@ -69,8 +70,11 @@ show_help() {
}
check_command() {
# Allowed commands return 0 to continue. Otherwise show help and exit
if test $1 == "create"; then
return 0
elif test $1 == "dev"; then
return 0
elif test $1 == "init"; then
return 0
elif test $1 == "migrate"; then
@ -132,6 +136,17 @@ create() {
$docker_cmd run -d --volumes-from "${DB_VOLUME_NAME}" --name "${POSTGRES_DOCKER_NAME}" "postgres:${POSTGRES_VERSION}" || error_and_quit "Launching database docker container failed."
}
dev() {
initial_start
# Run existing Docker container, otherwise create a new one
GISSMO_RUNNING=$($docker_cmd inspect --format="{{ .State.Running }}" ${GISSMO_DOCKER_NAME} 2> /dev/null)
if [ $? -eq 1 ]; then
$docker_cmd run -it --rm --link ${POSTGRES_DOCKER_NAME}:db -p ${GISSMO_DOCKER_PORT}:8000 -v ${GISSMO_DIR}:/opt/gissmo --name ${GISSMO_DOCKER_NAME} gissmo:${GISSMO_VERSION} development || error_and_quit "Failed to create and launch ${GISSMO_DOCKER_NAME} container."
else
error_and_quit "${GISSMO_DOCKER_NAME} is already launched!"
fi
}
init() {
# check directory existence
if ! test -d "$PROJECT_DIR"; then
@ -189,7 +204,7 @@ restore() {
exec $RESTORE_COMMAND || error_and_quit "Failed to launch this command: ${CMD}"
}
test_start() {
test_initial_start() {
if test -z "$GISSMO_VERSION"; then
error_and_quit "No Gissmo version given (GISSMO_VERSION in config file)."
fi
@ -199,8 +214,8 @@ test_start() {
test_postgresql_exists
}
start() {
test_start
initial_start() {
test_initial_start
# Build Gissmo Docker images if missing
if [[ "$($docker_cmd images -q gissmo:${GISSMO_VERSION} 2> /dev/null)" == "" ]]; then
cd $GISSMO_DIR
@ -212,6 +227,10 @@ start() {
if [ $? -eq 1 ]; then
$docker_cmd start ${POSTGRES_DOCKER_NAME}
fi
}
start() {
initial_start
# Run existing Docker container, otherwise create a new one
GISSMO_RUNNING=$($docker_cmd inspect --format="{{ .State.Running }}" ${GISSMO_DOCKER_NAME} 2> /dev/null)
if [ $? -eq 1 ]; then