Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
Added docker setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Qizot committed Mar 21, 2020
1 parent d240d95 commit 0a370d2
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 8 deletions.
2 changes: 2 additions & 0 deletions DataScraper/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__
venv
22 changes: 22 additions & 0 deletions DataScraper/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.7-slim

LABEL Author="Jakub Perżyło"
LABEL version="1.0.0"

ENV FLASK_APP "scraper"

RUN mkdir /app
WORKDIR /app

COPY . .

RUN pip install --upgrade pip && \
pip install -r requirements.txt

ADD . /app


EXPOSE 5000

CMD flask run --host=0.0.0.0

1 change: 0 additions & 1 deletion DataScraper/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ idna==2.9
itsdangerous==1.1.0
Jinja2==2.11.1
MarkupSafe==1.1.1
pkg-resources==0.0.0
requests==2.23.0
sgqlc==10.1
urllib3==1.25.8
Expand Down
2 changes: 2 additions & 0 deletions backend/coronavirus-visualizer-api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
12 changes: 12 additions & 0 deletions backend/coronavirus-visualizer-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:10.15.2-alpine as builder
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package* ./
COPY tsconfig.json ./
COPY src/ src/
RUN npm install
RUN npm run build:prod

CMD [ "npm", "run", "start:prod" ]

EXPOSE 4000
2 changes: 2 additions & 0 deletions backend/coronavirus-visualizer-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"scripts": {
"start:dev": "nodemon dist/index.js",
"build:dev": "tsc --watch --preserveWatchOutput",
"build:prod": "tsc",
"start:prod": "node dist/index.js",
"dev": "concurrently \"npm:build:dev\" \"npm:start:dev\""
},
"keywords": [],
Expand Down
5 changes: 4 additions & 1 deletion backend/coronavirus-visualizer-api/src/config/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export const PORT = process.env.PORT || 4000;
export const PORT = process.env.PORT || 4000;
export const HOST = process.env.HOST || "localhost";
export const MONGO_DB = process.env.MONGO_DB || "localhost";
export const VIRUS_DATA_API = process.env.VIRUS_DATA_API || "localhost:5000";
8 changes: 4 additions & 4 deletions backend/coronavirus-visualizer-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express from 'express';
import logger from 'morgan';
import { PORT } from './config/constants';
import { PORT, MONGO_DB, HOST } from './config/constants';
import indexRouter from "./routes/index";
import mongoose from 'mongoose';
import {CronJob} from "cron";
Expand All @@ -13,7 +13,7 @@ app.use(logger("dev"));

app.use("/api", indexRouter);

const mongoUri = "mongodb://localhost/corona_visualizer";
const mongoUri = `mongodb://${MONGO_DB}/corona_visualizer`;


mongoose.connect(mongoUri, {
Expand All @@ -24,10 +24,10 @@ mongoose.connect(mongoUri, {
console.log("MongoDB: ", err);
} else {
console.log("Connected to MongoDb");
refreshTimelinesJob();
}
});

refreshTimelinesJob();
// run cron job every full hour - refreshing timelines
const job = new CronJob("0 * * * *", () => {
refreshTimelinesJob();
Expand All @@ -36,6 +36,6 @@ const job = new CronJob("0 * * * *", () => {
job.start();

app.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}`);
console.log(`Server is listening on port${PORT}`);
});

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fetch from "node-fetch";
import { VirusTimelineType, VirusTimelineSchema } from "../models/timeline";
import { VIRUS_DATA_API } from "../config/constants";



Expand All @@ -11,7 +12,7 @@ export const refreshTimelinesJob = async () => {

for (let key in countries) {
for (let api of APIS) {
const url = `http://127.0.0.1:5000/api/timelines/${countries[key]}?api=${api}`;
const url = `http://${VIRUS_DATA_API}/api/timelines/${countries[key]}?api=${api}`;
try {
const response = await fetch(url);
const body = await response.json();
Expand All @@ -32,7 +33,7 @@ export const refreshTimelinesJob = async () => {
break;

} catch (err) {
console.log("error while updating timeline");
console.log("error while updating timeline", err);
}


Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3'
services:
mongo:
image: mongo
virus_server:
image: virus_server
build: ./backend/coronavirus-visualizer-api
environment:
- MONGO_DB=mongo
- VIRUS_DATA_API=virus_data_api:5000
- HOST=0.0.0.0
ports:
- "4000:4000"
virus_data_api:
image: virus_data_api
build: ./DataScraper
ports:
- "5000:5000"

0 comments on commit 0a370d2

Please sign in to comment.