diff --git a/Crontab b/Crontab new file mode 100644 index 0000000..b6ea5bc --- /dev/null +++ b/Crontab @@ -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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index c4a8a55..775a558 100644 --- a/Dockerfile +++ b/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"] \ No newline at end of file +CMD cron && tail -f /var/log/cron.log \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..67e3b70 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,5 @@ +services: + app: + build: . + volumes: + - ./data/db:./data/db \ No newline at end of file diff --git a/package.json b/package.json index 32b5b91..434a70f 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/app.ts b/src/app.ts index 70c6df5..db8a048 100644 --- a/src/app.ts +++ b/src/app.ts @@ -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"}` diff --git a/src/sendNotification.ts b/src/sendNotification.ts index cb0a754..3792745 100644 --- a/src/sendNotification.ts +++ b/src/sendNotification.ts @@ -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) { + if ( click ) { command.push(`--click=${click}`); } - Bun.spawn(command); + const proc = Bun.spawn(command); + const text = await proc.stdout.text(); + console.log("sendNotification: " + text); } diff --git a/src/sql.ts b/src/sql.ts index 04be71c..6d55878 100644 --- a/src/sql.ts +++ b/src/sql.ts @@ -10,4 +10,6 @@ export const db = new Database(db_filepath); export function init () { Event.createTable(db); -} \ No newline at end of file +} + +init(); \ No newline at end of file