Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
b8f68384a6 | |||
e92ea8488d | |||
da74d4b4a6 | |||
553174219c | |||
acf07de49a | |||
1cf29b3e5b | |||
ff93eb34b0 | |||
0a8526813e | |||
f5163ce894 | |||
416fbce956 | |||
fa9ea2fcdb | |||
e211f62306 | |||
f8ecbe1d1a |
1
TODO
1
TODO
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## À faire
|
## À faire
|
||||||
|
|
||||||
|
* Supprimer le git-hook et remplacer par pre-commit install
|
||||||
* Faire un script qui lance l'environnement complet pour le test et les lance
|
* Faire un script qui lance l'environnement complet pour le test et les lance
|
||||||
|
|
||||||
## Terminés
|
## Terminés
|
||||||
|
@ -17,9 +17,9 @@ PROJECT_DIR="${HOME}/gissmo_project"
|
|||||||
POSTGRES_VERSION="9.5"
|
POSTGRES_VERSION="9.5"
|
||||||
POSTGRES_DOCKER_NAME="gissmo_db"
|
POSTGRES_DOCKER_NAME="gissmo_db"
|
||||||
DB_DIR="/dbdata"
|
DB_DIR="/dbdata"
|
||||||
DB_VOLUME_NAME="dbdata"
|
|
||||||
GIT_BRANCH="v1.7"
|
GIT_BRANCH="v1.7"
|
||||||
GISSMO_VERSION="1.7"
|
GISSMO_VERSION="1.7"
|
||||||
# GISSMO_DOCKER_NAME="gissmo"
|
# GISSMO_DOCKER_NAME="gissmo"
|
||||||
|
DJANGO_DIR="django" # only for Gissmo 2.x
|
||||||
GISSMO_DOCKER_PORT="8002"
|
GISSMO_DOCKER_PORT="8002"
|
||||||
UPLOAD_DIR="/srv/upload"
|
UPLOAD_DIR="/srv/upload"
|
||||||
|
36
launch.sh
36
launch.sh
@ -10,7 +10,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"
|
||||||
POSTGRES_VERSION="9.5"
|
POSTGRES_VERSION="9.5-alpine"
|
||||||
|
POSTGRES_PORT=5433
|
||||||
GISSMO_DOCKER_NAME="gissmo"
|
GISSMO_DOCKER_NAME="gissmo"
|
||||||
|
|
||||||
## User
|
## User
|
||||||
@ -46,6 +47,13 @@ fi
|
|||||||
GISSMO_DIR="${PROJECT_DIR}/${GIT_DIR_NAME}"
|
GISSMO_DIR="${PROJECT_DIR}/${GIT_DIR_NAME}"
|
||||||
DOCKERFILE="${GISSMO_DIR}/${DOCKERFILE_NAME}"
|
DOCKERFILE="${GISSMO_DIR}/${DOCKERFILE_NAME}"
|
||||||
|
|
||||||
|
# Set DJANGO_VOLUME_DIR
|
||||||
|
if ! test -z "$DJANGO_DIR"; then
|
||||||
|
DJANGO_VOLUME_DIR="${GISSMO_DIR}/$DJANGO_DIR"
|
||||||
|
else
|
||||||
|
DJANGO_VOLUME_DIR="${GISSMO_DIR}"
|
||||||
|
fi
|
||||||
|
|
||||||
## Miscellaneous
|
## Miscellaneous
|
||||||
COMMAND="$1"
|
COMMAND="$1"
|
||||||
shift 1; ARGS="$@"
|
shift 1; ARGS="$@"
|
||||||
@ -84,8 +92,7 @@ show_help() {
|
|||||||
echo -e " Where ${green}COMMAND${reset} is one of:"
|
echo -e " Where ${green}COMMAND${reset} is one of:"
|
||||||
echo -e " - backup Create a compressed postgreSQL database dump
|
echo -e " - backup Create a compressed postgreSQL database dump
|
||||||
in current directory"
|
in current directory"
|
||||||
echo -e " - create Create postgreSQL database volume and
|
echo -e " - create Create postgreSQL Docker container"
|
||||||
postgreSQL Docker container"
|
|
||||||
echo -e " - dev [arg ...] Mount Git repository directory AS VOLUME
|
echo -e " - dev [arg ...] Mount Git repository directory AS VOLUME
|
||||||
for Gissmo Docker container and launch it in
|
for Gissmo Docker container and launch it in
|
||||||
'development' mode"
|
'development' mode"
|
||||||
@ -162,10 +169,6 @@ test_create() {
|
|||||||
if test -z "$DB_DIR"; then
|
if test -z "$DB_DIR"; then
|
||||||
error_and_quit "No database directory given (DB_DIR in config file)."
|
error_and_quit "No database directory given (DB_DIR in config file)."
|
||||||
fi
|
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
|
if test -z "$POSTGRES_VERSION"; then
|
||||||
error_and_quit "No postgres version given (POSTGRES_VERSION in
|
error_and_quit "No postgres version given (POSTGRES_VERSION in
|
||||||
config file)."
|
config file)."
|
||||||
@ -179,8 +182,7 @@ config file)."
|
|||||||
create() {
|
create() {
|
||||||
test_create
|
test_create
|
||||||
init
|
init
|
||||||
$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 -p ${POSTGRES_PORT}:5432 -v "${DB_DIR}:/var/lib/postgresql/data" --name "${POSTGRES_DOCKER_NAME}" "postgres:${POSTGRES_VERSION}" || error_and_quit "Launching database docker container failed."
|
||||||
$docker_cmd run -d -P --volumes-from "${DB_VOLUME_NAME}" --name "${POSTGRES_DOCKER_NAME}" "postgres:${POSTGRES_VERSION}" || error_and_quit "Launching database docker container failed."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dev() {
|
dev() {
|
||||||
@ -190,7 +192,7 @@ dev() {
|
|||||||
if [ $GISSMO_DEV_RUNNING_PORT -eq 0 ]; then
|
if [ $GISSMO_DEV_RUNNING_PORT -eq 0 ]; then
|
||||||
PORT_PARAM=" -P "
|
PORT_PARAM=" -P "
|
||||||
fi
|
fi
|
||||||
$docker_cmd run -it --rm --link ${POSTGRES_DOCKER_NAME}:db ${PORT_PARAM} -v ${GISSMO_DIR}:/opt/gissmo -v ${UPLOAD_DIR}:/data gissmo:${GISSMO_VERSION} ${ARGS:='development'} || error_and_quit "Failed to create and launch ${GISSMO_DOCKER_NAME} container."
|
$docker_cmd run -it --rm --link ${POSTGRES_DOCKER_NAME}:db ${PORT_PARAM} -v ${DJANGO_VOLUME_DIR}:/opt/gissmo -v ${UPLOAD_DIR}:/data gissmo:${GISSMO_VERSION} ${ARGS:='development'} || error_and_quit "Failed to create and launch ${GISSMO_DOCKER_NAME} container."
|
||||||
}
|
}
|
||||||
|
|
||||||
test_backup() {
|
test_backup() {
|
||||||
@ -229,11 +231,13 @@ init() {
|
|||||||
GIT_WORK_TREE="${GISSMO_DIR}/" GIT_DIR="${GISSMO_DIR}/.git/" git pull -q origin ${GIT_BRANCH} || error_and_quit "Pull command on Git repository failed."
|
GIT_WORK_TREE="${GISSMO_DIR}/" GIT_DIR="${GISSMO_DIR}/.git/" git pull -q origin ${GIT_BRANCH} || error_and_quit "Pull command on Git repository failed."
|
||||||
fi
|
fi
|
||||||
info "Git repository state checked."
|
info "Git repository state checked."
|
||||||
# install pre-commit hook that check code validity and more
|
# install pre-commit hook that check code validity and more (only for 1.9 branchs)
|
||||||
if ! test -f "${GISSMO_DIR}/.git/hooks/pre-commit"; then
|
if ! test -f "${GISSMO_DIR}/.git/hooks/pre-commit"; then
|
||||||
|
if test -f "${GISSMO_DIR}/scripts/git_hooks/pre-commit"; then
|
||||||
cp "${GISSMO_DIR}/scripts/git_hooks/pre-commit" "${GISSMO_DIR}/.git/hooks/pre-commit" || error_and_quit "Failed to install pre-commit hook."
|
cp "${GISSMO_DIR}/scripts/git_hooks/pre-commit" "${GISSMO_DIR}/.git/hooks/pre-commit" || error_and_quit "Failed to install pre-commit hook."
|
||||||
info "Git repository pre-commit hook installed."
|
info "Git repository pre-commit hook installed."
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
source bin/activate || error_and_quit "Failed entering python virtual environment"
|
source bin/activate || error_and_quit "Failed entering python virtual environment"
|
||||||
cd "$GISSMO_DIR"
|
cd "$GISSMO_DIR"
|
||||||
pip install -q -r requirements.txt || error_and_quit "Python dependancies
|
pip install -q -r requirements.txt || error_and_quit "Python dependancies
|
||||||
@ -261,6 +265,9 @@ test_restore() {
|
|||||||
DUMP_FILE=`basename $ARGS`
|
DUMP_FILE=`basename $ARGS`
|
||||||
info "Dump file found: ${DUMP_FILE}"
|
info "Dump file found: ${DUMP_FILE}"
|
||||||
DUMP_DIR="${ARGS%/*}"
|
DUMP_DIR="${ARGS%/*}"
|
||||||
|
if [ -z "$DUMP_DIR" ]; then
|
||||||
|
DUMP_DIR="/"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
psql() {
|
psql() {
|
||||||
@ -277,8 +284,11 @@ restore() {
|
|||||||
test_restore
|
test_restore
|
||||||
$docker_cmd stop ${POSTGRES_DOCKER_NAME} && $docker_cmd rm ${POSTGRES_DOCKER_NAME} || error_and_quit "Failed to stop and delete postgreSQL Docker container: ${POSTGRES_DOCKER_NAME}"
|
$docker_cmd stop ${POSTGRES_DOCKER_NAME} && $docker_cmd rm ${POSTGRES_DOCKER_NAME} || error_and_quit "Failed to stop and delete postgreSQL Docker container: ${POSTGRES_DOCKER_NAME}"
|
||||||
sudo rm -rf ${DB_DIR} || error_and_quit "Failed to delete this directory: ${DB_DIR}"
|
sudo rm -rf ${DB_DIR} || error_and_quit "Failed to delete this directory: ${DB_DIR}"
|
||||||
$docker_cmd run -d -P --volumes-from "${DB_VOLUME_NAME}" --name "${POSTGRES_DOCKER_NAME}" "postgres:${POSTGRES_VERSION}" || error_and_quit "Launching database docker container failed."
|
$docker_cmd run -d -p ${POSTGRES_PORT}:5432 -v "${DB_DIR}:/var/lib/postgresql/data" --name "${POSTGRES_DOCKER_NAME}" "postgres:${POSTGRES_VERSION}" || error_and_quit "Launching database docker container failed."
|
||||||
sleep 6 # to wait about docker container runs totally
|
# Wait postgres was initialized
|
||||||
|
until $docker_cmd run --rm --link ${POSTGRES_DOCKER_NAME}:postgres postgres:${POSTGRES_VERSION} pg_isready -U postgres -h postgres; do
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
RESTORE_COMMAND="$docker_cmd run -it --rm --link ${POSTGRES_DOCKER_NAME}:db -v ${DUMP_DIR}:/backup -e PGHOST=`$docker_cmd inspect -f \"{{ .NetworkSettings.IPAddress }}\" ${POSTGRES_DOCKER_NAME}` -e PGUSER=postgres postgres:${POSTGRES_VERSION} pg_restore -d postgres /backup/${DUMP_FILE}"
|
RESTORE_COMMAND="$docker_cmd run -it --rm --link ${POSTGRES_DOCKER_NAME}:db -v ${DUMP_DIR}:/backup -e PGHOST=`$docker_cmd inspect -f \"{{ .NetworkSettings.IPAddress }}\" ${POSTGRES_DOCKER_NAME}` -e PGUSER=postgres postgres:${POSTGRES_VERSION} pg_restore -d postgres /backup/${DUMP_FILE}"
|
||||||
exec $RESTORE_COMMAND || error_and_quit "Failed to launch this command: ${CMD}"
|
exec $RESTORE_COMMAND || error_and_quit "Failed to launch this command: ${CMD}"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user