diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f6f156b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +FROM debian:stable-slim + +LABEL org.opencontainers.image.authors="ccyr@alwaysdata.net" + +RUN apt-get update && apt-get --assume-yes --no-install-recommends install libgmp10 libpcre2-dev unzip && rm -rf /var/lib/apt/lists/* && apt-get clean && apt-get autoclean + +COPY bin/*.sh /usr/local/bin + +RUN useradd --uid 2317 --home-dir /home/geneweb geneweb + +RUN mkdir -p /home/geneweb/bases /home/geneweb/import /home/geneweb/backup + +COPY geneweb-7.1.0-beta2-linux.zip / + +RUN chmod a+x /usr/local/bin/*.sh + +RUN unzip /geneweb-7.1.0-beta2-linux.zip -d /opt/ + +RUN chown -R geneweb:geneweb /home/geneweb + +VOLUME ["/home/geneweb"] + +ENV LANGAGE fr + +EXPOSE 2317 + +USER geneweb + +ENTRYPOINT ["main.sh"] +CMD ["start"] \ No newline at end of file diff --git a/README.md b/README.md index ef1d4ed..828456c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,33 @@ -# geneweb7_docker +# Docker image with geneweb7 image -geneweb7 dans docker \ No newline at end of file +## Build container + +```bash +docker buildx build --tag geneweb . +``` + +## Test + +```bash +docker run -it --rm --name gw geneweb:latest /bin/bash +``` + +## start container + +```bash +docker run -d --name geneweb -p 2317:2317 \ + -v /home/geneweb/bases:/home/geneweb/bases \ + geneweb:latest +``` + +## backup database + +```bash +docker exec -it geneweb backup.sh +``` + +## import database + +```bash +docker exec -it geneweb import.sh +``` diff --git a/bin/backup.sh b/bin/backup.sh new file mode 100644 index 0000000..877d979 --- /dev/null +++ b/bin/backup.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +/opt/gw/gwu /home/geneweb/bases/adrien.gwb -o /home/geneweb/backup/adrien_$(date +%Y%m%d_%H%M%S).gw |tee -a /home/geneweb/backup.log diff --git a/bin/import.sh b/bin/import.sh new file mode 100644 index 0000000..1e5e58d --- /dev/null +++ b/bin/import.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +#/opt/gw/gwc -bd /home/geneweb/bases -f -o adrien -f /home/geneweb/import/adrien.gw |tee -a /home/geneweb/import.log + +/opt/gw/gwc -bd /home/geneweb/bases -f -v -o adrien -ds "TODO" -f /home/geneweb/import/adrien.gw |tee -a /home/geneweb/import.log \ No newline at end of file diff --git a/bin/main.sh b/bin/main.sh new file mode 100644 index 0000000..72b5ef9 --- /dev/null +++ b/bin/main.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +function backup() +{ + backup.sh +} + +function import() +{ + import.sh +} + +function start() +{ + /opt/gw/gwd -lang fr -hd /opt/gw -bd /home/geneweb/bases -p 2317 -log /home/geneweb/geneweb.log +} + +case "$1" in + start) + start + ;; + + backup) + backup + ;; + + import) + import + ;; + + *) + echo $"Usage: $0 {start|backup|import}" + exit 1 + +esac \ No newline at end of file diff --git a/main.sh b/main.sh new file mode 100755 index 0000000..075ec1e --- /dev/null +++ b/main.sh @@ -0,0 +1,173 @@ +#!/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 \ No newline at end of file