fix-docker #1

Merged
chiko merged 12 commits from fix-docker into main 2025-10-21 00:52:32 +00:00
7 changed files with 28 additions and 11 deletions
Showing only changes of commit fd0081d4d0 - Show all commits

2
Crontab Normal file
View 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

View File

@@ -1,7 +1,7 @@
FROM debian:12 AS base FROM debian:12 AS base
WORKDIR /opt/app WORKDIR /opt/app
RUN apt-get update && \ 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/* rm -rf /var/lib/apt/lists/*
# install BunJs # install BunJs
RUN curl -fsSL https://bun.com/install | bash 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=install /temp/prod/node_modules node_modules
COPY --from=prerelease /opt/app/src/app.ts . COPY --from=prerelease /opt/app/src/app.ts .
COPY --from=prerelease /opt/app/package.json . 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"] VOLUME ["/opt/app/data/db"]
# run the app CMD cron && tail -f /var/log/cron.log
USER bun
ENTRYPOINT ["./entrypoint.sh"]

5
docker-compose.yml Normal file
View File

@@ -0,0 +1,5 @@
services:
app:
build: .
volumes:
- ./data/db:./data/db

View File

@@ -12,7 +12,8 @@
"dev:init": "bun run ./src/app.ts --init", "dev:init": "bun run ./src/app.ts --init",
"db:init": "bun run ./run/db_init.ts", "db:init": "bun run ./run/db_init.ts",
"db:deleteall": "bun run ./run/db_deleteall.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 ." "docker:build": "docker build -t chiko/77th_eventcalendarntfy:0.1.0 ."
}, },
"peerDependencies": { "peerDependencies": {

View File

@@ -112,7 +112,7 @@ async function main( ) {
} }
return false; return false;
})( ev ); })( ev );
sendNotification( await sendNotification(
`${today_prefix ? "TODAY " : ""}${notification_prefix ? notification_prefix + ": " : ""} ${ev.title} (${ TEventType[ ev.event_type ] })`, `${today_prefix ? "TODAY " : ""}${notification_prefix ? notification_prefix + ": " : ""} ${ev.title} (${ TEventType[ ev.event_type ] })`,
`${body}` `${body}`
// `${ev.link || "https://77th-jsoc.com/#/events"}` // `${ev.link || "https://77th-jsoc.com/#/events"}`

View File

@@ -1,14 +1,16 @@
import * as Bun from "bun"; 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 = [ const command = [
"python", "python",
"./app/notification.py", "./src/notification.py",
`--title=${title}`, `--title=${title}`,
`--body=${body}`, `--body=${body}`,
]; ];
if ( click ) { if ( click ) {
command.push(`--click=${click}`); command.push(`--click=${click}`);
} }
Bun.spawn(command); const proc = Bun.spawn(command);
const text = await proc.stdout.text();
console.log("sendNotification: " + text);
} }

View File

@@ -11,3 +11,5 @@ export const db = new Database(db_filepath);
export function init () { export function init () {
Event.createTable(db); Event.createTable(db);
} }
init();