diff --git a/Dockerfile b/Dockerfile index d23c855..82f88f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ RUN set -eux && \ apt-get upgrade -y -qq && \ echo "Installing tools" && \ apt-get install -y -qq \ - curl unzip cron ca-certificates logrotate && \ + curl unzip cron ca-certificates logrotate dos2unix && \ echo "Cleaning up" && \ apt-get --yes autoremove --purge && \ apt-get clean --yes && \ @@ -19,9 +19,14 @@ RUN set -eux && \ rm --recursive --force --verbose /var/tmp/* && \ rm --recursive --force --verbose /var/cache/apt/archives/* && \ truncate --size 0 /var/log/*log +COPY ./docker/cron-bun-log /etc/logrotate.d/ +COPY ./docker/Crontab /etc/cron.d/ +RUN chmod 0644 /etc/cron.d/Crontab + # install BunJs RUN curl -fsSL https://bun.com/install | bash ENV PATH="/root/.bun/bin:$PATH" +RUN ln -s /root/.bun/bin/bun /usr/local/bin/bun # install dependencies into temp directory # this will cache them and speed up future builds FROM base AS install @@ -34,26 +39,20 @@ RUN mkdir -p /temp/prod COPY package.json bun.lock /temp/prod/ RUN cd /temp/prod && bun install --frozen-lockfile --production -COPY ./docker/Crontab /etc/cron.d/ -RUN chmod 0644 /etc/cron.d/Crontab -COPY ./docker/cron-bun-log /etc/logrotate.d/ -RUN mkdir /var/log/cron && touch /var/log/cron.log - # copy node_modules from temp directory # then copy all (non-ignored) project files into the image FROM base AS prerelease COPY --from=install /temp/dev/node_modules node_modules COPY . ./ # [optional] tests & build -ENV NODE_ENV=production # copy production dependencies and source code into final image FROM base AS release +ENV NODE_ENV=production COPY --from=install /temp/prod/node_modules node_modules -COPY --from=prerelease /opt/app/package.json . -#COPY --from=prerelease .entrypoint.sh . COPY . ./ -RUN mkdir /var/log/cron && touch /var/log/cron.log -VOLUME /opt/app/data/db -# VOLUME /var/log/cron -CMD bun run ./src/app.ts --today && cron && tail -f /var/log/cron.log \ No newline at end of file +COPY ./docker/docker-entrypoint.sh /opt/app/docker-entrypoint.sh +#COPY --from=prerelease .entrypoint.sh . +RUN dos2unix /opt/app/docker-entrypoint.sh && \ + chmod +x /opt/app/docker-entrypoint.sh +ENTRYPOINT [ "/opt/app/docker-entrypoint.sh" ] \ No newline at end of file diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh new file mode 100644 index 0000000..ab691c8 --- /dev/null +++ b/docker/docker-entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/bash +bun run ./src/app.ts --today + +echo "ntfy_on=$ntfy_on" >> /etc/environment +echo "ntfy_username=$ntfy_username" >> /etc/environment +echo "ntfy_password=$ntfy_password" >> /etc/environment +echo "ntfy_host=$ntfy_host" >> /etc/environment +echo "ntfy_topic=$ntfy_topic" >> /etc/environment +echo "dc_on=$dc_on" >> /etc/environment +echo "dc_webhook=$dc_webhook" >> /etc/environment +echo "dc_botname=$dc_botname" >> /etc/environment +echo "dc_avatar_url=$dc_avatar_url" >> /etc/environment + +# Start cron in foreground +exec cron -f \ No newline at end of file