Compare commits
2 Commits
1729332373
...
f9a1919d08
| Author | SHA1 | Date | |
|---|---|---|---|
| f9a1919d08 | |||
| 96e9e79aeb |
25
Dockerfile
25
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
|
||||
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" ]
|
||||
@@ -1,2 +1,2 @@
|
||||
8 * * * * bun run ./src/app.ts --today > /var/log/cron.log 2>&1
|
||||
*/15 * * * * bun run ./src/app.ts > /var/log/cron.log 2>&1
|
||||
0 8 * * * root /opt/app/run-task.sh --today
|
||||
*/15 * * * * root /opt/app/run-task.sh
|
||||
|
||||
15
docker/docker-entrypoint.sh
Normal file
15
docker/docker-entrypoint.sh
Normal file
@@ -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
|
||||
27
run-task.sh
Normal file
27
run-task.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
set -o allexport
|
||||
. /etc/environment || echo "[WARN] Failed to load env" >> /proc/1/fd/2
|
||||
set +o allexport
|
||||
|
||||
export PATH="/root/.bun/bin:$PATH"
|
||||
|
||||
cd /opt/app
|
||||
|
||||
log_info() {
|
||||
echo "[INFO] $(date) $1" >> /proc/1/fd/1
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo "[ERROR] $(date) $1" >> /proc/1/fd/2
|
||||
}
|
||||
|
||||
log_info "Starting task with args: $*"
|
||||
|
||||
if bun run ./src/app.ts "$@" >> /proc/1/fd/1 2>> /proc/1/fd/2; then
|
||||
log_info "Task completed successfully."
|
||||
else
|
||||
log_error "Task failed!"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user