FROM ubuntu:18.10 ### APT RUN apt -y update \ && DEBIAN_FRONTEND=noninteractive apt -y install tzdata \ && apt -y install locales language-pack-en-base \ && echo '127.0.0.1 firefly-iii-domain.com firefly-iii localhost' >> /etc/hosts \ && apt -y install \ mariadb-server \ nginx \ php-fpm php7.2-mysql php-curl php-gd php-bcmath php-zip php-intl php-mbstring php-xml \ curl \ gcc \ cron \ && rm /etc/nginx/sites-enabled/default \ && touch /etc/nginx/sites-available/firefly-iii.conf \ && ln -s /etc/nginx/sites-available/firefly-iii.conf /etc/nginx/sites-enabled/firefly-iii.conf \ && openssl dhparam 2048 > /etc/nginx/dhparam.pem \ && service mysql start && sleep 5 \ && echo 'FLUSH PRIVILEGES; ' \ 'USE mysql; ' \ 'UPDATE user SET authentication_string=PASSWORD("pwd") WHERE User='"'"'root'"'"'; ' \ 'UPDATE user SET plugin="mysql_native_password" WHERE User='"'"'root'"'"'; ' \ | mysql --user=root mysql || true && echo made user \ && service mysql stop && sleep 5 \ && sed 's/^password .*/password = pwd/' /etc/mysql/debian.cnf > /tmp/cnf \ && mv /tmp/cnf /etc/mysql/debian.cnf \ && service mysql start && sleep 5 \ && echo 'create database fireflyiii character set utf8 collate utf8_bin; ' \ 'grant all privileges on fireflyiii.* to fireflyiii@localhost identified by '"'"'pwd'"'"'; ' \ | mysql --user=root --password=pwd mysql && echo made fireflyiii ### PHP RUN service mysql start && sleep 10 \ && curl -sS https://getcomposer.org/installer \ | php -- --install-dir=/usr/local/bin --filename=composer \ && cd /opt \ && composer create-project grumpydictator/firefly-iii --no-dev --prefer-dist firefly-iii 4.7.4 COPY ./env /opt/firefly-iii/.env RUN service mysql start && sleep 10 \ && cd /opt/firefly-iii \ && php artisan migrate:refresh --seed \ && php artisan passport:install \ && chown -R www-data:www-data /opt/firefly-iii \ && mkdir -p /run/php ### WAIT COPY ./pause /xfer/ RUN cd /xfer && gcc main.c -o /xfer/pauser ### CONFIG COPY ./env /opt/firefly-iii/.env COPY ./firefly-iii.conf /etc/nginx/sites-enabled/ RUN apt -y autoremove \ && apt -y purge --auto-remove gcc curl \ && rm -rf /var/lib/apt \ && apt clean ### CRON RUN echo \ 'lastback="$(find /mnt/back/ -maxdepth 1 -mindepth 1 | sort | tail -n 1)"; ' \ 'mkdir -p $lastback/inc; ' \ 'thisback="$lastback/inc/$(date -u +%Y%m%d%H%M)/"; ' \ 'rm -rf $thisback; ' \ 'mariabackup --backup --target-dir="$thisback" --user root --password=pwd --incremental-basedir $lastback/full; ' \ > /backup-inc.sh \ && echo \ 'set -e; ' \ 'service mysql start; ' \ 'thisback="/mnt/back/$(date -u +%Y%m%d)"/full; ' \ 'mkdir -p $thisback; ' \ 'rm -rf "$(dirname "$thisback")"; ' \ 'mkdir -p "$(dirname "$thisback")"; ' \ 'mariabackup --backup --target-dir="$thisback" --user=root --password=pwd; ' \ > /backup.sh \ && echo \ 'set -e; ' \ 'rm -rf /var/lib/mysql-old; ' \ 'mkdir -p /mnt/back; ' \ 'lastback="$(find /mnt/back/ -maxdepth 1 -mindepth 1 | sort | tail -n 1)"; ' \ 'if [ -z "$lastback" ]; then exit 0; fi; ' \ 'service mysql stop || true; ' \ 'restoring=/tmp/restoring; ' \ 'cp -r "${lastback}/full" "$restoring"; ' \ 'mariabackup --prepare --target-dir="$restoring" --user=root --password=pwd --apply-log-only || true; ' \ 'inc_back="$(find $lastback/inc/ -maxdepth 1 -mindepth 1 | sort | tail -n 1)"; ' \ 'echo --- inc restore $inc_back ---; ' \ 'mariabackup --prepare --target-dir="$restoring" --user=root --password=pwd --incremental-dir "$inc_back" --apply-log-only || true; ' \ 'mv /var/lib/mysql /var/lib/mysql-old; ' \ 'mariabackup --copy-back --target-dir="$restoring" --user=root --password=pwd; ' \ 'rm -rf "$restoring"; ' \ 'chown -R mysql:mysql /var/lib/mysql; ' \ 'service mysql start; ' \ > /restore.sh \ && echo '0 * * * * bash /backup-inc.sh >> /var/log/cronj.log 2>&1' > /etc/cron.d/backups \ && echo '' >> /etc/cron.d/backups \ && chmod 0644 /etc/cron.d/backups \ && crontab /etc/cron.d/backups \ && touch /var/log/cronj.log ### on enter/exit, rsync to/from /var/lib/mysql and /mnt ENTRYPOINT true \ && bash /restore.sh \ && bash /backup.sh \ && for s in mysql nginx php7.2-fpm cron; do service $s restart ; done && sleep 10 \ && exec /xfer/pauser