Browse Source

👕 Change configuration to run on docker

main
Haris Razis 4 years ago
parent
commit
aa3b4f87c8
No known key found for this signature in database GPG Key ID: 86A4D290ED03FAB4
  1. 71
      docker-compose.yml
  2. 6
      server/config/keys.js
  3. 7
      server/connections/influx_conn.js
  4. 12
      server/connections/mongo_conn.js
  5. 4
      server/connections/redis_conn.js
  6. 23
      server/docker-compose.yml
  7. 0
      server/models/User.js
  8. 11
      web/Dockerfile
  9. 0
      web/index.js
  10. 11
      web/package.json

71
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:

6
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'
}

7
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}
module.exports = {write, queryApi}

12
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!')));

4
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) => {

23
server/docker-compose.yml

@ -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:

0
server/models/User.js

11
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" ]

0
web/index.js

11
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"
}
Loading…
Cancel
Save