Compare commits
5 Commits
notificati
...
5546d5511e
| Author | SHA1 | Date | |
|---|---|---|---|
| 5546d5511e | |||
| 4e21b1372f | |||
| f33324e9f8 | |||
| f9a1919d08 | |||
| 96e9e79aeb |
34
Dockerfile
34
Dockerfile
@@ -10,7 +10,9 @@ RUN set -eux && \
|
|||||||
apt-get upgrade -y -qq && \
|
apt-get upgrade -y -qq && \
|
||||||
echo "Installing tools" && \
|
echo "Installing tools" && \
|
||||||
apt-get install -y -qq \
|
apt-get install -y -qq \
|
||||||
curl unzip cron ca-certificates logrotate && \
|
curl unzip cron ca-certificates logrotate dos2unix && \
|
||||||
|
echo "Remove exim" && \
|
||||||
|
apt-get remove -y -qq exim4 exim4-base exim4-daemon-light && \
|
||||||
echo "Cleaning up" && \
|
echo "Cleaning up" && \
|
||||||
apt-get --yes autoremove --purge && \
|
apt-get --yes autoremove --purge && \
|
||||||
apt-get clean --yes && \
|
apt-get clean --yes && \
|
||||||
@@ -19,9 +21,11 @@ RUN set -eux && \
|
|||||||
rm --recursive --force --verbose /var/tmp/* && \
|
rm --recursive --force --verbose /var/tmp/* && \
|
||||||
rm --recursive --force --verbose /var/cache/apt/archives/* && \
|
rm --recursive --force --verbose /var/cache/apt/archives/* && \
|
||||||
truncate --size 0 /var/log/*log
|
truncate --size 0 /var/log/*log
|
||||||
|
|
||||||
# install BunJs
|
# install BunJs
|
||||||
RUN curl -fsSL https://bun.com/install | bash
|
RUN curl -fsSL https://bun.com/install | bash
|
||||||
ENV PATH="/root/.bun/bin:$PATH"
|
ENV PATH="/root/.bun/bin:$PATH"
|
||||||
|
RUN ln -s /root/.bun/bin/bun /usr/local/bin/bun
|
||||||
# install dependencies into temp directory
|
# install dependencies into temp directory
|
||||||
# this will cache them and speed up future builds
|
# this will cache them and speed up future builds
|
||||||
FROM base AS install
|
FROM base AS install
|
||||||
@@ -34,26 +38,26 @@ RUN mkdir -p /temp/prod
|
|||||||
COPY package.json bun.lock /temp/prod/
|
COPY package.json bun.lock /temp/prod/
|
||||||
RUN cd /temp/prod && bun install --frozen-lockfile --production
|
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
|
# copy node_modules from temp directory
|
||||||
# then copy all (non-ignored) project files into the image
|
# then copy all (non-ignored) project files into the image
|
||||||
FROM base AS prerelease
|
FROM base AS prerelease
|
||||||
COPY --from=install /temp/dev/node_modules node_modules
|
COPY --from=install /temp/dev/node_modules node_modules
|
||||||
COPY . ./
|
COPY . .
|
||||||
# [optional] tests & build
|
# [optional] tests & build
|
||||||
ENV NODE_ENV=production
|
|
||||||
|
|
||||||
# copy production dependencies and source code into final image
|
# copy production dependencies and source code into final image
|
||||||
FROM base AS release
|
FROM base AS release
|
||||||
|
ENV NODE_ENV=production
|
||||||
COPY --from=install /temp/prod/node_modules node_modules
|
COPY --from=install /temp/prod/node_modules node_modules
|
||||||
COPY --from=prerelease /opt/app/package.json .
|
# COPY ./docker/cron-bun-log /etc/logrotate.d/
|
||||||
#COPY --from=prerelease .entrypoint.sh .
|
COPY ./docker/Crontab /etc/cron.d/
|
||||||
COPY . ./
|
RUN chmod 0644 /etc/cron.d/Crontab && \
|
||||||
RUN mkdir /var/log/cron && touch /var/log/cron.log
|
chown root:root /etc/cron.d/Crontab
|
||||||
VOLUME /opt/app/data/db
|
COPY . .
|
||||||
# VOLUME /var/log/cron
|
RUN dos2unix \
|
||||||
CMD bun run ./src/app.ts --today && cron && tail -f /var/log/cron.log
|
/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" ]
|
||||||
@@ -3,7 +3,6 @@ services:
|
|||||||
build: .
|
build: .
|
||||||
volumes:
|
volumes:
|
||||||
- ./data/db:/opt/app/data/db
|
- ./data/db:/opt/app/data/db
|
||||||
- ./data/app/log:/var/log
|
|
||||||
env_file:
|
env_file:
|
||||||
- path: ./.env
|
- path: ./.env
|
||||||
required: true
|
required: true
|
||||||
@@ -28,8 +27,8 @@ services:
|
|||||||
#- 8880:8000
|
#- 8880:8000
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-f", "http://localhost:8000/status"]
|
test: ["CMD", "curl", "-f", "http://localhost:8000/status"]
|
||||||
interval: 10s
|
interval: 5s
|
||||||
timeout: 5s
|
timeout: 3s
|
||||||
retries: 5
|
retries: 5
|
||||||
# networks:
|
# networks:
|
||||||
# default:
|
# default:
|
||||||
|
|||||||
@@ -1,2 +1,5 @@
|
|||||||
8 * * * * bun run ./src/app.ts --today > /var/log/cron.log 2>&1
|
SHELL=/bin/bash
|
||||||
*/15 * * * * bun run ./src/app.ts > /var/log/cron.log 2>&1
|
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
|
||||||
|
|||||||
33
docker/docker-entrypoint.sh
Normal file
33
docker/docker-entrypoint.sh
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 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
|
||||||
26
run-task.sh
Normal file
26
run-task.sh
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# set -e
|
||||||
|
export PATH="/root/.bun/bin:$PATH"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
log_error() {
|
||||||
|
echo "[ERROR] $(date) $1" >> /proc/1/fd/2
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
log_error "Task failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user