### ### Meta Information ### FROM localhost/debian # deploy options # -p (port) and -v (volume) both go host:container LABEL config_default="\ -p 9080:80 \ -v $HOME/vol/nextcloud/files:/vol/files \ -v $HOME/vol/nextcloud/data:/vol/data \ --shm-size=1g" # Build Variables # uid that the files owner user should have ARG FILESUID=5000 # database name and user ENV DBUSER=ncadmin ENV DBNAME=nextcloud ### ### General Setup ### # install packages we want RUN apt update -y && apt install -y apache2 php-fpm php-gd php-zip php-pgsql \ php-curl php-mbstring php-intl php-imagick php-xml php-gmp php-json \ redis php-redis postgresql postgresql-doc php-ldap php-bcmath cron # put database variables in /etc/environment so anyone can access them # also autodetect versions of php and postgres and put them in /etc/environment as well RUN echo "DBUSER=$DBUSER" >> /etc/environment && \ echo "DBNAME=$DBNAME" >> /etc/environment && \ echo "PSQLV=$(psql -V | cut -d ' ' -f 3 | cut -d '.' -f 1)" >> /etc/environment && \ echo "PHPV=$(echo $(php -r 'echo PHP_VERSION;') | cut -d '.' -f 1-2)" >> /etc/environment # change www-data's UID to the file owner UID RUN usermod --uid $FILESUID www-data && \ groupmod --gid $FILESUID www-data && \ chown -R www-data:www-data /var/www # copy our custom scripts COPY assets/bin/ /usr/local/bin/ # make sure volume dirs exist, and copy sample data RUN mkdir -p /vol/data /vol/files COPY --chown=www-data:www-data data/ /vol/data/ ### ### PHP ### # enable PHP interpreter RUN systemctl enable php${PHPV:?}-fpm # copy php configuration COPY assets/php/ php/ RUN mv php/php.ini /etc/php/${PHPV:?}/fpm/ && \ mv php/www.conf /etc/php/${PHPV:?}/fpm/pool.d/ && \ rmdir php ### ### PostgreSQL ### ### # configure PostgreSQL COPY --chown=postgres:postgres assets/postgresql/ postgresql/ # If the posgresql.conf file contains multiple entries for the same parameter, all but the last one is ignored. # So we can just append our settings to the already-existing postgresql.conf file. RUN mv postgresql/pg_hba.conf /etc/postgresql/${PSQLV:?}/main/ && \ cat postgresql/postgresql.conf >> /etc/postgresql/${PSQLV:?}/main/postgresql.conf && \ rm -rf postgresql ### ### Apache ### # enable modules we need RUN a2enmod rewrite headers env dir mime proxy_fcgi && \ a2enconf php${PHPV:?}-fpm # copy site config COPY assets/apache/nextcloud.conf /etc/apache2/sites-available/ RUN a2dissite 000-default && a2ensite nextcloud ### ### Redis ### # copy redis config COPY --chown=redis:redis assets/redis.conf /etc/redis/redis.conf # add www-data to redis group so it can use the socket RUN usermod -a -G redis www-data ### ### Nextcloud ### # download nextcloud COPY assets/nextcloud/ ./ RUN test -f latest.zip || \ wget --progress=dot:giga https://download.nextcloud.com/server/releases/latest.zip WORKDIR /var/www/html RUN echo "Unzipping ..." && \ unzip -q $HOME/latest.zip && \ chown -R www-data:www-data nextcloud && \ rm $HOME/latest.zip # create data dir for nextcloud RUN mkdir -p /vol/files && \ chown -R www-data:www-data /vol/files # copy nextcloud config COPY --chown=www-data:www-data assets/config/ nextcloud/config/ # make link to host config & secret config RUN cd nextcloud/config && \ ln -s /vol/data/host.config.php && \ ln -s /vol/data/secret.config.php ### ### DB Auto Load/Dump ### # copy service COPY assets/db-updown.service /etc/systemd/system/ # enable service RUN systemctl enable db-updown.service ### ### Crontab ### COPY assets/crontab /root/ # crontab for www-data RUN crontab -u www-data /root/crontab ### ### Bugfix ### # push the fixed systemd file for redis COPY assets/bugfix/redis-server.service /etc/systemd/system/redis-server.service COPY assets/bugfix/apache2.override /etc/systemd/system/apache2.service.d/override.conf # bugfix for cron COPY assets/bugfix/cronfix /root/ RUN chmod +x /root/cronfix && /root/cronfix ### ### Workdir ### WORKDIR /vol/data