From a62fa88008bf35cbe5b6b980719085dd1959e1a8 Mon Sep 17 00:00:00 2001 From: Torben Nehmer Date: Thu, 25 Oct 2018 22:10:01 +0200 Subject: [PATCH] First working version of the ispconfig roundcube - Completly rebuild the container startup to be less brute-forcish - All relevant configs now lie in the external volume - DB init is only done if a new config is written. - ENV Vars are only needed if you want to automatically write a config - Cleaned up everything --- Dockerfile | 9 +-- src/db.inc.php | 6 +- src/docker-entrypoint.sh | 117 +++++++++--------------------------- src/scripts/write-config.sh | 28 ++++++--- 4 files changed, 54 insertions(+), 106 deletions(-) diff --git a/Dockerfile b/Dockerfile index a97a56f..41d8c63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -54,13 +54,14 @@ RUN set -ex; \ # expose these volumes VOLUME /var/roundcube/config -VOLUME /tmp/roundcube-temp # Define Roundcubemail version ENV ROUNDCUBEMAIL_VERSION 1.3.7 -# Publish the rootfs file into the container -ADD rootfs.tar.gz / - +# Set the entry point ENTRYPOINT ["/docker-entrypoint.sh"] CMD ["apache2-foreground"] + +# Finally, publish the rootfs file into the container +# This is done as last step to make docker build caching more efficient. +ADD rootfs.tar.gz / diff --git a/src/db.inc.php b/src/db.inc.php index dbf0e65..8933756 100644 --- a/src/db.inc.php +++ b/src/db.inc.php @@ -1,13 +1,15 @@ &2 "roundcubemail not found in $PWD - copying now..." - if [ "$(ls -A)" ]; then - echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" - ( set -x; ls -A; sleep 10 ) - fi - tar cf - --one-file-system -C /usr/src/roundcubemail . | tar xf - - echo >&2 "Complete! ROUNDCUBEMAIL has been successfully copied to $PWD" + # Wait for DB Server + if [ "$ROUNDCUBEMAIL_DB_TYPE" == "pgsql" ]; then + /usr/local/sbin/wait-for-it.sh ${ROUNDCUBEMAIL_DB_HOST}:${ROUNDCUBEMAIL_DB_PORT:-5432} -t 30 + elif [ "$ROUNDCUBEMAIL_DB_TYPE" == "mysql" ]; then + /usr/local/sbin/wait-for-it.sh ${ROUNDCUBEMAIL_DB_HOST}:${ROUNDCUBEMAIL_DB_PORT:-3306} -t 30 fi - if [ ! -z "${!POSTGRES_ENV_POSTGRES_*}" ] || [ "$ROUNDCUBEMAIL_DB_TYPE" == "pgsql" ]; then - : "${ROUNDCUBEMAIL_DB_TYPE:=pgsql}" - : "${ROUNDCUBEMAIL_DB_HOST:=postgres}" - : "${ROUNDCUBEMAIL_DB_USER:=${POSTGRES_ENV_POSTGRES_USER}}" - : "${ROUNDCUBEMAIL_DB_PASSWORD:=${POSTGRES_ENV_POSTGRES_PASSWORD}}" - : "${ROUNDCUBEMAIL_DB_NAME:=${POSTGRES_ENV_POSTGRES_DB:-roundcubemail}}" - : "${ROUNDCUBEMAIL_DSNW:=${ROUNDCUBEMAIL_DB_TYPE}://${ROUNDCUBEMAIL_DB_USER}:${ROUNDCUBEMAIL_DB_PASSWORD}@${ROUNDCUBEMAIL_DB_HOST}/${ROUNDCUBEMAIL_DB_NAME}}" - - /wait-for-it.sh ${ROUNDCUBEMAIL_DB_HOST}:5432 -t 30 - elif [ ! -z "${!MYSQL_ENV_MYSQL_*}" ] || [ "$ROUNDCUBEMAIL_DB_TYPE" == "mysql" ]; then - : "${ROUNDCUBEMAIL_DB_TYPE:=mysql}" - : "${ROUNDCUBEMAIL_DB_HOST:=mysql}" - : "${ROUNDCUBEMAIL_DB_USER:=${MYSQL_ENV_MYSQL_USER:-root}}" - if [ "$ROUNDCUBEMAIL_DB_USER" = 'root' ]; then - : "${ROUNDCUBEMAIL_DB_PASSWORD:=${MYSQL_ENV_MYSQL_ROOT_PASSWORD}}" - else - : "${ROUNDCUBEMAIL_DB_PASSWORD:=${MYSQL_ENV_MYSQL_PASSWORD}}" - fi - : "${ROUNDCUBEMAIL_DB_NAME:=${MYSQL_ENV_MYSQL_DATABASE:-roundcubemail}}" - : "${ROUNDCUBEMAIL_DSNW:=${ROUNDCUBEMAIL_DB_TYPE}://${ROUNDCUBEMAIL_DB_USER}:${ROUNDCUBEMAIL_DB_PASSWORD}@${ROUNDCUBEMAIL_DB_HOST}/${ROUNDCUBEMAIL_DB_NAME}}" - - /wait-for-it.sh ${ROUNDCUBEMAIL_DB_HOST}:3306 -t 30 - else - # use local SQLite DB in /var/www/html/db - : "${ROUNDCUBEMAIL_DB_TYPE:=sqlite}" - : "${ROUNDCUBEMAIL_DB_DIR:=$PWD/db}" - : "${ROUNDCUBEMAIL_DB_NAME:=sqlite}" - : "${ROUNDCUBEMAIL_DSNW:=${ROUNDCUBEMAIL_DB_TYPE}:///$ROUNDCUBEMAIL_DB_DIR/${ROUNDCUBEMAIL_DB_NAME}.db?mode=0646}" - - mkdir -p $ROUNDCUBEMAIL_DB_DIR - chown www-data:www-data $ROUNDCUBEMAIL_DB_DIR - fi - - : "${ROUNDCUBEMAIL_DEFAULT_HOST:=localhost}" - : "${ROUNDCUBEMAIL_DEFAULT_PORT:=143}" - : "${ROUNDCUBEMAIL_SMTP_SERVER:=localhost}" - : "${ROUNDCUBEMAIL_SMTP_PORT:=587}" - : "${ROUNDCUBEMAIL_PLUGINS:=archive,zipdownload}" - : "${ROUNDCUBEMAIL_TEMP_DIR:=/tmp/roundcube-temp}" - - if [ ! -e config/config.inc.php ]; then - - #### TODO SUPERSEEDED BY write-config.sh - - ROUNDCUBEMAIL_PLUGINS_PHP=`echo "${ROUNDCUBEMAIL_PLUGINS}" | sed -E "s/[, ]+/', '/g"` - mkdir -p ${ROUNDCUBEMAIL_TEMP_DIR} && chown www-data ${ROUNDCUBEMAIL_TEMP_DIR} - touch config/config.inc.php - - echo "Write config to $PWD/config/config.inc.php" - echo " config/config.inc.php - - for fn in `ls /var/roundcube/config/*.php 2>/dev/null || true`; do - echo "include('$fn');" >> config/config.inc.php - done - - # initialize DB if not SQLite - echo "${ROUNDCUBEMAIL_DSNW}" | grep -q 'sqlite:' || bin/initdb.sh --dir=$PWD/SQL || bin/updatedb.sh --dir=$PWD/SQL --package=roundcube || echo "Failed to initialize databse. Please run $PWD/bin/initdb.sh manually." - else - echo "WARNING: $PWD/config/config.inc.php already exists." - echo "ROUNDCUBEMAIL_* environment variables have been ignored." + # Create configuration if required, then init the database. + if [ ! -e /var/roundcube/config/config.inc.php ]; then + /usr/local/sbin/write-config.sh + /var/www/html/bin/initdb.sh --dir=/var/www/html/SQL \ + || echo "initdb.sh failed to execute, please bash into the container and run it manually." fi + /var/www/html/bin/updatedb.sh --dir=/var/www/html/SQL --package=roundcube \ + || echo "updatedb.sh failed to execute, please bash into the container and run it manually." + # Add Filesize limits to PHP config if [ ! -z "${ROUNDCUBEMAIL_UPLOAD_MAX_FILESIZE}" ]; then - echo "upload_max_filesize=${ROUNDCUBEMAIL_UPLOAD_MAX_FILESIZE}" >> /usr/local/etc/php/conf.d/roundcube-override.ini - echo "post_max_size=${ROUNDCUBEMAIL_UPLOAD_MAX_FILESIZE}" >> /usr/local/etc/php/conf.d/roundcube-override.ini + echo "upload_max_filesize=${ROUNDCUBEMAIL_UPLOAD_MAX_FILESIZE}" > /usr/local/etc/php/conf.d/roundcube-filesize.ini + echo "post_max_size=${ROUNDCUBEMAIL_UPLOAD_MAX_FILESIZE}" >> /usr/local/etc/php/conf.d/roundcube-filesize.ini fi + + # Move Dist config files into the volume + cp /var/www/html/config/defaults.inc.php /var/roundcube/config/defaults.inc.php.sample + cp /var/www/html/config/config.inc.php.sample /var/roundcube/config/ + cp /var/www/html/plugins/ispconfig3_account/config/config.inc.php.dist /var/roundcube/config/ispconfig3_account.inc.php.sample fi -exec "$@" +if [ "$1" == "testmode" ]; then + exec /bin/bash +else + exec "$@" +fi diff --git a/src/scripts/write-config.sh b/src/scripts/write-config.sh index f3a91ef..9e07ab8 100755 --- a/src/scripts/write-config.sh +++ b/src/scripts/write-config.sh @@ -1,27 +1,35 @@ #!/bin/bash -# set -ex +set -ex -CONFIG=/var/roundcube/config/config.inc.php +DB_CONFIG_FILE=/var/roundcube/config/db.inc.php +MAIN_CONFIG=/var/roundcube/config/config.inc.php + +echo "Writing ${DB_CONFIG_FILE}..." +echo " +" > ${DB_CONFIG_FILE} ROUNDCUBEMAIL_PLUGINS_PHP=`echo "${ROUNDCUBEMAIL_PLUGINS}" | sed -E "s/[, ]+/', '/g"` -mkdir -p ${ROUNDCUBEMAIL_TEMP_DIR} && chown www-data ${ROUNDCUBEMAIL_TEMP_DIR} -touch $CONFIG echo "Write config to $PWD/config/config.inc.php" echo " $CONFIG - - +?> +" > $MAIN_CONFIG