Dockerfile 1.1 KB

1234567891011121314151617181920
  1. FROM postgres:13.0
  2. # crontab
  3. RUN mkdir /backups
  4. COPY ./backup.sh /usr/local/bin/bookwyrm-backup.sh
  5. COPY ./weed.sh /usr/local/bin/bookwyrm-weed.sh
  6. COPY ./cronfile /etc/cron.d/cronfile
  7. RUN apt-get update && apt-get -y --no-install-recommends install cron
  8. RUN chmod 0644 /etc/cron.d/cronfile
  9. RUN crontab /etc/cron.d/cronfile
  10. RUN touch /var/log/cron.log
  11. # The postgres image's entrypoint expects the docker command to only contain flags to
  12. # pass postgres. It runs the entrypoint twice, the second times as the postgres user.
  13. # We need to start the cron service the first time it runs, when it's still being run
  14. # as the root user. We're going to add a check that looks at the first argument and
  15. # if it's 'cron', starts the service and then removes that argument.
  16. RUN awk '$0 ~ /^\t_main "\$@"$/ { print "\tif [[ $1 == cron ]]; then\n\t\techo \"POSTGRES_DB=${POSTGRES_DB}\" > /backups/.env\n\t\techo \"POSTGRES_USER=${POSTGRES_USER}\" >> /backups/.env\n\t\tservice cron start\n\t\tshift\n\tfi" }{ print }' docker-entrypoint.sh > bookwyrm-entrypoint.sh
  17. RUN chown postgres /bookwyrm-entrypoint.sh
  18. RUN chmod u=rwx,go=r /bookwyrm-entrypoint.sh