From 4b4c4633bca167a71594d66612a26eaba193c572 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Sun, 19 Nov 2017 21:55:05 +0100 Subject: [PATCH] Refactored Dockerfile as suggested in #5874 It's now based on a php:7.1-apache image and pre-configures Roundcube from the given environment variables to either connect to a MySQL server or to use a local SQLite database. Added a README file with some basic information and description of the most important denv variables. More configuration options are yet to come. This is a pre-requisite for #5827. --- Dockerfile | 36 ------------------ docker/Dockerfile | 42 +++++++++++++++++++++ docker/README.md | 59 ++++++++++++++++++++++++++++++ docker/docker-entrypoint.sh | 73 +++++++++++++++++++++++++++++++++++++ 4 files changed, 174 insertions(+), 36 deletions(-) delete mode 100644 Dockerfile create mode 100644 docker/Dockerfile create mode 100644 docker/README.md create mode 100755 docker/docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 3060cdf48..000000000 --- a/Dockerfile +++ /dev/null @@ -1,36 +0,0 @@ -FROM debian:jessie -MAINTAINER Alex Brandt - -EXPOSE 80 443 - -RUN apt-get -qq update -RUN apt-get install -qq apache2-mpm-event ca-certificates - -RUN apt-get install -qq php5 php-pear php5-mysql php5-pgsql php5-sqlite -RUN pear install mail_mime net_smtp net_idna2-beta auth_sasl net_sieve crypt_gpg - -RUN a2enmod expires -RUN a2enmod headers -RUN a2enmod ssl - -RUN sed -e 's|/var/www/html|/var/www/public_html|' -e 's@\(Log \+\)[^ ]\+@\1"|/bin/cat"@' -i /etc/apache2/sites-available/000-default.conf -RUN sed -e 's||\t\n\t\tAllowOverride All\n\t\n&|' -i /etc/apache2/sites-available/000-default.conf -RUN a2ensite 000-default - -RUN sed -e 's|/var/www/html|/var/www/public_html|' -e 's@\(Log \+\)[^ ]\+@\1"|/bin/cat"@' -i /etc/apache2/sites-available/default-ssl.conf -RUN sed -e 's||\t\n\t\tAllowOverride All\n\t\n&|' -i /etc/apache2/sites-available/default-ssl.conf -RUN sed -e '/SSLCertificateKeyFile/s|ssl-cert-snakeoil.key|ssl-cert.key|' -e '/SSLCertificateFile/s|ssl-cert-snakeoil.pem|ssl-cert.pem|' -i /etc/apache2/sites-available/default-ssl.conf -RUN ln -snf ssl-cert-snakeoil.pem /etc/ssl/certs/ssl-cert.pem -RUN ln -snf ssl-cert-snakeoil.key /etc/ssl/private/ssl-cert.key -RUN a2ensite default-ssl - -RUN rm -rf /var/www -ADD . /var/www - -RUN echo ' /var/www/config/config.inc.php -RUN rm -rf /var/www/installer - -RUN . /etc/apache2/envvars && chown -R ${APACHE_RUN_USER}:${APACHE_RUN_GROUP} /var/www/temp /var/www/logs - -ENTRYPOINT [ "/usr/sbin/apache2ctl", "-D", "FOREGROUND" ] -CMD [ "-k", "start" ] diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 000000000..4b0e1a4e1 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,42 @@ +FROM php:7.1-apache +MAINTAINER Thomas Bruederli + +RUN apt-get -qq update \ + && apt-get install -qq \ + libpq-dev \ + libsqlite3-dev \ + libicu-dev \ + zlib1g-dev \ + libpng-dev \ + libfreetype6-dev \ + libjpeg62-turbo-dev \ + && rm -rf /var/lib/apt/lists/* +RUN docker-php-ext-install -j$(nproc) intl exif pdo pdo_mysql pdo_sqlite pdo_pgsql zip +RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && docker-php-ext-install -j$(nproc) gd + +# enable mod_rewrite +RUN a2enmod rewrite + +VOLUME /var/www/html + +# Define Roundcubemail version +ENV ROUNDCUBEMAIL_VERSION 1.3.2 + +# 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 + +COPY docker-entrypoint.sh / + +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["apache2-foreground"] + diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 000000000..22b58970e --- /dev/null +++ b/docker/README.md @@ -0,0 +1,59 @@ +# 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` + +By default, the image will use a local SQLite database for storing user account metadata. +It'll be created inside the `/var/www/html` volume and can be backed up from there. Please note that +this option should not be used for production. + +### 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: + +`MYSQL_ENV_MYSQL_HOST` - Host (or Docker instance) name of the MySQL service; defaults to `mysql` + +`MYSQL_ENV_MYSQL_USER` - The database username for Roundcube; defaults to `root` + +`MYSQL_ENV_MYSQL_PASSWORD` - The password for the database connection or +`MYSQL_ENV_MYSQL_ROOT_PASSWORD` - if the database username is `root` + +`MYSQL_ENV_MYSQL_DATABASE` - The database name for Roundcube to use; defaults to `roundcubemail` + +Before staring 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 -e MYSQL_ENV_MYSQL_ROOT_PASSWORD=my-secret-password --link=mysql:mysql -d roundcube/roundcubemail +``` + +## Building a Docker Container + +Use the `Dockerfile` in this directory to build you 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/docker-entrypoint.sh b/docker/docker-entrypoint.sh new file mode 100755 index 000000000..8b57b618b --- /dev/null +++ b/docker/docker-entrypoint.sh @@ -0,0 +1,73 @@ +#!/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 "${!MYSQL_ENV_MYSQL_*}" ]; then + : "${ROUNDCUBEMAIL_DB_TYPE:=mysql}" + : "${ROUNDCUBEMAIL_DB_HOST:=${MYSQL_ENV_MYSQL_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}}" + else + # use local SQLite DB in /var/www/html/db + : "${ROUNDCUBEMAIL_DB_DIR:=$PWD/db}" + : "${ROUNDCUBEMAIL_DSNW:=sqlite:///$ROUNDCUBEMAIL_DB_DIR/sqlite.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}" + : "${ROUNDCUBEMAIL_LOG_DIR:=/var/log/roundcubemail}" + + if [ ! -e config/config.inc.php ]; then + ROUNDCUBEMAIL_PLUGINS_PHP=`echo "${ROUNDCUBEMAIL_PLUGINS}" | sed -E "s/[, ]+/', '/"` + mkdir -p ${ROUNDCUBEMAIL_TEMP_DIR} && chown www-data ${ROUNDCUBEMAIL_TEMP_DIR} + mkdir -p ${ROUNDCUBEMAIL_LOG_DIR} && chown www-data ${ROUNDCUBEMAIL_LOG_DIR} + touch config/config.inc.php + + echo "Write config to $PWD/config/config.inc.php" + echo "" | tee config/config.inc.php + + # 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 + else + echo "WARNING: $PWD/config/config.inc.php already exists." + echo "ROUNDCUBEMAIL_* environment variables have been ignored." + fi +fi + +exec "$@" \ No newline at end of file