Skip to content

Commit

Permalink
wip: first working version :-)
Browse files Browse the repository at this point in the history
  • Loading branch information
mqu committed Jan 25, 2022
1 parent 04b4c6a commit 862c671
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/
19 changes: 18 additions & 1 deletion build/diacama-syndic/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

8 changes: 8 additions & 0 deletions build/diacama-syndic/entrypoint.d/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
function run {
echo "undefined function run"
}

function usage {
echo "undefined function usage"
}
37 changes: 37 additions & 0 deletions build/diacama-syndic/entrypoint.d/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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}
8 changes: 8 additions & 0 deletions build/diacama-syndic/entrypoint.d/sub_command/backup.sh
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 13 additions & 0 deletions build/diacama-syndic/entrypoint.d/sub_command/restore.sh
Original file line number Diff line number Diff line change
@@ -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
}
78 changes: 78 additions & 0 deletions build/diacama-syndic/entrypoint.d/sub_command/run.sh
Original file line number Diff line number Diff line change
@@ -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 ""
}
39 changes: 39 additions & 0 deletions build/diacama-syndic/entrypoint.d/sub_command/usage.sh
Original file line number Diff line number Diff line change
@@ -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 [<command_name>]"
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 <file-to-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 <command_name> Help for the given command"
echo ""
}
7 changes: 7 additions & 0 deletions build/diacama-syndic/entrypoint.d/sub_command/version.sh
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 3 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 862c671

Please sign in to comment.