3 Commits

5 changed files with 56 additions and 32 deletions

View File

@@ -11,6 +11,8 @@ RUN set -eux && \
echo "Installing tools" && \
apt-get install -y -qq \
curl unzip cron ca-certificates logrotate dos2unix && \
echo "Remove exim" && \
apt-get remove -y -qq exim4 exim4-base exim4-daemon-light && \
echo "Cleaning up" && \
apt-get --yes autoremove --purge && \
apt-get clean --yes && \
@@ -19,9 +21,6 @@ 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
@@ -43,16 +42,22 @@ RUN cd /temp/prod && bun install --frozen-lockfile --production
# then copy all (non-ignored) project files into the image
FROM base AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . ./
COPY . .
# [optional] tests & build
# 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 . ./
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" ]
# COPY ./docker/cron-bun-log /etc/logrotate.d/
COPY ./docker/Crontab /etc/cron.d/
RUN chmod 0644 /etc/cron.d/Crontab && \
chown root:root /etc/cron.d/Crontab
COPY . .
RUN dos2unix \
/opt/app/docker/docker-entrypoint.sh \
/opt/app/run-task.sh \
/etc/cron.d/Crontab
RUN chmod +x /opt/app/docker/docker-entrypoint.sh && \
chmod +x /opt/app/run-task.sh
ENTRYPOINT [ "/opt/app/docker/docker-entrypoint.sh" ]

View File

@@ -3,7 +3,6 @@ services:
build: .
volumes:
- ./data/db:/opt/app/data/db
- ./data/app/log:/var/log
env_file:
- path: ./.env
required: true
@@ -28,8 +27,8 @@ services:
#- 8880:8000
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/status"]
interval: 10s
timeout: 5s
interval: 5s
timeout: 3s
retries: 5
# networks:
# default:

View File

@@ -1,2 +1,5 @@
0 8 * * * root /opt/app/run-task.sh --today
*/15 * * * * root /opt/app/run-task.sh
SHELL=/bin/bash
MAILTO=""
0 8 * * * root . /etc/cron-env.sh && /opt/app/run-task.sh --today >> /proc/1/fd/1 2>&1
*/15 * * * * root . /etc/cron-env.sh && /opt/app/run-task.sh >> /proc/1/fd/1 2>&1
* * * * * root echo "cron test ran at $(date)" >> /proc/1/fd/1 2>&1

View File

@@ -1,15 +1,33 @@
#!/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
# Create or overwrite the cron env file
cat /dev/null > /etc/cron-env.sh
chmod 600 /etc/cron-env.sh
chmod +x /etc/cron-env.sh
# Write the Env Vars into a file for cron. happens during runtime of the container and not build.
# List your environment variables here
env_vars=(
ntfy_on
ntfy_username
ntfy_password
ntfy_host
ntfy_topic
dc_on
dc_webhook
dc_botname
dc_avatar_url
)
for var in "${env_vars[@]}"; do
val="${!var}"
if [ -n "$val" ]; then
# Safely export the variable with proper quoting
printf 'export %s=%q\n' "$var" "$val" >> /etc/cron-env.sh
fi
done
export PATH="/root/.bun/bin:$PATH"
bun run /opt/app/src/app.ts --today
# Start cron in foreground
exec cron -f

View File

@@ -1,13 +1,10 @@
#!/bin/bash
set -e
set -o allexport
. /etc/environment || echo "[WARN] Failed to load env" >> /proc/1/fd/2
set +o allexport
# set -e
export PATH="/root/.bun/bin:$PATH"
cd /opt/app
set -o allexport
. /etc/cron-env.sh || echo "[WARN] Failed to load env" >> /proc/1/fd/2
set +o allexport
log_info() {
echo "[INFO] $(date) $1" >> /proc/1/fd/1
@@ -19,6 +16,8 @@ log_error() {
log_info "Starting task with args: $*"
cd /opt/app
if bun run ./src/app.ts "$@" >> /proc/1/fd/1 2>> /proc/1/fd/2; then
log_info "Task completed successfully."
else