Compare commits
1 Commits
v0.1.1
...
999bdf7222
| Author | SHA1 | Date | |
|---|---|---|---|
| 999bdf7222 |
2
Crontab
Normal file
2
Crontab
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
1 * * * * bun run ./src/app.ts --today > /dev/null 2>&1
|
||||||
|
0 * * * * bun run ./src/app.ts > /dev/null 2>&1
|
||||||
31
Dockerfile
31
Dockerfile
@@ -1,44 +1,51 @@
|
|||||||
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 && \
|
||||||
|
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
|
||||||
ENV PATH="/root/.bun/bin:$PATH"
|
ENV PATH="/root/.bun/bin:$PATH"
|
||||||
# symlink python3 to python
|
|
||||||
RUN ln -s /usr/bin/python3 /usr/bin/python
|
|
||||||
|
|
||||||
# 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
|
||||||
RUN mkdir -p /temp/dev
|
RUN mkdir -p /temp/dev
|
||||||
COPY package.json bun.lock /temp/dev/
|
COPY package.json bun.lock /temp/dev/
|
||||||
RUN cd /temp/dev && bun install --frozen-lockfile
|
RUN cd /temp/dev && bun install --frozen-lockfile
|
||||||
# and install python dependencies
|
|
||||||
COPY ./requirements.txt .
|
|
||||||
RUN pip3 install --break-system-packages -r ./requirements.txt
|
|
||||||
|
|
||||||
# install with --production (exclude devDependencies)
|
# install with --production (exclude devDependencies)
|
||||||
RUN mkdir -p /temp/prod
|
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
|
||||||
|
|
||||||
|
# and install python dependencies
|
||||||
|
# COPY ./requirements.txt .
|
||||||
|
# RUN python3 -m pip install --break-system-packages -r requirements.txt
|
||||||
|
# RUN python3 -m pip install -U python-dotenv
|
||||||
|
|
||||||
# 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
|
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
|
||||||
|
WORKDIR /opt/app
|
||||||
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 .
|
||||||
VOLUME ["/opt/app/data/db"]
|
#COPY --from=prerelease .entrypoint.sh .
|
||||||
# run the app
|
COPY Crontab /etc/cron.d/
|
||||||
USER bun
|
RUN chmod 0644 /etc/cron.d/Crontab
|
||||||
ENTRYPOINT ["./entrypoint.sh"]
|
COPY . ./
|
||||||
|
# USER bun
|
||||||
|
RUN touch /var/log/cron.log
|
||||||
|
# RUN chmod +x entrypoint.sh
|
||||||
|
# ENTRYPOINT ["./entrypoint.sh"]
|
||||||
|
VOLUME /opt/app/data/db
|
||||||
|
CMD bun run ./src/app.ts --today && cron && tail -f /var/log/cron.log
|
||||||
36
docker-compose.yml
Normal file
36
docker-compose.yml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
services:
|
||||||
|
app:
|
||||||
|
build: .
|
||||||
|
volumes:
|
||||||
|
- ./data/db:/opt/app/data/db
|
||||||
|
env_file:
|
||||||
|
- path: ./.env
|
||||||
|
required: true
|
||||||
|
depends_on:
|
||||||
|
apprise:
|
||||||
|
condition: service_healthy
|
||||||
|
links:
|
||||||
|
- apprise
|
||||||
|
apprise:
|
||||||
|
image: caronc/apprise:latest
|
||||||
|
hostname: apprise
|
||||||
|
environment:
|
||||||
|
- APPRISE_WORKER_COUNT=1
|
||||||
|
- APPRISE_STATEFUL_MODE=simple
|
||||||
|
# - PUID=$(id -u)
|
||||||
|
# - PGID=$(id -g)
|
||||||
|
volumes:
|
||||||
|
- ./data/apprise/config:/config
|
||||||
|
- ./data/apprise/plugin:/plugin
|
||||||
|
- ./data/apprise/attach:/attach
|
||||||
|
ports:
|
||||||
|
- 8000:8000
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost:8000/status"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 5
|
||||||
|
# networks:
|
||||||
|
# default:
|
||||||
|
# external: true
|
||||||
|
# name: npm
|
||||||
@@ -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": {
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
apprise
|
apprise
|
||||||
|
python-dotenv
|
||||||
28
src/app.ts
28
src/app.ts
@@ -112,11 +112,29 @@ async function main( ) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
})( ev );
|
})( ev );
|
||||||
sendNotification(
|
const title = `${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}`
|
await fetch("http://apprise:8000/notify", {
|
||||||
// `${ev.link || "https://77th-jsoc.com/#/events"}`
|
method: "POST",
|
||||||
);
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
urls: [
|
||||||
|
`ntfys://${process.env.ntfy_username}:${process.env.ntfy_password}@${process.env.ntfy_host}/${process.env.ntfy_topic}${ ev.link ? `?click=${ev.link}`: "?click=https://77th-jsoc.com/#/events" }`,
|
||||||
|
`discord://${process.env.dc_webhook}?avatar_url=${process.env.dc_avatar_url}&botname=${process.env.dc_botname}`
|
||||||
|
].join(","),
|
||||||
|
title: title,
|
||||||
|
body: body,
|
||||||
|
format: "text"
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// await sendNotification(
|
||||||
|
// title,
|
||||||
|
// body
|
||||||
|
// // `${ev.link || "https://77th-jsoc.com/#/events"}`
|
||||||
|
// );
|
||||||
ev.set_notification("done", db);
|
ev.set_notification("done", db);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
def main():
|
||||||
load_dotenv() # Load environment variables from .env file
|
load_dotenv() # Load environment variables from .env file
|
||||||
ntfy_username = os.getenv('ntfy_username')
|
ntfy_username = os.getenv('ntfy_username')
|
||||||
ntfy_password = os.getenv('ntfy_password')
|
ntfy_password = os.getenv('ntfy_password')
|
||||||
@@ -35,3 +36,6 @@ apobj.notify(
|
|||||||
body=args.body,
|
body=args.body,
|
||||||
title=args.title
|
title=args.title
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -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",
|
"python3",
|
||||||
"./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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,3 +11,5 @@ export const db = new Database(db_filepath);
|
|||||||
export function init () {
|
export function init () {
|
||||||
Event.createTable(db);
|
Event.createTable(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
Reference in New Issue
Block a user