### ### Meta Information ### FROM localhost/debian # deploy options # -p (port) and -v (volume) both go host:container ARG EXT_HOME LABEL config_default="\ -p 9080:80 \ -v $EXT_HOME/vol/nextcloud/files:/vol/files \ -v $EXT_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 # autodetect versions of php and postgres and put them in /etc/environment # put database variables in /etc/environment so anyone can access them RUN export PSQLV="$(psql -V | cut -d ' ' -f 3 | cut -d '.' -f 1)" && \ export PHPV="$(echo $(php -r 'echo PHP_VERSION;') | cut -d '.' -f 1-2)" && \ rm -f /vol/data/etc/environment && \ echo "export PSQLV=$PSQLV" >> /vol/data/etc/environment && \ echo "export PHPV=$PHPV" >> /vol/data/etc/environment && \ echo "export DBUSER=$DBUSER" >> /vol/data/etc/environment && \ echo "export DBNAME=$DBNAME" >> /vol/data/etc/environment && \ rm -f /etc/environment && \ ln -s /vol/data/etc/environment /etc/environment # change www-data's UID to the file owner UID ### RUN usermod --uid $FILESUID www-data && \ ### groupmod --gid $FILESUID www-data # make sure volume dirs exist, and copy sample data ### COPY --chown=www-data:www-data data/ /vol/data/ RUN mkdir -p /vol/data /vol/files && \ chown -R www-data:www-data /vol/data && \ chown -R www-data:www-data /var/www # copy our custom scripts COPY assets/bin/ /usr/local/bin/ ### ### PHP ### # copy php configuration COPY assets/php/ php/ # enable PHP interpreter RUN . /vol/data/etc/environment && \ mv php/php.ini /etc/php/${PHPV:?}/fpm/ && \ mv php/www.conf /etc/php/${PHPV:?}/fpm/pool.d/ && \ systemctl enable php${PHPV:?}-fpm && \ 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 . /vol/data/etc/environment && \ 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 . /vol/data/etc/environment && \ 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/ ./ # copy nextcloud config COPY --chown=www-data:www-data assets/config/ nextcloud/config/ ### RUN test -f latest.zip || \ ### wget --progress=dot:giga https://download.nextcloud.com/server/releases/latest.zip WORKDIR /var/www/html RUN echo "Unzipping nextcloud ..." && \ unzip -q $HOME/latest.zip && \ chown -R www-data:www-data nextcloud && \ rm $HOME/latest.zip && \ echo "Creating files dir for nextcloud ..." && \ mkdir -p /vol/files && \ chown -R www-data:www-data /vol/files && \ echo "Making link to host config & secret config ..." && \ cd nextcloud/config && \ ln -s /vol/data/ncconfig/host.config.php && \ ln -s /vol/data/ncconfig/secret.config.php && \ echo "... finished installing nextcloud" ### ### 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 && \ rm -f /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 && \ rm -f /root/cronfix ### ### Workdir ### ### WORKDIR /vol/data