FROM node:14-alpine

# RUN mkdir /crontabui \
#   && touch /etc/crontabs/oldfuture \
#   && chmod +x /etc/crontabs/oldfuture

RUN mkdir /crontabui \
  && touch /etc/crontabs \
  && chmod +x /etc/crontabs


WORKDIR /crontabui

RUN apk --no-cache --update add tzdata curl supervisor \
  && npm install -g crontab-ui \
  && echo $'[supervisord] \n\
nodaemon=true \n\
\n\
[program:crontab] \n\
command=crond -l 2 -f -c /etc/crontabs \n\
stderr_logfile = /var/log/crontab-stderr.log \n\
stdout_logfile = /var/log/crontab-stdout.log \n\
\n\
[program:crontabui] \n\
command=crontab-ui \n\
stderr_logfile = /var/log/crontabui-stderr.log \n\
stdout_logfile = /var/log/crontabui-stdout.log \n\
' >> /etc/supervisord.conf

ENV TZ=Europe/Zurich \
  HOST=0.0.0.0 \
  PORT=9000 \
  CRON_DB_PATH=./crontabs

COPY crontab.db /crontabui/crontabs/

EXPOSE 9000
VOLUME /etc/crontabs
VOLUME /opt

CMD ["supervisord", "-c", "/etc/supervisord.conf"]