Modified the app to run inside a docker container
This commit is contained in:
parent
0b3e254bb7
commit
7e32e3974d
21
Dockerfile
Normal file
21
Dockerfile
Normal file
@ -0,0 +1,21 @@
|
||||
FROM node:current-slim
|
||||
ARG VERSION
|
||||
ENV VERSION ${VERSION:-development}
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY start.sh package*.json ecosystem.config.json /app/
|
||||
|
||||
COPY ./app/ /app/app
|
||||
|
||||
COPY ./libs/ /app/libs
|
||||
|
||||
COPY ./data/ /app/data
|
||||
|
||||
RUN npm install pm2 -g && npm install
|
||||
|
||||
# RUN ls -lh .
|
||||
|
||||
RUN chmod +x /app/start.sh
|
||||
|
||||
ENTRYPOINT ["/app/start.sh"]
|
33
Makefile
Normal file
33
Makefile
Normal file
@ -0,0 +1,33 @@
|
||||
PROJECT = lot
|
||||
VERSION = $(shell git rev-parse --short HEAD)
|
||||
|
||||
ECR_REPO = mail.caliban.io:5000
|
||||
#APP_IMAGE = 482681734622.dkr.ecr.eu-west-1.amazonaws.com/$(PROJECT):$(VERSION)
|
||||
APP_IMAGE = $(ECR_REPO)/$(PROJECT):$(VERSION)
|
||||
NO_CACHE = true
|
||||
|
||||
|
||||
#build docker image
|
||||
build:
|
||||
docker build . -t $(APP_IMAGE) --build-arg VERSION=$(VERSION) --no-cache=$(NO_CACHE) --compress
|
||||
.PHONY: build
|
||||
|
||||
#push docker image to registry
|
||||
push: build
|
||||
docker push $(APP_IMAGE)
|
||||
.PHONY: push
|
||||
|
||||
#push docker image to registry
|
||||
run: build
|
||||
docker run $(APP_IMAGE)
|
||||
.PHONY: run
|
||||
ver:
|
||||
@echo '$(VERSION)'
|
||||
#echo $ERSION
|
||||
.PHONY: ver
|
||||
|
||||
tar:
|
||||
# docker build . -t $(APP_IMAGE) --build-arg VERSION=$(VERSION) --no-cache=$(NO_CACHE)
|
||||
tar -C ./ -czvf ./archive.tar.gz 'package.json' 'ncas/' 'helpers/' -X *.js
|
||||
|
||||
.PHONY: build
|
31
app/predict.js
Normal file
31
app/predict.js
Normal file
@ -0,0 +1,31 @@
|
||||
const loader = require('../libs/loader');
|
||||
const lot = require('../libs/lot');
|
||||
const lotv2 = require('../libs/lotV2');
|
||||
const pusher = require('../libs/pusher');
|
||||
const log4js = require('log4js');
|
||||
const logger = log4js.getLogger();
|
||||
|
||||
logger.level = 'debug';
|
||||
|
||||
function run(data) {
|
||||
const v1 = lot.calculate(data);
|
||||
const v2 = lotv2.calculate(data);
|
||||
|
||||
const msg = `V2: ${v2} stars: ${v1.mainstars}
|
||||
V1: ${v1.mainline} stars: ${v1.mainstars}
|
||||
Other: ${v1.otherLine} stars: ${v1.otherStars}
|
||||
`;
|
||||
|
||||
pusher.push(msg);
|
||||
logger.debug(msg);
|
||||
// loader.save(data);
|
||||
}
|
||||
|
||||
function go() {
|
||||
logger.info('GO!');
|
||||
loader.load(run);
|
||||
}
|
||||
|
||||
(() => {
|
||||
go();
|
||||
})();
|
5
app/retriever.js
Normal file
5
app/retriever.js
Normal file
@ -0,0 +1,5 @@
|
||||
const { retrieveNew } = require('../libs/retriever');
|
||||
|
||||
(() => {
|
||||
retrieveNew();
|
||||
})();
|
File diff suppressed because one or more lines are too long
22
ecosystem.config.json
Normal file
22
ecosystem.config.json
Normal file
@ -0,0 +1,22 @@
|
||||
[
|
||||
{
|
||||
"name": "Predictor",
|
||||
"script": "app/predict.js",
|
||||
"env": {
|
||||
"NODE_ENV": "production"
|
||||
},
|
||||
"autorestart": false,
|
||||
"instances": 1,
|
||||
"cron_restart": "10 15 * * 2,5"
|
||||
},
|
||||
{
|
||||
"name": "Retriever",
|
||||
"script": "app/retriever.js",
|
||||
"env": {
|
||||
"NODE_ENV": "production"
|
||||
},
|
||||
"autorestart": false,
|
||||
"instances": 1,
|
||||
"cron_restart": "45 9 * * 3,6"
|
||||
}
|
||||
]
|
@ -5,22 +5,21 @@
|
||||
* Time: 16:35
|
||||
*
|
||||
*/
|
||||
var Pushover = require('node-pushover'), dateFormat = require('dateformat');
|
||||
var push = new Pushover({
|
||||
'token': 'aqnos2j4v4pjpry3hvnxq9646eup23',
|
||||
'user': 'BE2vgFxdHJw91lVGMRYvZDDmVa5cCM'
|
||||
const Pushover = require('node-pushover')/* , dateFormat = require('dateformat')*/;
|
||||
const push = new Pushover({
|
||||
'token': 'aqnos2j4v4pjpry3hvnxq9646eup23', 'user': 'BE2vgFxdHJw91lVGMRYvZDDmVa5cCM'
|
||||
});
|
||||
|
||||
|
||||
var logger = require('log4js').getLogger();
|
||||
const logger = require('log4js').getLogger();
|
||||
|
||||
const prefix = process.env.NODE_ENV === 'production' ? 'Production' : 'Dev';
|
||||
const title = `mdLot ${ prefix } Alert`;
|
||||
module.exports = {
|
||||
|
||||
'push' : function(contents) {
|
||||
var now = new Date();
|
||||
var msg = `Updated at ${ dateFormat(now, 'dddd, mmmm dS, yyyy, HH:MM:ss') }\n\n${ contents }`;
|
||||
const now = new Date();
|
||||
// var msg = `Updated at ${ dateFormat(now, 'dddd, mmmm dS, yyyy, HH:MM:ss') }\n\n${ contents }`;
|
||||
const msg = `Updated at ${new Date(now).toLocaleString()}\n\n${contents}`;
|
||||
push.send(title, msg);
|
||||
}
|
||||
};
|
||||
|
@ -1,30 +1,36 @@
|
||||
const jsonfile = require("jsonfile");
|
||||
const jsonfile = require('jsonfile');
|
||||
|
||||
const fetch = require("node-fetch");
|
||||
const fecha = require("fecha");
|
||||
const fetch = require('node-fetch');
|
||||
const fecha = require('fecha');
|
||||
|
||||
const { scrapeResults } = require("./scraper");
|
||||
const { scrapeResults } = require('./scraper');
|
||||
|
||||
const file = "data/data.json";
|
||||
const file = 'data/data.json';
|
||||
|
||||
// https://www.euro-millions.com/results
|
||||
function lastEvent() {
|
||||
const dateThen = new Date();
|
||||
|
||||
// Tuesday and Friday
|
||||
// Sun, Mon, *Tue*, Wed, Thu, *Fri*, Sat
|
||||
// [2, 3 ,4 ,1 ,2 ,3 ,1]
|
||||
|
||||
const daySubtractor = [2, 3, 4, 1, 2, 3, 1];
|
||||
|
||||
const dayNow = dateThen.getDay();
|
||||
|
||||
dateThen.setDate(dateThen.getDate() - daySubtractor[dayNow]);
|
||||
|
||||
return fecha.format(dateThen, '/DD-MM-YYYY');
|
||||
}
|
||||
|
||||
function retrieveNew() {
|
||||
console.log("retrieveNew...");
|
||||
const now = new Date().getTime();
|
||||
|
||||
// https://www.euro-millions.com/results/05-02-2019
|
||||
|
||||
const yesterday = new Date(now - 8.64e7);
|
||||
|
||||
const ystring = fecha.format(yesterday, "/DD-MM-YYYY");
|
||||
const ystring = lastEvent();
|
||||
|
||||
const lotData = jsonfile.readFileSync(file);
|
||||
|
||||
const u = `https://www.euro-millions.com/results${ystring}`;
|
||||
|
||||
console.log("retrieving:", u);
|
||||
|
||||
// https://www.euro-millions.com/results/15-02-2019
|
||||
console.log('retrieving:', u);
|
||||
|
||||
fetch(u)
|
||||
.then((res) => res.text())
|
||||
|
@ -43,3 +43,6 @@ cron.schedule("45 9 * * 3,6", () => {
|
||||
});
|
||||
|
||||
logger.info("Lot V3 started...");
|
||||
|
||||
|
||||
retrieveNew();
|
@ -5,14 +5,13 @@
|
||||
* Time: 16:35
|
||||
*
|
||||
*/
|
||||
var Pushover = require('node-pushover'), dateFormat = require('dateformat');
|
||||
var Pushover = require('node-pushover')/*, dateFormat = require('dateformat')*/;
|
||||
var push = new Pushover({
|
||||
'token': 'aqnos2j4v4pjpry3hvnxq9646eup23',
|
||||
'user': 'BE2vgFxdHJw91lVGMRYvZDDmVa5cCM'
|
||||
});
|
||||
|
||||
|
||||
var logger = require('log4js').getLogger();
|
||||
const logger = require('log4js').getLogger();
|
||||
|
||||
const prefix = process.env.NODE_ENV === 'production' ? 'Production' : 'Dev';
|
||||
const title = `mdLot ${ prefix } Alert`;
|
||||
@ -20,7 +19,8 @@ module.exports = {
|
||||
|
||||
'push' : function(contents) {
|
||||
var now = new Date();
|
||||
var msg = `Updated at ${ dateFormat(now, 'dddd, mmmm dS, yyyy, HH:MM:ss') }\n\n${ contents }`;
|
||||
// var msg = `Updated at ${ dateFormat(now, 'dddd, mmmm dS, yyyy, HH:MM:ss') }\n\n${ contents }`;
|
||||
var msg = `Updated at ${ now.format(('dddd, mmmm dS, yyyy, HH:MM')) }\n\n${ contents }`;
|
||||
push.send(title, msg);
|
||||
}
|
||||
};
|
2323
package-lock.json
generated
Normal file
2323
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@ -11,9 +11,10 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"jsonfile": "^2.2.3",
|
||||
"node-cron": "^1.0.0",
|
||||
"tape": "^4.9.2",
|
||||
"eslint": "^8.15.0",
|
||||
"jsonfile": "^6.1.0",
|
||||
"node-cron": "^3.0.0",
|
||||
"tape": "^5.5.3",
|
||||
"tape-promise": "^4.0.0",
|
||||
"ultrases": "^0.1.3"
|
||||
},
|
||||
@ -22,12 +23,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"cheerio": "^1.0.0-rc.2",
|
||||
"dateformat": "^2.0.0",
|
||||
"fecha": "^3.0.2",
|
||||
"jsonfile": "^2.4.0",
|
||||
"log4js": "^2.3.3",
|
||||
"node-fetch": "^2.3.0",
|
||||
"node-pushover": "^0.2.2",
|
||||
"fecha": "^4.2.3",
|
||||
"log4js": "^6.4.6",
|
||||
"node-fetch": "^3.2.4",
|
||||
"node-pushover": "^1.0.0",
|
||||
"sugar": "^2.0.1",
|
||||
"sugar-date": "^2.0.0"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user