Compare commits
13 Commits
Author | SHA1 | Date |
---|---|---|
Olivier DOSSMANN | b8f68384a6 | |
Olivier DOSSMANN | e92ea8488d | |
Olivier DOSSMANN | da74d4b4a6 | |
Olivier DOSSMANN | 553174219c | |
Olivier DOSSMANN | acf07de49a | |
Olivier DOSSMANN | 1cf29b3e5b | |
Olivier DOSSMANN | ff93eb34b0 | |
Olivier DOSSMANN | 0a8526813e | |
Olivier DOSSMANN | f5163ce894 | |
Olivier DOSSMANN | 416fbce956 | |
Olivier DOSSMANN | fa9ea2fcdb | |
Olivier DOSSMANN | e211f62306 | |
Olivier DOSSMANN | f8ecbe1d1a |
1
TODO
1
TODO
|
@ -2,6 +2,7 @@
|
|||
|
||||
## À 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
|
||||
|
||||
## Terminés
|
||||
|
|
|
@ -17,9 +17,9 @@ PROJECT_DIR="${HOME}/gissmo_project"
|
|||
POSTGRES_VERSION="9.5"
|
||||
POSTGRES_DOCKER_NAME="gissmo_db"
|
||||
DB_DIR="/dbdata"
|
||||
DB_VOLUME_NAME="dbdata"
|
||||
GIT_BRANCH="v1.7"
|
||||
GISSMO_VERSION="1.7"
|
||||
# GISSMO_DOCKER_NAME="gissmo"
|
||||
DJANGO_DIR="django" # only for Gissmo 2.x
|
||||
GISSMO_DOCKER_PORT="8002"
|
||||
UPLOAD_DIR="/srv/upload"
|
||||
|
|
40
launch.sh
40
launch.sh
|
@ -10,7 +10,8 @@ GIT_URL="git@github.com:eost/gissmo.git"
|
|||
GIT_BRANCH="dev" # Default Git Branch
|
||||
GIT_DIR_NAME="gissmo"
|
||||
DOCKERFILE_NAME="Dockerfile"
|
||||
POSTGRES_VERSION="9.5"
|
||||
POSTGRES_VERSION="9.5-alpine"
|
||||
POSTGRES_PORT=5433
|
||||
GISSMO_DOCKER_NAME="gissmo"
|
||||
|
||||
## User
|
||||
|
@ -46,6 +47,13 @@ fi
|
|||
GISSMO_DIR="${PROJECT_DIR}/${GIT_DIR_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
|
||||
COMMAND="$1"
|
||||
shift 1; ARGS="$@"
|
||||
|
@ -84,8 +92,7 @@ show_help() {
|
|||
echo -e " Where ${green}COMMAND${reset} is one of:"
|
||||
echo -e " - backup Create a compressed postgreSQL database dump
|
||||
in current directory"
|
||||
echo -e " - create Create postgreSQL database volume and
|
||||
postgreSQL Docker container"
|
||||
echo -e " - create Create postgreSQL Docker container"
|
||||
echo -e " - dev [arg ...] Mount Git repository directory AS VOLUME
|
||||
for Gissmo Docker container and launch it in
|
||||
'development' mode"
|
||||
|
@ -162,10 +169,6 @@ test_create() {
|
|||
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)."
|
||||
|
@ -179,8 +182,7 @@ config file)."
|
|||
create() {
|
||||
test_create
|
||||
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 --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."
|
||||
}
|
||||
|
||||
dev() {
|
||||
|
@ -190,7 +192,7 @@ dev() {
|
|||
if [ $GISSMO_DEV_RUNNING_PORT -eq 0 ]; then
|
||||
PORT_PARAM=" -P "
|
||||
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() {
|
||||
|
@ -229,10 +231,12 @@ 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."
|
||||
fi
|
||||
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
|
||||
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."
|
||||
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."
|
||||
info "Git repository pre-commit hook installed."
|
||||
fi
|
||||
fi
|
||||
source bin/activate || error_and_quit "Failed entering python virtual environment"
|
||||
cd "$GISSMO_DIR"
|
||||
|
@ -261,6 +265,9 @@ test_restore() {
|
|||
DUMP_FILE=`basename $ARGS`
|
||||
info "Dump file found: ${DUMP_FILE}"
|
||||
DUMP_DIR="${ARGS%/*}"
|
||||
if [ -z "$DUMP_DIR" ]; then
|
||||
DUMP_DIR="/"
|
||||
fi
|
||||
}
|
||||
|
||||
psql() {
|
||||
|
@ -277,8 +284,11 @@ 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}"
|
||||
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."
|
||||
sleep 6 # to wait about docker container runs totally
|
||||
$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."
|
||||
# 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}"
|
||||
exec $RESTORE_COMMAND || error_and_quit "Failed to launch this command: ${CMD}"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue