diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a3878b9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,71 @@ +version: "3.9" +services: + redis: + image: "redis" + container_name: "redis" + deploy: + restart_policy: + condition: on-failure + delay: 5s + max_attempts: 3 + window: 120s + networks: + - backend + influx: + image: "influxdb" + container_name: "influx" + deploy: + restart_policy: + condition: on-failure + delay: 5s + max_attempts: 3 + window: 120s + networks: + - backend + mongo: + image: "mongo" + container_name: "mongo" + deploy: + restart_policy: + condition: on-failure + delay: 5s + max_attempts: 3 + window: 120s + networks: + - backend + backend: + build: ./server + container_name: "backend" + deploy: + restart_policy: + condition: on-failure + delay: 5s + max_attempts: 3 + window: 120s + ports: + - "6000:6000" + networks: + - backend + - frontend + depends_on: + - redis + - influx + - mongo + frontend: + build: ./web + container_name: "frontend" + deploy: + restart_policy: + condition: on-failure + delay: 5s + max_attempts: 3 + window: 120s + ports: + - "6001:6001" + networks: + - frontend + depends_on: + - backend +networks: + backend: + frontend: diff --git a/server/config/keys.js b/server/config/keys.js index e2f2414..1937595 100644 --- a/server/config/keys.js +++ b/server/config/keys.js @@ -1,10 +1,10 @@ module.exports = { - influx_url: 'http://0.0.0.0', + influx_uri: 'http://influx:8086', influx_token: '', influx_org: '', influx_bucket: '', redis_user: '', redis_password: '', - redis_host: 'redis', - redis_port: '6379' + redis_uri: 'redis://redis:6379', + mongo_uri: 'mongodb://mongo:27017/user' } \ No newline at end of file diff --git a/server/connections/influx_conn.js b/server/connections/influx_conn.js index f52ca68..868ccf3 100644 --- a/server/connections/influx_conn.js +++ b/server/connections/influx_conn.js @@ -1,10 +1,10 @@ const {InfluxDB} = require('@influxdata/influxdb-client') const chalk = require('chalk') -const {influx_url, influx_token, influx_org, influx_bucket} = require('../config/keys') +const {influx_uri, influx_token, influx_org, influx_bucket} = require('../config/keys') const client = new InfluxDB({ - url: influx_url, + url: influx_uri, token: influx_token, }); @@ -14,6 +14,7 @@ const write = client.getWriteApi( ); const queryApi = client.getQueryApi(influx_org); + console.log(chalk.greenBright.bold('Connected to influx!')) -module.exports = {writeApi: write, queryApi} \ No newline at end of file +module.exports = {write, queryApi} \ No newline at end of file diff --git a/server/connections/mongo_conn.js b/server/connections/mongo_conn.js index e69de29..59bb010 100644 --- a/server/connections/mongo_conn.js +++ b/server/connections/mongo_conn.js @@ -0,0 +1,12 @@ +const mongoose = require('mongoose'); +const chalk = require('chalk') +const {mongo_uri} = require('../config/keys'); + +mongoose.Promise = global.Promise; +mongoose.connect(mongo_uri, { + useNewUrlParser: true, + useUnifiedTopology: true, + useFindAndModify: false, + useCreateIndex: true +}).then(() => console.log(chalk.greenBright.bold('Connected to mongo!'))); + diff --git a/server/connections/redis_conn.js b/server/connections/redis_conn.js index f503316..4d43f91 100644 --- a/server/connections/redis_conn.js +++ b/server/connections/redis_conn.js @@ -1,9 +1,9 @@ const redis = require('redis'); const chalk = require('chalk'); -const {redis_host, redis_port} = require('../config/keys') +const {redis_uri} = require('../config/keys') -const pub = redis.createClient(`redis://${redis_host}:${redis_port}`); +const pub = redis.createClient(redis_uri); const sub = pub.duplicate(); pub.on('error', (error) => { diff --git a/server/docker-compose.yml b/server/docker-compose.yml deleted file mode 100644 index c59e068..0000000 --- a/server/docker-compose.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: "3.9" -services: - redis: - image: "redis:alpine" - networks: - - backend - influx: - image: "influxdb:alpine" - networks: - - backend - volumes: - - /home/xrazis/Documents/random_code/database/influx/:/var/lib/influxdb - backend: - build: "" - ports: - - "6000:6000" - networks: - - backend - depends_on: - - redis - - influx -networks: - backend: diff --git a/server/models/User.js b/server/models/User.js new file mode 100644 index 0000000..e69de29 diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 0000000..8abf7f6 --- /dev/null +++ b/web/Dockerfile @@ -0,0 +1,11 @@ +FROM node:latest + +WORKDIR /usr/src/app + +COPY package*.json ./ + +RUN npm install +COPY . . + +EXPOSE 6000 +CMD [ "npm", "run", "run" ] \ No newline at end of file diff --git a/web/index.js b/web/index.js new file mode 100644 index 0000000..e69de29 diff --git a/web/package.json b/web/package.json new file mode 100644 index 0000000..9306978 --- /dev/null +++ b/web/package.json @@ -0,0 +1,11 @@ +{ + "name": "web", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +}