From 862c671efb18f2d54ed9abb04fd05fbdec3600a6 Mon Sep 17 00:00:00 2001 From: Marc Quinton Date: Tue, 25 Jan 2022 07:47:31 +0100 Subject: [PATCH] wip: first working version :-) --- .gitignore | 1 + build/diacama-syndic/Dockerfile | 19 ++++- build/diacama-syndic/entrypoint.d/common.sh | 8 ++ .../diacama-syndic/entrypoint.d/entrypoint.sh | 37 +++++++++ .../entrypoint.d/sub_command/backup.sh | 8 ++ .../entrypoint.d/sub_command/restore.sh | 13 ++++ .../entrypoint.d/sub_command/run.sh | 78 +++++++++++++++++++ .../entrypoint.d/sub_command/usage.sh | 39 ++++++++++ .../entrypoint.d/sub_command/version.sh | 7 ++ docker-compose.yml | 8 +- 10 files changed, 212 insertions(+), 6 deletions(-) create mode 100644 .gitignore create mode 100755 build/diacama-syndic/entrypoint.d/common.sh create mode 100755 build/diacama-syndic/entrypoint.d/entrypoint.sh create mode 100755 build/diacama-syndic/entrypoint.d/sub_command/backup.sh create mode 100755 build/diacama-syndic/entrypoint.d/sub_command/restore.sh create mode 100755 build/diacama-syndic/entrypoint.d/sub_command/run.sh create mode 100755 build/diacama-syndic/entrypoint.d/sub_command/usage.sh create mode 100755 build/diacama-syndic/entrypoint.d/sub_command/version.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8fce603 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +data/ diff --git a/build/diacama-syndic/Dockerfile b/build/diacama-syndic/Dockerfile index 1e527fe..ecb727c 100644 --- a/build/diacama-syndic/Dockerfile +++ b/build/diacama-syndic/Dockerfile @@ -29,7 +29,24 @@ RUN set -x ; \ pip install -U $PIP_OPTION pip ; \ pip install -U $PIP_OPTION $PACKAGES +RUN set -x ; \ + . $LUCTERIOS_PATH/virtual_for_lucterios/bin/activate ; \ + pip install gunicorn + +RUN set -x ; \ + . $LUCTERIOS_PATH/virtual_for_lucterios/bin/activate ; \ + pip install psycopg2-binary + +# RUN set -x ; \ +# . $LUCTERIOS_PATH/virtual_for_lucterios/bin/activate ; \ +# pip install mysqlclient + ADD launch_lucterios.sh $LUCTERIOS_PATH +ADD entrypoint.d /entrypoint.d + +RUN ls /entrypoint.d + EXPOSE 8100 -ENTRYPOINT $LUCTERIOS_PATH/launch_lucterios.sh +ENTRYPOINT /entrypoint.d/entrypoint.sh run + diff --git a/build/diacama-syndic/entrypoint.d/common.sh b/build/diacama-syndic/entrypoint.d/common.sh new file mode 100755 index 0000000..880a749 --- /dev/null +++ b/build/diacama-syndic/entrypoint.d/common.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +function run { + echo "undefined function run" +} + +function usage { + echo "undefined function usage" +} diff --git a/build/diacama-syndic/entrypoint.d/entrypoint.sh b/build/diacama-syndic/entrypoint.d/entrypoint.sh new file mode 100755 index 0000000..00eff4d --- /dev/null +++ b/build/diacama-syndic/entrypoint.d/entrypoint.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# this entrypoint come from : https://hub.docker.com/r/mgodlewski/diacamma +# thanks. + +set -e + +trap "exit 1" TERM +export TOP_PID=$$ + +export CURRENT_ORGANISATION=${DIACAMMA_ORGANISATION:-asso} +export CURRENT_DIACAMMA_TYPE=${DIACAMMA_TYPE:-asso} + +export BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "${BIN_DIR}/common.sh" +pushd ${BIN_DIR} > /dev/null + +COMMAND="$1" +if [ "${COMMAND}" == "" ]; then + COMMAND="usage" +else + # shift off first parameter to cascade remaining to sub command + shift 1 +fi + +if [ ! -f sub_command/${COMMAND}.sh ]; then + echo "Undefined command \"${COMMAND}\". See usage below:" + echo "" + COMMAND="usage" +fi +source "sub_command/${COMMAND}.sh" + +run $@ +RETURN_CODE=$? +popd > /dev/null +exit ${RETURN_CODE} diff --git a/build/diacama-syndic/entrypoint.d/sub_command/backup.sh b/build/diacama-syndic/entrypoint.d/sub_command/backup.sh new file mode 100755 index 0000000..dbf15aa --- /dev/null +++ b/build/diacama-syndic/entrypoint.d/sub_command/backup.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +function run { + pushd /var/lucterios2 > /dev/null + now=$(date "+%Y%m%d_%H_%M_%S") + /bin/bash launch_lucterios.sh archive --name=${CURRENT_ORGANISATION} --file=/backups/backup_${now}.lbkf + popd > /dev/null +} diff --git a/build/diacama-syndic/entrypoint.d/sub_command/restore.sh b/build/diacama-syndic/entrypoint.d/sub_command/restore.sh new file mode 100755 index 0000000..554b5fb --- /dev/null +++ b/build/diacama-syndic/entrypoint.d/sub_command/restore.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +function run { + pushd /var/lucterios2 > /dev/null + filename="/backups/${1}" + if [ -f ${filename} ] + then + /bin/bash launch_lucterios.sh restore --name=${CURRENT_ORGANISATION} --file=${filename} + else + echo "File ${filename} not found : cannot restore instance ${CURRENT_ORGANISATION}" + fi + popd > /dev/null +} diff --git a/build/diacama-syndic/entrypoint.d/sub_command/run.sh b/build/diacama-syndic/entrypoint.d/sub_command/run.sh new file mode 100755 index 0000000..0a4e082 --- /dev/null +++ b/build/diacama-syndic/entrypoint.d/sub_command/run.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +function wait_database { + # Wait for DB to be ready before starting this + if [ "${DIACAMMA_DATABASE}" != "" ] + then + sleep 10 + fi +} + +function get_database_param { + if [ "${DIACAMMA_DATABASE}" != "" ] + then + echo "-d ${DIACAMMA_DATABASE}" + else + echo "" + fi +} + +function get_module_list { + case "${CURRENT_DIACAMMA_TYPE}" in + asso) + echo "lucterios.contacts,lucterios.documents,lucterios.mailing,diacamma.accounting,diacamma.payoff,diacamma.event,diacamma.member,diacamma.invoice" + return 0 + ;; + syndic) + echo "lucterios.contacts,lucterios.documents,lucterios.mailing,diacamma.accounting,diacamma.payoff,diacamma.condominium" + return 0 + ;; + *) + kill -s TERM ${TOP_PID} + ;; + esac +} + +function init_database { + if [ "${DIACAMMA_DATABASE}" != "" ] + then + pushd /var/lucterios2 > /dev/null + /bin/bash launch_lucterios.sh refreshall + popd > /dev/null + fi +} + +function run { + echo Organisation: ${CURRENT_ORGANISATION} + echo Type: ${CURRENT_DIACAMMA_TYPE} + + wait_database + + pushd /var/lucterios2 > /dev/null + if [ ! -f ${CURRENT_ORGANISATION}/settings.py ] + then + modules=$(get_module_list) + database_parameter=$(get_database_param) + + /bin/bash launch_lucterios.sh add -n ${CURRENT_ORGANISATION} -m "${modules}" -p diacamma.${CURRENT_DIACAMMA_TYPE} ${database_parameter} + + echo "LANGUAGE_CODE = 'fr'" >> ${CURRENT_ORGANISATION}/settings.py + echo "ALLOWED_HOSTS = [ '*' ]" >> ${CURRENT_ORGANISATION}/settings.py + fi + + source virtual_for_lucterios/bin/activate + export DJANGO_SETTINGS_MODULE="${CURRENT_ORGANISATION}.settings" + + init_database + + exec gunicorn lucterios.framework.wsgi --bind=0.0.0.0:8100 --access-logfile - --error-logfile - + popd > /dev/null +} + +function usage { + echo "Usage:" + echo " entrypoint.sh run" + echo "" + echo " Run the Diacamma instance" + echo "" +} diff --git a/build/diacama-syndic/entrypoint.d/sub_command/usage.sh b/build/diacama-syndic/entrypoint.d/sub_command/usage.sh new file mode 100755 index 0000000..498ea8a --- /dev/null +++ b/build/diacama-syndic/entrypoint.d/sub_command/usage.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +function run { + COMMAND="${1}" + if [ "${COMMAND}" != "" ]; then + if [ ! -f sub_command/${COMMAND}.sh ]; then + display_error "Undefined command \"${COMMAND}\". See usage below:" + echo "" + else + source "sub_command/${COMMAND}.sh" + # shift off first parameter to cascade remaining to sub command + shift 1 + usage $@ + return 0 + fi + fi + + usage +} + +function usage { + echo "Usage:" + echo " entrypoint.sh []" + echo "" + echo "Available commands:" + echo "" + echo " Action:" + echo " run Run Diacamma instance" + echo "" + echo " Admin:" + echo " backup Backup Diacamma instance to a backup file" + echo " restore Restore Diacamma instance from the provided backup file" + echo "" + echo " Help:" + echo " version Show the Diacamma version running" + echo " usage This help screen" + echo " usage Help for the given command" + echo "" +} diff --git a/build/diacama-syndic/entrypoint.d/sub_command/version.sh b/build/diacama-syndic/entrypoint.d/sub_command/version.sh new file mode 100755 index 0000000..00807a4 --- /dev/null +++ b/build/diacama-syndic/entrypoint.d/sub_command/version.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +function run { + pushd /var/lucterios2 > /dev/null + /bin/bash launch_lucterios.sh check | grep '=>' | cut -f2 | sort | tail -1 + popd > /dev/null +} diff --git a/docker-compose.yml b/docker-compose.yml index e192ac8..ababb7e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -56,18 +56,16 @@ services: build: context: ./build/diacama-syndic/ dockerfile: Dockerfile - # args: - # TAG: 1.34.0 restart: unless-stopped ports: - "127.0.0.1:8100:8100" volumes: - ./data/diacamma/backups/:/backups - - ./data/diacamma/data:/var/lucterios2/ramier-des-cedres-1 - - ./data/diacamma/var/error.log:/var/lucterios2/error.log + - ./data/diacamma/data:/var/lucterios2/mon-syndic + # - ./data/diacamma/var/error.log:/var/lucterios2/error.log environment: - DIACAMMA_TYPE=syndic - - DIACAMMA_ORGANISATION=ramier-des-cedres-1 + - DIACAMMA_ORGANISATION=mon-syndic - DIACAMMA_DATABASE=sqlite networks: