Fixed dockerfile, added a docker-compose.yml, added db init function to run on every startup
This commit is contained in:
2
Crontab
Normal file
2
Crontab
Normal file
@@ -0,0 +1,2 @@
|
||||
0 8 * * * bun run ./src/app.ts --today > /dev/null 2>&1
|
||||
0 * * * * bun run ./src/app.ts > /dev/null 2>&1
|
||||
13
Dockerfile
13
Dockerfile
@@ -1,7 +1,7 @@
|
||||
FROM debian:12 AS base
|
||||
WORKDIR /opt/app
|
||||
RUN apt-get update && \
|
||||
apt-get install -y curl unzip ca-certificates python3 python3-pip && \
|
||||
apt-get install -y curl unzip cron ca-certificates python3 python3-pip && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
# install BunJs
|
||||
RUN curl -fsSL https://bun.com/install | bash
|
||||
@@ -38,7 +38,12 @@ FROM base AS release
|
||||
COPY --from=install /temp/prod/node_modules node_modules
|
||||
COPY --from=prerelease /opt/app/src/app.ts .
|
||||
COPY --from=prerelease /opt/app/package.json .
|
||||
COPY --from=prerelease /opt/app/entrypoint.sh .
|
||||
COPY Crontab /etc/cron.d/
|
||||
RUN chmod 0644 /etc/cron.d/Crontab
|
||||
# USER bun
|
||||
RUN touch /var/log/cron.log
|
||||
# RUN chmod +x entrypoint.sh
|
||||
# ENTRYPOINT ["./entrypoint.sh"]
|
||||
VOLUME ["/opt/app/data/db"]
|
||||
# run the app
|
||||
USER bun
|
||||
ENTRYPOINT ["./entrypoint.sh"]
|
||||
CMD cron && tail -f /var/log/cron.log
|
||||
5
docker-compose.yml
Normal file
5
docker-compose.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
services:
|
||||
app:
|
||||
build: .
|
||||
volumes:
|
||||
- ./data/db:./data/db
|
||||
@@ -12,7 +12,8 @@
|
||||
"dev:init": "bun run ./src/app.ts --init",
|
||||
"db:init": "bun run ./run/db_init.ts",
|
||||
"db:deleteall": "bun run ./run/db_deleteall.ts",
|
||||
"build": "bun build ./src/app.ts --compile --outfile ./build/77th_event_calendar_notification",
|
||||
"build": "bun build --compile --minify --sourcemap ./src/app.ts --outfile ./build/77th_event_calendar_notification",
|
||||
"build:linux": "bun build --compile --minify --sourcemap --target=bun-linux-arm64 ./src/app.ts --outfile ./build/77th_event_calendar_notification",
|
||||
"docker:build": "docker build -t chiko/77th_eventcalendarntfy:0.1.0 ."
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@@ -112,7 +112,7 @@ async function main( ) {
|
||||
}
|
||||
return false;
|
||||
})( ev );
|
||||
sendNotification(
|
||||
await sendNotification(
|
||||
`${today_prefix ? "TODAY " : ""}${notification_prefix ? notification_prefix + ": " : ""} ${ev.title} (${ TEventType[ ev.event_type ] })`,
|
||||
`${body}`
|
||||
// `${ev.link || "https://77th-jsoc.com/#/events"}`
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import * as Bun from "bun";
|
||||
|
||||
export function sendNotification(title: string, body: string, click?: string | null) {
|
||||
export async function sendNotification(title: string, body: string, click?: string | null) {
|
||||
const command = [
|
||||
"python",
|
||||
"./app/notification.py",
|
||||
"./src/notification.py",
|
||||
`--title=${title}`,
|
||||
`--body=${body}`,
|
||||
];
|
||||
if ( click ) {
|
||||
command.push(`--click=${click}`);
|
||||
}
|
||||
Bun.spawn(command);
|
||||
const proc = Bun.spawn(command);
|
||||
const text = await proc.stdout.text();
|
||||
console.log("sendNotification: " + text);
|
||||
}
|
||||
|
||||
@@ -11,3 +11,5 @@ export const db = new Database(db_filepath);
|
||||
export function init () {
|
||||
Event.createTable(db);
|
||||
}
|
||||
|
||||
init();
|
||||
Reference in New Issue
Block a user