From 8b04c510a77cc17016642d8592602334a95d4948 Mon Sep 17 00:00:00 2001 From: kfir Date: Sun, 2 Apr 2023 13:43:22 +0000 Subject: [PATCH] dockerizing_project (#3) Co-authored-by: Kfir Dayan Reviewed-on: https://git.dayanhub.com/kfir/haifa-reminder/pulls/3 added docker files --- .dockerignore | 4 +++ Dockerfile | 19 +++++++++++ maccabi-haifa-fc.ics | 77 -------------------------------------------- package.json | 4 ++- src/index.ts | 26 ++++++++------- 5 files changed, 40 insertions(+), 90 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile delete mode 100644 maccabi-haifa-fc.ics diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..92a116f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +node_modules +npm-debug.log +src +tmp \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7d0eb91 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM node:16 + +# Create app directory +WORKDIR /usr/src/app + +# Install app dependencies +# A wildcard is used to ensure both package.json AND package-lock.json are copied +# where available (npm@5+) +COPY package*.json ./ + +RUN npm install +# If you are building your code for production +# RUN npm ci --omit=dev + +# Bundle app source +COPY . . + +EXPOSE ${PORT} +CMD [ "node", "dist/index.js" ] \ No newline at end of file diff --git a/maccabi-haifa-fc.ics b/maccabi-haifa-fc.ics deleted file mode 100644 index aa03f7b..0000000 --- a/maccabi-haifa-fc.ics +++ /dev/null @@ -1,77 +0,0 @@ -BEGIN:VCALENDAR -VERSION:2.0 -CALSCALE:GREGORIAN -PRODID:https://mhaifafc.com/ -METHOD:PUBLISH -X-PUBLISHED-TTL:PT1H -BEGIN:VEVENT -UID:_5qS0t0NPnxt7ysQhiM1b -SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T122458Z -DTSTART:20230404T173000Z -DTEND:20230404T193000Z -DESCRIPTION:Maccabi Tel aviv vs. Maccabi Haifa -URL:https://mhaifafc.com/ -LOCATION:Sammy Ofer Stadium -STATUS:CONFIRMED -CATEGORIES: -ORGANIZER;CN=Maccabi Haifa F.C. -X-MICROSOFT-CDO-BUSYSTATUS:BUSY -END:VEVENT -BEGIN:VEVENT -UID:gOdljSPvOnSsLTwF_JSdA -SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T122458Z -DTSTART:20230408T170000Z -DTEND:20230408T190000Z -DESCRIPTION:Maccabi Haifa vs. Maccabi Netanya -URL:https://mhaifafc.com/ -LOCATION:Sammy Ofer Stadium -STATUS:CONFIRMED -CATEGORIES: -ORGANIZER;CN=Maccabi Haifa F.C. -X-MICROSOFT-CDO-BUSYSTATUS:BUSY -END:VEVENT -BEGIN:VEVENT -UID:6VKjleqclIMSj6TG7bx4_ -SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T122458Z -DTSTART:20230415T153000Z -DTEND:20230415T173000Z -DESCRIPTION:Hapoel Jerusalem vs. Maccabi Haifa -URL:https://mhaifafc.com/ -LOCATION:Sammy Ofer Stadium -STATUS:CONFIRMED -CATEGORIES: -ORGANIZER;CN=Maccabi Haifa F.C. -X-MICROSOFT-CDO-BUSYSTATUS:BUSY -END:VEVENT -BEGIN:VEVENT -UID:yabS2xjYG6txukIHZCeFV -SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T122458Z -DTSTART:20230423T173000Z -DTEND:20230423T193000Z -DESCRIPTION:F.C Ashdod vs. Maccabi Haifa -URL:https://mhaifafc.com/ -LOCATION:Sammy Ofer Stadium -STATUS:CONFIRMED -CATEGORIES: -ORGANIZER;CN=Maccabi Haifa F.C. -X-MICROSOFT-CDO-BUSYSTATUS:BUSY -END:VEVENT -BEGIN:VEVENT -UID:cuLZKgXMny8Utk3LInSVj -SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T122458Z -DTSTART:20230501T173000Z -DTEND:20230501T193000Z -DESCRIPTION:H Be'er Sheva vs. Maccabi Haifa -URL:https://mhaifafc.com/ -LOCATION:Sammy Ofer Stadium -STATUS:CONFIRMED -CATEGORIES: -ORGANIZER;CN=Maccabi Haifa F.C. -X-MICROSOFT-CDO-BUSYSTATUS:BUSY -END:VEVENT -END:VCALENDAR diff --git a/package.json b/package.json index f544135..e56d53e 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "node-html-parser": "^6.1.5" }, "scripts": { - "dev": "nodemon dist/index.js" + "dev": "nodemon dist/index.js", + "build": "tsc", + "start": "node dist/index.js" }, "devDependencies": { "@types/express": "^4.17.17", diff --git a/src/index.ts b/src/index.ts index 56a22bc..b9f4ca3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,10 @@ import GameSource from './GameSource'; import fs from 'fs'; import Ics from './Ics'; import express from 'express' +import env from 'dotenv'; + +env.config(); + const CronJob = require('cron').CronJob; @@ -34,31 +38,29 @@ class App { } const app = new App(); - -console.log("Declaring Cron Job") - -const cron = "0 10 * * *" // every day at 10:00 +console.log("Declaring Cron Job every day at 10:00") const job = new CronJob( - "* * * * *", + "0 10 * * *", // every day at 10:00, async () => { - console.log("START") - const outputFileLocation = 'maccabi-haifa-fc.ics'; + console.log("Staring a new job") + const outputFileLocation = 'public/maccabi-haifa-fc.ics'; + console.log("Getting games from Haifa") const games = await app.gameSource.getGamesFromHaifa(); + console.log("Generating ICS file") const icsEvents = app.ics.generateIcsOutputFromGames(games); + console.log("Writing ICS file to " + outputFileLocation) fs.writeFileSync(outputFileLocation, icsEvents); + console.log("Done") }, null, true, 'Asia/Jerusalem' ); - - - const webServer = express(); webServer.use(express.static('public')) -webServer.listen(3000, () => { - console.log('Example app listening on port 3000!') +webServer.listen(process.env.PORT, () => { + console.log('Example app listening on port '+process.env.PORT+'!') }) \ No newline at end of file