Skip to content

Commit a797f2d

Browse files
committed
Added automated cron tasks for periodic processing of user files
1 parent 4952836 commit a797f2d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

docker/Dockerfile.development

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
# https://hub.docker.com/_/node
55
FROM node:lts-alpine
66

7-
# Add cURL for health check and OpenSSL for generating random secret
8-
RUN apk update && apk add --no-cache curl openssl
7+
# Add cURL for health check, OpenSSL for generating random secret
8+
# and SuperCronic for cronjobs
9+
RUN apk update && apk add --no-cache curl openssl supercronic
910

1011
# Set the working directory to the website files
1112
WORKDIR /usr/src/app
@@ -25,6 +26,11 @@ RUN --mount=type=cache,target=.npm \
2526
npm set cache .npm && \
2627
npm install && chown -R node:node ./node_modules
2728

29+
# Add some cronjobs for automated tasks
30+
RUN npx tsc scripts/create-fake-accounts.ts scripts/expired-files.ts scripts/outdated-notifications.ts
31+
RUN echo "*/5 * * * * node /usr/src/app/scripts/expired-files.js > /dev/null 2>&1" >> /var/spool/cron/crontabs/node
32+
RUN echo "*/5 * * * * node /usr/src/app/scripts/outdated-notifications > /dev/null 2>&1" >> /var/spool/cron/crontabs/node
33+
2834
# Add wait script to wait for other services to be ready
2935
ADD https://github.com/ufoscout/docker-compose-wait/releases/latest/download/wait /wait
3036
RUN chmod +x /wait
@@ -36,6 +42,6 @@ USER node
3642
RUN sed -i "s#AUTH_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx#AUTH_SECRET=$(openssl rand -base64 32)#g" .env
3743

3844
# Create a custom entrypoint script
39-
RUN echo "/wait && npm run migrate && npm run dev" > docker/entrypoint.sh && chmod +x docker/entrypoint.sh
45+
RUN echo "/wait && npm run migrate && node scripts/create-fake-accounts.js && supercronic /etc/crontabs/node && npm run dev" > docker/entrypoint.sh && chmod +x docker/entrypoint.sh
4046

4147
CMD ["docker/entrypoint.sh"]

docker/Dockerfile.production

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
# https://hub.docker.com/_/node
55
FROM node:lts-alpine
66

7-
# Add cURL for health check and OpenSSL for generating random secret
8-
RUN apk update && apk add --no-cache curl openssl
7+
# Add cURL for health check, OpenSSL for generating random secret
8+
# and SuperCronic for cronjobs
9+
RUN apk update && apk add --no-cache curl openssl supercronic
910

1011
# Set the working directory to the website files
1112
WORKDIR /usr/src/app
@@ -25,6 +26,11 @@ RUN --mount=type=cache,target=.npm \
2526
npm set cache .npm && \
2627
npm install && chown -R node:node ./node_modules
2728

29+
# Add some cronjobs for automated tasks
30+
RUN npx tsc scripts/create-fake-accounts.ts scripts/expired-files.ts scripts/outdated-notifications.ts
31+
RUN echo "*/5 * * * * node /usr/src/app/scripts/expired-files.js > /dev/null 2>&1" >> /var/spool/cron/crontabs/node
32+
RUN echo "*/5 * * * * node /usr/src/app/scripts/outdated-notifications > /dev/null 2>&1" >> /var/spool/cron/crontabs/node
33+
2834
# Add wait script to wait for other services to be ready
2935
ADD https://github.com/ufoscout/docker-compose-wait/releases/latest/download/wait /wait
3036
RUN chmod +x /wait
@@ -39,6 +45,6 @@ RUN npm run build
3945
RUN npm prune --production
4046

4147
# Create a custom entrypoint script
42-
RUN echo "/wait && npm run migrate && npm run start" > docker/entrypoint.sh && chmod +x docker/entrypoint.sh
48+
RUN echo "/wait && npm run migrate && supercronic /etc/crontabs/node && npm run start" > docker/entrypoint.sh && chmod +x docker/entrypoint.sh
4349

4450
CMD ["docker/entrypoint.sh"]

0 commit comments

Comments
 (0)