diff --git a/Crontab b/Crontab new file mode 100644 index 0000000..c1dd39e --- /dev/null +++ b/Crontab @@ -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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d23c855..f6e5930 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ ARG VERSION LABEL build_version="77th_eventcalendarntfy ${VERSION}, Build-date:- ${BUILD_DATE}" LABEL maintainer="chiko " WORKDIR /opt/app +<<<<<<< HEAD RUN set -eux && \ echo "Updating APT" && \ apt-get update -y -qq && \ @@ -19,6 +20,12 @@ RUN set -eux && \ rm --recursive --force --verbose /var/tmp/* && \ rm --recursive --force --verbose /var/cache/apt/archives/* && \ truncate --size 0 /var/log/*log +======= +RUN apt-get update && \ + # 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/* +>>>>>>> 999bdf7222a68995dd40ec7da967b360f67d354a # install BunJs RUN curl -fsSL https://bun.com/install | bash ENV PATH="/root/.bun/bin:$PATH" @@ -34,26 +41,49 @@ RUN mkdir -p /temp/prod COPY package.json bun.lock /temp/prod/ RUN cd /temp/prod && bun install --frozen-lockfile --production +<<<<<<< HEAD COPY ./docker/Crontab /etc/cron.d/ RUN chmod 0644 /etc/cron.d/Crontab COPY ./docker/cron-bun-log /etc/logrotate.d/ RUN mkdir /var/log/cron && touch /var/log/cron.log +======= +# 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 +>>>>>>> 999bdf7222a68995dd40ec7da967b360f67d354a # copy node_modules from temp directory # then copy all (non-ignored) project files into the image FROM base AS prerelease COPY --from=install /temp/dev/node_modules node_modules COPY . ./ +<<<<<<< HEAD +======= + +>>>>>>> 999bdf7222a68995dd40ec7da967b360f67d354a # [optional] tests & build ENV NODE_ENV=production # copy production dependencies and source code into final image FROM base AS release +WORKDIR /opt/app COPY --from=install /temp/prod/node_modules node_modules COPY --from=prerelease /opt/app/package.json . #COPY --from=prerelease .entrypoint.sh . +<<<<<<< HEAD COPY . ./ RUN mkdir /var/log/cron && touch /var/log/cron.log VOLUME /opt/app/data/db # VOLUME /var/log/cron +======= +COPY Crontab /etc/cron.d/ +RUN chmod 0644 /etc/cron.d/Crontab +COPY . ./ +# USER bun +RUN touch /var/log/cron.log +# RUN chmod +x entrypoint.sh +# ENTRYPOINT ["./entrypoint.sh"] +VOLUME /opt/app/data/db +>>>>>>> 999bdf7222a68995dd40ec7da967b360f67d354a CMD bun run ./src/app.ts --today && cron && tail -f /var/log/cron.log \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index ebcd829..61238d5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,10 @@ services: build: . volumes: - ./data/db:/opt/app/data/db +<<<<<<< HEAD - ./data/app/log:/var/log +======= +>>>>>>> 999bdf7222a68995dd40ec7da967b360f67d354a env_file: - path: ./.env required: true @@ -24,12 +27,21 @@ services: - ./data/apprise/config:/config - ./data/apprise/plugin:/plugin - ./data/apprise/attach:/attach +<<<<<<< HEAD # ports: #- 8880:8000 healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8000/status"] interval: 10s timeout: 5s +======= + ports: + - 8000:8000 + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8000/status"] + interval: 30s + timeout: 10s +>>>>>>> 999bdf7222a68995dd40ec7da967b360f67d354a retries: 5 # networks: # default: diff --git a/src/app.ts b/src/app.ts index 723d77b..34a058d 100644 --- a/src/app.ts +++ b/src/app.ts @@ -116,8 +116,33 @@ async function main ( ) { return false; })( ev ); const title = `${today_prefix ? "TODAY " : ""}${notification_prefix ? notification_prefix + ": " : ""} ${ev.title} (${ TEventType[ ev.event_type ] })`; +<<<<<<< HEAD console.log("loop list_of_events - ev 'title': " + title ); await sendNotification( title, body, ev.link ? ev.link : null); +======= + + await fetch("http://apprise:8000/notify", { + 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"}` + // ); +>>>>>>> 999bdf7222a68995dd40ec7da967b360f67d354a ev.set_notification("done", db); } }; diff --git a/src/sendNotification.ts b/src/sendNotification.ts index 66e61d4..57d10a9 100644 --- a/src/sendNotification.ts +++ b/src/sendNotification.ts @@ -1,3 +1,4 @@ +<<<<<<< HEAD export async function sendNotification(title: string, body: string, link?: string | null) { console.dir({ sendNotification: { @@ -23,4 +24,22 @@ export async function sendNotification(title: string, body: string, link?: strin }); const responseBody = await response.json(); return responseBody; -} \ No newline at end of file +} +======= +import * as Bun from "bun"; + +export async function sendNotification(title: string, body: string, click?: string | null) { + const command = [ + "python3", + "./src/notification.py", + `--title=${title}`, + `--body=${body}`, + ]; + if ( click ) { + command.push(`--click=${click}`); + } + const proc = Bun.spawn(command); + const text = await proc.stdout.text(); + console.log("sendNotification: " + text); +} +>>>>>>> 999bdf7222a68995dd40ec7da967b360f67d354a