FROM ubuntu:18.04 as builder ### SYS RUN export DEBIAN_FRONTEND=noninteractive; \ apt -y update || true; \ apt -y install tzdata; \ ln -fs /usr/share/zoneinfo/America/Denver /etc/localtime; \ dpkg-reconfigure --frontend noninteractive tzdata; \ apt -y install \ curl \ rsync \ cron \ postgresql postgresql-contrib \ && mkdir -p /mnt/save ### APP RUN \ apt install nginx postgresql uwsgi uwsgi-plugin-python3 python3-venv git ### POSTGRES RUN useradd -d /home/postgres -ms /bin/bash -g postgres -G sudo postgres USER postgres RUN service postgresql start && sleep 10 \ && psql --command "CREATE USER ss WITH SUPERUSER PASSWORD 'ss';" \ && createdb -O ss ss \ && psql --command "CREATE DATABASE silverstrikedb;" \ && psql --command "GRANT ALL PRIVILEGES ON DATABASE silverstrikedb TO ss;" USER root ### CRON BACKUPS RUN true \ && echo 'b=$(date +%Y%m%d%H%M%S) && mkdir -p /mnt/save/$b && pg_dump $DATABASE_URL --clean > /mnt/save/$b/pg.dump' > /backup.sh \ && echo 'b=$(find /mnt/save -type f | sort | tail -n 1); if [ -n "$b" ]; then echo restoring $b; psql $DATABASE_URL < "$b"; fi && service postgresql start;' > /restore.sh \ && echo '0 4,8,12,16,20 * * * bash /backup.sh >> /var/log/cronj.log 2>&1' > /etc/cron.d/backups \ && echo '' >> /etc/cron.d/backups \ && chmod 0644 /etc/cron.d/backups \ && touch /var/log/cronj.log ### FINAL ENV DATABASE_URL=postgres://ss:ss@localhost/silverstrikedb?sslmode=disable ENV SECRET_KEY=AimmBfzjdWcVN3rQs8YawbUowv5R8Eex ENV ALLOWED_HOSTS=* ENTRYPOINT \ until psql $DATABASE_URL < /dev/null; do sleep 5; done \ && bash /restore.sh \ && sleep 5 && python manage.py migrate && exec uwsgi