geneweb7 dans docker
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

173 lines
3.9 KiB

#!/usr/bin/env bash
set -e
PROJECT_NAME=geneweb
PROJECT_RELEASE=7.1.0-beta2
WEB_PORT=2317
DATA_HOME=/home/geneweb
LANGUAGE="fr"
HOST_IP="172.17.0.1"
TIME_ZONE="Europe/Paris"
function containerName()
{
echo "${PROJECT_NAME}_${PROJECT_RELEASE}"
}
function usage()
{
cat << EOF
${0}
Command options:
-h Display this help message.
-b Build the GeneWeb container
-r | -z Run the GeneWeb container | Build and run the GeneWeb Container
Option parameters:
-l The language to run GeneWeb in e.g. (en, de, fr)
-i The host ip address where the setup portal will be accessed from
-t The time zone to run GeneWeb in. e.g. (Australia/Melbourne)
-w The web portal port number. e.g. 2317
-b The storage location for the bases e.g. ~/GenealogyData
-k Stop the container
-i Import database
-s Backup database
EOF
exit 1
}
function displayRunning()
{
cat << RUNNING
GeneWeb is running using language '${LANGUAGE}' in the time zone '${TIME_ZONE}'
The bases will be stored under '${DATA_HOME}'
The web portal can be accessed at http://localhost:${WEB_PORT}
To stop the GeneWeb container, execute: '${0} -k'
RUNNING
}
function checkoutRepo()
{
find / -name "geneweb-7.1.0-beta2-linux.zip" -exec cp {} . \;
}
function buildContainer()
{
if grep -e "${PROJECT_NAME}:${PROJECT_RELEASE}" "$(docker image list)" 2> /dev/null
then
docker image rm ${PROJECT_NAME}:${PROJECT_RELEASE}
fi
echo "docker buildx build --tag geneweb:${PROJECT_RELEASE} ."
docker buildx build --tag geneweb:${PROJECT_RELEASE} .
}
function import()
{
docker cp ../genealogie/adrien.gw ${containerName}:/home/geneweb/import/
docker exec -it $(containerName) import.sh
}
function backup()
{
docker exec -it $(containerName) backup.sh
}
function runContainer()
{
# Create the database directory
# mkdir -p ${DATA_HOME}
# Remove any running/old containers
stopContainer && removeContainer
# Run the container in detached mode
echo "docker run --detach --restart unless-stopped --publish ${WEB_PORT}:${WEB_PORT} --volume ${DATA_HOME}:${DATA_HOME} --env HOST_IP=${HOST_IP} --env LANGUAGE=${LANGUAGE} --env TZ=${TIME_ZONE} --name $(containerName) ${PROJECT_NAME}:${PROJECT_RELEASE}"
docker run --detach --restart unless-stopped --publish ${WEB_PORT}:${WEB_PORT} --volume ${DATA_HOME}:${DATA_HOME} --env HOST_IP=${HOST_IP} --env LANGUAGE=${LANGUAGE} --env TZ=${TIME_ZONE} --name $(containerName) ${PROJECT_NAME}:${PROJECT_RELEASE}
}
function stopContainer()
{
docker stop $(containerName)
}
function removeContainer()
{
set +e
docker rm $(containerName) 2>/dev/null
set -e
}
function invalidOption()
{
echo "Invalid Command: -$OPTARG" 1>&2
}
function invalidOptionParameter()
{
echo "Invalid Option: -$OPTARG" 1>&2
}
function optionParameterRequiresValue()
{
echo "Option: -$OPTARG requires an argument" 1>&2
}
while getopts ":hbrzkis" opt; do
case ${opt} in
h ) usage ;;
b ) buildContainer; exit $? ;;
r | z )
command=${opt}
while getopts ":l:t:i:w:b:" opt; do
case ${opt} in
l ) LANGUAGE=$OPTARG ;;
t ) TIME_ZONE=$OPTARG ;;
i ) HOST_IP=$OPTARG ;;
w ) WEB_PORT=$OPTARG ;;
b ) DATA_HOME=$OPTARG ;;
\? ) invalidOptionParameter && usage ;;
: ) optionParameterRequiresValue && usage ;;
esac
done
if [[ "${command}" = "r" ]]; then
runContainer
else
buildContainer && runContainer
fi
displayRunning; exit $?
;;
k ) stopContainer; exit $? ;;
i ) import ; exit $? ;;
s) backup ; exit $? ;;
\? ) invalidOption && usage ;;
esac
done
if [[ $OPTIND -eq 1 ]]; then
usage
fi