From 1a9742f92109c61a4faff1f015f0edfa4d311e31 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Sun, 2 Apr 2023 10:14:38 +0300 Subject: [PATCH 1/6] Dockerfile created --- Dockerfile | 19 +++++++++++++++++++ package.json | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..23a04a3 --- /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 8080 +CMD [ "node", "dist/index.js" ] \ No newline at end of file diff --git a/package.json b/package.json index 0c159c7..f4d0c85 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,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/node": "^18.15.5" -- 2.45.2 From 70aa6c0dd29709d7ce48fec2dcc00b02f29ee196 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Sun, 2 Apr 2023 15:40:12 +0300 Subject: [PATCH 2/6] fixing saving to public folder --- maccabi-haifa-fc.ics | 20 ++++++++++---------- src/index.ts | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/maccabi-haifa-fc.ics b/maccabi-haifa-fc.ics index aa03f7b..d9491d4 100644 --- a/maccabi-haifa-fc.ics +++ b/maccabi-haifa-fc.ics @@ -5,9 +5,9 @@ PRODID:https://mhaifafc.com/ METHOD:PUBLISH X-PUBLISHED-TTL:PT1H BEGIN:VEVENT -UID:_5qS0t0NPnxt7ysQhiM1b +UID:Od0AeXkvLYZ2ELyVyCf3w SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T122458Z +DTSTAMP:20230402T123647Z DTSTART:20230404T173000Z DTEND:20230404T193000Z DESCRIPTION:Maccabi Tel aviv vs. Maccabi Haifa @@ -19,9 +19,9 @@ ORGANIZER;CN=Maccabi Haifa F.C. X-MICROSOFT-CDO-BUSYSTATUS:BUSY END:VEVENT BEGIN:VEVENT -UID:gOdljSPvOnSsLTwF_JSdA +UID:OCMexF1apX1IoP8K9qHCQ SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T122458Z +DTSTAMP:20230402T123647Z DTSTART:20230408T170000Z DTEND:20230408T190000Z DESCRIPTION:Maccabi Haifa vs. Maccabi Netanya @@ -33,9 +33,9 @@ ORGANIZER;CN=Maccabi Haifa F.C. X-MICROSOFT-CDO-BUSYSTATUS:BUSY END:VEVENT BEGIN:VEVENT -UID:6VKjleqclIMSj6TG7bx4_ +UID:4Qab1aW2S5xDL3OC-3_sA SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T122458Z +DTSTAMP:20230402T123647Z DTSTART:20230415T153000Z DTEND:20230415T173000Z DESCRIPTION:Hapoel Jerusalem vs. Maccabi Haifa @@ -47,9 +47,9 @@ ORGANIZER;CN=Maccabi Haifa F.C. X-MICROSOFT-CDO-BUSYSTATUS:BUSY END:VEVENT BEGIN:VEVENT -UID:yabS2xjYG6txukIHZCeFV +UID:N3At5VutrWAUaQiaNkwm6 SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T122458Z +DTSTAMP:20230402T123647Z DTSTART:20230423T173000Z DTEND:20230423T193000Z DESCRIPTION:F.C Ashdod vs. Maccabi Haifa @@ -61,9 +61,9 @@ ORGANIZER;CN=Maccabi Haifa F.C. X-MICROSOFT-CDO-BUSYSTATUS:BUSY END:VEVENT BEGIN:VEVENT -UID:cuLZKgXMny8Utk3LInSVj +UID:QTleUThXSlGWTOZo2moK5 SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T122458Z +DTSTAMP:20230402T123647Z DTSTART:20230501T173000Z DTEND:20230501T193000Z DESCRIPTION:H Be'er Sheva vs. Maccabi Haifa diff --git a/src/index.ts b/src/index.ts index 56a22bc..d8dfac6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -34,8 +34,7 @@ class App { } const app = new App(); - -console.log("Declaring Cron Job") +console.log("Declaring Cron Job every day at 10:00") const cron = "0 10 * * *" // every day at 10:00 @@ -43,10 +42,11 @@ const job = new CronJob( "* * * * *", async () => { console.log("START") - const outputFileLocation = 'maccabi-haifa-fc.ics'; + const outputFileLocation = 'public/maccabi-haifa-fc.ics'; const games = await app.gameSource.getGamesFromHaifa(); const icsEvents = app.ics.generateIcsOutputFromGames(games); fs.writeFileSync(outputFileLocation, icsEvents); + console.log("END") }, null, true, -- 2.45.2 From 71da8d04eef6acdb4559501216968d3ae78ebe33 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Sun, 2 Apr 2023 16:09:45 +0300 Subject: [PATCH 3/6] wip --- Dockerfile | 4 ++-- src/index.ts | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 23a04a3..8d2ae21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:16 +FROM node:latest # Create app directory WORKDIR /usr/src/app @@ -15,5 +15,5 @@ RUN npm install # Bundle app source COPY . . -EXPOSE 8080 +EXPOSE ${PORT} CMD [ "node", "dist/index.js" ] \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index d8dfac6..39ee401 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; @@ -52,13 +56,10 @@ const job = new CronJob( 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 -- 2.45.2 From 85e1f7b863b6344e15c9b3647390c57019abece9 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Sun, 2 Apr 2023 16:22:49 +0300 Subject: [PATCH 4/6] done with dockerizing --- .dockerignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5171c54 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log \ No newline at end of file -- 2.45.2 From 49b42b83b944a4d8b377396df7143e6adb9bc2d8 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Sun, 2 Apr 2023 16:40:49 +0300 Subject: [PATCH 5/6] done with dockerizing --- .dockerignore | 4 +++- Dockerfile | 2 +- src/index.ts | 11 ++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.dockerignore b/.dockerignore index 5171c54..92a116f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,4 @@ node_modules -npm-debug.log \ No newline at end of file +npm-debug.log +src +tmp \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8d2ae21..7d0eb91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:latest +FROM node:16 # Create app directory WORKDIR /usr/src/app diff --git a/src/index.ts b/src/index.ts index 39ee401..b9f4ca3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,17 +40,18 @@ class App { const app = new App(); console.log("Declaring Cron Job every day at 10:00") -const cron = "0 10 * * *" // every day at 10:00 - const job = new CronJob( - "* * * * *", + "0 10 * * *", // every day at 10:00, async () => { - console.log("START") + 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("END") + console.log("Done") }, null, true, -- 2.45.2 From 4ff7cdb438db26de33f7e403bff90787cc7e32c5 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Sun, 2 Apr 2023 16:42:09 +0300 Subject: [PATCH 6/6] done with dockerizing --- maccabi-haifa-fc.ics | 77 -------------------------------------------- 1 file changed, 77 deletions(-) delete mode 100644 maccabi-haifa-fc.ics diff --git a/maccabi-haifa-fc.ics b/maccabi-haifa-fc.ics deleted file mode 100644 index d9491d4..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:Od0AeXkvLYZ2ELyVyCf3w -SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T123647Z -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:OCMexF1apX1IoP8K9qHCQ -SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T123647Z -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:4Qab1aW2S5xDL3OC-3_sA -SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T123647Z -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:N3At5VutrWAUaQiaNkwm6 -SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T123647Z -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:QTleUThXSlGWTOZo2moK5 -SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230402T123647Z -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 -- 2.45.2