From 3cd4286acedef4b16b4831d8ee24dc5e9be35a70 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Tue, 27 Feb 2018 22:26:42 +0100 Subject: [PATCH] Copy Docker files from roundcubemail repository as suggested in #5827 --- Dockerfile | 49 +++++++++++++++++++++++ README.md | 76 ++++++++++++++++++++++++++++++++++- docker-entrypoint.sh | 94 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100755 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9512ced --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +FROM php:7.1-apache +MAINTAINER Thomas Bruederli + +RUN apt-get -qq update \ + && apt-get install -qq \ + libfreetype6-dev \ + libicu-dev \ + libjpeg62-turbo-dev \ + libldap2-dev \ + libpng-dev \ + libpq-dev \ + libsqlite3-dev \ + zlib1g-dev \ + && rm -rf /var/lib/apt/lists/* +RUN docker-php-ext-install -j$(nproc) exif intl pdo pdo_mysql pdo_pgsql pdo_sqlite zip +RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && docker-php-ext-install -j$(nproc) gd +RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu && docker-php-ext-install -j$(nproc) ldap + +# enable mod_rewrite +RUN a2enmod rewrite + +# expose these volumes +VOLUME /var/roundcube/config +VOLUME /tmp/roundcube-temp + +# Define Roundcubemail version +ENV ROUNDCUBEMAIL_VERSION 1.3.4 + +# Download package and extract to web volume +RUN curl -o roundcubemail.tar.gz -SL https://github.com/roundcube/roundcubemail/releases/download/${ROUNDCUBEMAIL_VERSION}/roundcubemail-${ROUNDCUBEMAIL_VERSION}-complete.tar.gz \ + && curl -o roundcubemail.tar.gz.asc -SL https://github.com/roundcube/roundcubemail/releases/download/${ROUNDCUBEMAIL_VERSION}/roundcubemail-${ROUNDCUBEMAIL_VERSION}-complete.tar.gz.asc \ + && export GNUPGHOME="$(mktemp -d)" \ + && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys F3E4C04BB3DB5D4215C45F7F5AB2BAA141C4F7D5 \ + && gpg --batch --verify roundcubemail.tar.gz.asc roundcubemail.tar.gz \ + && rm -r "$GNUPGHOME" roundcubemail.tar.gz.asc \ + && tar -xzf roundcubemail.tar.gz -C /usr/src/ \ + # upstream tarballs include ./roundcubemail-${ROUNDCUBEMAIL_VERSION}/ so this gives us /usr/src/roundcubemail-${ROUNDCUBEMAIL_VERSION} + && mv /usr/src/roundcubemail-${ROUNDCUBEMAIL_VERSION} /usr/src/roundcubemail \ + && rm -rf /usr/src/roundcubemail/installer \ +&& rm roundcubemail.tar.gz + +# include the wait-for-it.sh script +RUN curl https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh > /wait-for-it.sh && chmod +x /wait-for-it.sh + +COPY docker-entrypoint.sh / + +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["apache2-foreground"] + diff --git a/README.md b/README.md index f643f5a..fbb9edd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,74 @@ -# roundcubemail-docker -Resources to build Docker images for Roundcube Webmail +# Running Roundcube in a Docker Container + +The simplest method is to run the official image: + +``` +docker run -e ROUNDCUBEMAIL_DEFAULT_HOST=mail -d roundcube/roundcubemail +``` + +## Configuration/Environment Variables + +The following env variables can be set to configure your Roundcube Docker instance: + +`ROUNDCUBEMAIL_DEFAULT_HOST` - Hostname of the IMAP server to connect to + +`ROUNDCUBEMAIL_DEFAULT_PORT` - IMAP port number; defaults to `143` + +`ROUNDCUBEMAIL_SMTP_SERVER` - Hostname of the SMTP server to send mails + +`ROUNDCUBEMAIL_SMTP_PORT` - SMTP port number; defaults to `587` + +`ROUNDCUBEMAIL_PLUGINS` - List of built-in plugins to activate. Defaults to `archive,zipdownload` + +`ROUNDCUBEMAIL_UPLOAD_MAX_FILESIZE` - File upload size limit; defaults to `5M` + +By default, the image will use a local SQLite database for storing user account metadata. +It'll be created inside the `/var/www/html` directory and can be backed up from there. Please note that +this option should not be used for production environments. + +### Connect to a MySQL Database + +The recommended way to run Roundcube is connected to a MySQL database. Specify the following env variables to do so: + +`ROUNDCUBEMAIL_DB_TYPE` - Database provider; currently supported: `mysql`, `pgsql`, `sqlite` + +`ROUNDCUBEMAIL_DB_HOST` - Host (or Docker instance) name of the database service; defaults to `mysql` or `postgres` depending on linked containers. + +`ROUNDCUBEMAIL_DB_USER` - The database username for Roundcube; defaults to `root` on `mysql` + +`ROUNDCUBEMAIL_DB_PASSWORD` - The password for the database connection + +`ROUNDCUBEMAIL_DB_NAME` - The database name for Roundcube to use; defaults to `roundcubemail` + +Before starting the container, please make sure that the supplied database exists and the given database user +has privileges to create tables. + +Run it with a link to the MySQL host and the username/password variables: + +``` +docker run --link=mysql:mysql -d roundcube/roundcubemail +``` + +### Advanced configuration + +Apart from the above described environment variables, the Docker image also allows to add custom config files +which are merged into Roundcube's default config. Therefore the image defines a volume `/var/roundcube/config` +where additional config files (`*.php`) are searched and included. Mount a local directory with your config +files - check for valid PHP syntax - when starting the Docker container: + +``` +docker run -v ./config/:/var/roundcube/config/ -d roundcube/roundcubemail +``` + +Check our wiki for a reference of [Roundcube config options](https://github.com/roundcube/roundcubemail/wiki/Configuration). + +## Building a Docker image + +Use the `Dockerfile` in this directory to build your own Docker image. +It pulls the latest build of Roundcube Webmail from the Github download page and builds it on top of a `php:7.1-apache` Docker image. + +Build it from this directory with + +``` +docker build -t roundcubemail . +``` diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..0178820 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,94 @@ +#!/bin/bash +# set -ex + +# PWD=`pwd` + +if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + if ! [ -e index.php -a -e bin/installto.sh ]; then + echo >&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 - + sed -i 's/mod_php5.c/mod_php7.c/' .htaccess + echo >&2 "Complete! ROUNDCUBEMAIL has been successfully copied to $PWD" + 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 + 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`; 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." + fi + + if [ ! -z "${ROUNDCUBEMAIL_UPLOAD_MAX_FILESIZE}" ]; then + sed -i -E "s/(upload_max_filesize|post_max_size) +[0-9BKMG]+/\1 ${ROUNDCUBEMAIL_UPLOAD_MAX_FILESIZE}/g" $PWD/.htaccess + fi +fi + +exec "$@"