From: Thomas Bruederli Date: Tue, 11 May 2021 18:56:15 +0000 (+0200) Subject: Add multi-stage Dockerfile for creating nightly builds (#132) X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=029c841103a6dacd93a267eb79c49d006387b614;p=roundcube-roundcubemail-docker.git Add multi-stage Dockerfile for creating nightly builds (#132) --- diff --git a/nightly/Dockerfile b/nightly/Dockerfile new file mode 100644 index 0000000..a54c09f --- /dev/null +++ b/nightly/Dockerfile @@ -0,0 +1,133 @@ +FROM php:7.4-apache AS base +LABEL maintainer="Thomas Bruederli " + +RUN set -ex; \ + apt-get update; \ + \ + savedAptMark="$(apt-mark showmanual)"; \ + \ + apt-get install -y --no-install-recommends \ + libfreetype6-dev \ + libicu-dev \ + libjpeg62-turbo-dev \ + libldap2-dev \ + libmagickwand-dev \ + libpng-dev \ + libpq-dev \ + libsqlite3-dev \ + libzip-dev \ + ; \ + \ + debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)"; \ + docker-php-ext-configure gd; \ + docker-php-ext-configure ldap --with-libdir="lib/$debMultiarch"; \ + docker-php-ext-install \ + exif \ + gd \ + intl \ + ldap \ + pdo_mysql \ + pdo_pgsql \ + pdo_sqlite \ + zip \ + ; \ + pecl install imagick; \ + docker-php-ext-enable imagick; \ + \ +# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies + apt-mark auto '.*' > /dev/null; \ + apt-mark manual $savedAptMark; \ + ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \ + | awk '/=>/ { print $3 }' \ + | sort -u \ + | xargs -r dpkg-query -S \ + | cut -d: -f1 \ + | sort -u \ + | xargs -rt apt-mark manual; \ + \ + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ + rm -rf /var/lib/apt/lists/* + +# installto.sh dependencies +RUN set -ex; \ + \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + rsync \ + ; \ + rm -rf /var/lib/apt/lists/* + +# ... and composer.phar +ADD https://getcomposer.org/installer /tmp/composer-installer.php + +RUN php /tmp/composer-installer.php --install-dir=/usr/local/bin/; \ + rm /tmp/composer-installer.php + +RUN a2enmod rewrite + +### Temporary build image +FROM base AS builder + +# install nodejs and lessc compiler +RUN apt-get -qq update; \ + apt-get install -y --no-install-recommends rsync unzip gnupg dirmngr; \ + curl -sL https://deb.nodesource.com/setup_14.x | bash -; \ + apt-get install -y nodejs; \ + npm install -g less; \ + npm install -g uglify-js; \ + npm install -g lessc; \ + npm install -g less-plugin-clean-css; \ + npm install -g csso-cli + +# Download source and build package into src directory +RUN set -ex; \ + curl -o roundcubemail.tar.gz -SL https://github.com/roundcube/roundcubemail/archive/master.tar.gz; \ + tar -xzf roundcubemail.tar.gz -C /usr/src/; \ + rm roundcubemail.tar.gz; \ + mv /usr/src/roundcubemail-master /usr/src/roundcubemail; \ + cd /usr/src/roundcubemail; \ + rm -rf installer tests public_html .ci .github .gitignore .editorconfig .tx .travis.yml; \ + (cd /usr/src/roundcubemail/skins/elastic; \ + lessc --clean-css="--s1 --advanced" styles/styles.less > styles/styles.min.css; \ + lessc --clean-css="--s1 --advanced" styles/print.less > styles/print.css; \ + lessc --clean-css="--s1 --advanced" styles/embed.less > styles/embed.css); \ + mv composer.json-dist composer.json; \ + composer.phar require kolab/net_ldap3 --no-install; \ + composer.phar require bjeavons/zxcvbn-php --no-install; \ + composer.phar install --no-dev --prefer-dist; \ + bin/install-jsdeps.sh; \ + bin/updatecss.sh; \ + rm -rf vendor/masterminds/html5/test \ + vendor/pear/*/tests vendor/*/*/.git* \ + vendor/pear/crypt_gpg/tools \ + vendor/pear/console_commandline/docs \ + vendor/pear/mail_mime/scripts \ + vendor/pear/net_ldap2/doc \ + vendor/pear/net_smtp/docs \ + vendor/pear/net_smtp/examples \ + vendor/pear/net_smtp/README.rst \ + vendor/endroid/qrcode/tests \ + temp/js_cache + +### Final image +FROM base + +RUN mkdir -p /usr/src +COPY --from=builder /usr/src/roundcubemail /usr/src/roundcubemail + +# expose these volumes +VOLUME /var/roundcube/config +VOLUME /var/roundcube/db +VOLUME /var/www/html +VOLUME /tmp/roundcube-temp + +# include the wait-for-it.sh script +RUN curl -fL https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh > /wait-for-it.sh && chmod +x /wait-for-it.sh + +# use custom PHP settings +COPY php.ini /usr/local/etc/php/conf.d/roundcube-defaults.ini + +COPY docker-entrypoint.sh / + +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["apache2-foreground"] diff --git a/nightly/README.md b/nightly/README.md new file mode 100644 index 0000000..db898ef --- /dev/null +++ b/nightly/README.md @@ -0,0 +1,10 @@ +# Roundcube Dockerfile for Nightly Builds + +The `Dockerfile` in this directory can be used to create nightly builds of Roundcube Webmail from Git master. +It's not recommended to use these builds for productive environments. + +Build from this directory with + +``` +docker build -t roundcubemail:nightly-`date +%Y%m%d` . +``` diff --git a/nightly/docker-entrypoint.sh b/nightly/docker-entrypoint.sh new file mode 100755 index 0000000..89fa670 --- /dev/null +++ b/nightly/docker-entrypoint.sh @@ -0,0 +1,136 @@ +#!/bin/bash +# set -ex + +# PWD=`pwd` + +if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then + # docroot is empty + 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 - + echo >&2 "Complete! ROUNDCUBEMAIL has been successfully copied to $PWD" + # update Roundcube in docroot + else + INSTALLDIR=`pwd` + echo >&2 "roundcubemail found in $INSTALLDIR - installing update..." + (cd /usr/src/roundcubemail && bin/installto.sh -y $INSTALLDIR) + composer.phar update --no-dev + fi + + if [ -f /run/secrets/roundcube_db_user ]; then + ROUNDCUBEMAIL_DB_USER=`cat /run/secrets/roundcube_db_user` + fi + if [ -f /run/secrets/roundcube_db_password ]; then + ROUNDCUBEMAIL_DB_PASSWORD=`cat /run/secrets/roundcube_db_password` + fi + + if [ ! -z "${!POSTGRES_ENV_POSTGRES_*}" ] || [ "$ROUNDCUBEMAIL_DB_TYPE" == "pgsql" ]; then + : "${ROUNDCUBEMAIL_DB_TYPE:=pgsql}" + : "${ROUNDCUBEMAIL_DB_HOST:=postgres}" + : "${ROUNDCUBEMAIL_DB_PORT:=5432}" + : "${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_PORT}/${ROUNDCUBEMAIL_DB_NAME}}" + + /wait-for-it.sh ${ROUNDCUBEMAIL_DB_HOST}:${ROUNDCUBEMAIL_DB_PORT} -t 30 + elif [ ! -z "${!MYSQL_ENV_MYSQL_*}" ] || [ "$ROUNDCUBEMAIL_DB_TYPE" == "mysql" ]; then + : "${ROUNDCUBEMAIL_DB_TYPE:=mysql}" + : "${ROUNDCUBEMAIL_DB_HOST:=mysql}" + : "${ROUNDCUBEMAIL_DB_PORT:=3306}" + : "${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_PORT}/${ROUNDCUBEMAIL_DB_NAME}}" + + /wait-for-it.sh ${ROUNDCUBEMAIL_DB_HOST}:${ROUNDCUBEMAIL_DB_PORT} -t 30 + else + # use local SQLite DB in /var/roundcube/db + : "${ROUNDCUBEMAIL_DB_TYPE:=sqlite}" + : "${ROUNDCUBEMAIL_DB_DIR:=/var/roundcube/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_SKIN:=elastic}" + : "${ROUNDCUBEMAIL_TEMP_DIR:=/tmp/roundcube-temp}" + + if [ ! -e config/config.inc.php ]; then + GENERATED_DES_KEY=`head /dev/urandom | base64 | head -c 24` + touch config/config.inc.php + + echo "Write root config to $PWD/config/config.inc.php" + echo " config/config.inc.php + + elif ! grep -q "config.docker.inc.php" config/config.inc.php; then + echo "include(__DIR__ . '/config.docker.inc.php');" >> config/config.inc.php + fi + + ROUNDCUBEMAIL_PLUGINS_PHP=`echo "${ROUNDCUBEMAIL_PLUGINS}" | sed -E "s/[, ]+/', '/g"` + echo "Write Docker config to $PWD/config/config.docker.inc.php" + echo " config/config.docker.inc.php + + if [ -e /run/secrets/roundcube_des_key ]; then + echo "\$config['des_key'] = file_get_contents('/run/secrets/roundcube_des_key');" >> config/config.docker.inc.php + elif [ ! -z "${ROUNDCUBEMAIL_DES_KEY}" ]; then + echo "\$config['des_key'] = getenv('ROUNDCUBEMAIL_DES_KEY');" >> config/config.docker.inc.php + fi + + # include custom config files + for fn in `ls /var/roundcube/config/*.php 2>/dev/null || true`; do + echo "include('$fn');" >> config/config.docker.inc.php + done + + # initialize or update DB + bin/initdb.sh --dir=$PWD/SQL --create || bin/updatedb.sh --dir=$PWD/SQL --package=roundcube || echo "Failed to initialize database. Please run $PWD/bin/initdb.sh and $PWD/bin/updatedb.sh manually." + + if [ ! -z "${ROUNDCUBEMAIL_TEMP_DIR}" ]; then + mkdir -p ${ROUNDCUBEMAIL_TEMP_DIR} && chown www-data ${ROUNDCUBEMAIL_TEMP_DIR} + fi + + 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 + fi + + : "${ROUNDCUBEMAIL_LOCALE:=en_US.UTF-8 UTF-8}" + + if [ -e /usr/sbin/locale-gen ] && [ ! -z "${ROUNDCUBEMAIL_LOCALE}" ]; then + echo "${ROUNDCUBEMAIL_LOCALE}" > /etc/locale.gen + /usr/sbin/locale-gen + fi +fi + +exec "$@" diff --git a/nightly/php.ini b/nightly/php.ini new file mode 100644 index 0000000..7b2147d --- /dev/null +++ b/nightly/php.ini @@ -0,0 +1,10 @@ +memory_limit=64M +display_errors=Off +log_errors=On +upload_max_filesize=5M +post_max_size=6M +zlib.output_compression=Off +session.auto_start=Off +session.gc_maxlifetime=21600 +session.gc_divisor=500 +session.gc_probability=1