Skip to content

Commit

Permalink
Fully Dockerized!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
kvizdos committed Aug 14, 2019
1 parent 7bd02bf commit 797bd2f
Show file tree
Hide file tree
Showing 13 changed files with 2,266 additions and 60 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
@@ -0,0 +1,10 @@
node_modules
npm-debug.log
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
LICENSE
.vscode
11 changes: 11 additions & 0 deletions Dockerfile
@@ -0,0 +1,11 @@
FROM node:10
WORKDIR /usr/src/homerouter

COPY package*.json ./

RUN npm install
COPY . .

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

EXPOSE 80
5 changes: 4 additions & 1 deletion auth/auth.js
@@ -1,8 +1,11 @@
// Install body-parser and Express
const express = require('express')
const app = express()

const _MongoConfig = require('../db/mongo');
const MongoClient = require('mongodb').MongoClient;
const url = "mongodb://localhost:27017/";
// const url = "mongodb://127.0.0.1:27017/";
const url = _MongoConfig.url;

const request = require('request');

Expand Down
5 changes: 4 additions & 1 deletion auth/confirmAuth.js
@@ -1,7 +1,10 @@
let cachedTokens = [];


const _MongoConfig = require('../db/mongo');
const MongoClient = require('mongodb').MongoClient;
const url = "mongodb://localhost:27017/";
// const url = "mongodb://127.0.0.1:27017/";
const url = _MongoConfig.url;

class Authenticator {
constructor(redis) {
Expand Down
10 changes: 5 additions & 5 deletions config.js
@@ -1,11 +1,11 @@
const config = function() {
this.ports = {
dashboard: 8081,
auth: 8082,
unauthed: 8083,
proxy: 80
dashboard: process.env.DASHPORT || 8081,
auth: process.env.AUTHPORT || 8082,
unauthed: process.env.DEAUTHPORT || 8083,
proxy: process.env.PORT || 80
},
this.baseURL = "home.kentonvizdos.com",
this.baseURL = process.env.URL || "home.kentonvizdos.com",
this.protocol = "http",
this.createURL = (app = "", noProto = false) => {
return `${!noProto ? this.protocol + "://" : ""}${app != "" ? app + "." : ""}${this.baseURL}`
Expand Down
24 changes: 22 additions & 2 deletions dashboard/dashboard.js
Expand Up @@ -6,17 +6,28 @@ var bodyParser = require('body-parser')
var multer = require('multer');
var fs = require("fs");

const _MongoConfig = require('../db/mongo');
const MongoClient = require('mongodb').MongoClient;
const url = "mongodb://localhost:27017/";
// const url = "mongodb://127.0.0.1:27017/";
const url = _MongoConfig.url;

console.log("Dashboard Starting (loading Redis)")

const _REDIS = new (require('../db/redis'))();

console.log("Dashboard Starting (Redis loaded)")

const _AUTH = new (require('../auth/confirmAuth'))(_REDIS);

console.log("Dashboard Starting (Auth loaded)")

const _PM = require('../proxy/proxy');
const _AUTHMODULE = require('../auth/auth');

const _CONF = require('../config');

console.log("Dashboard Starting (Everything lOaded)")

// Use req.query to read values!!
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
Expand Down Expand Up @@ -87,5 +98,14 @@ app.get("/*", (req, res) => {
res.sendFile("./dashboard/frontend/index.html", {root: "./"})
})

console.log("Trying to publish to :" + _CONF.ports.dashboard)


app.listen(_CONF.ports.dashboard, () => console.log('Dashboard Server Started'))
try {
app.listen(_CONF.ports.dashboard, (err) =>{
if(err) throw err;
console.log('Dashboard Server Started')
})
} catch(err) {
console.log(err)
}
3 changes: 3 additions & 0 deletions db/mongo.js
@@ -0,0 +1,3 @@
module.exports = {
'url': 'mongodb://homerouter-mongo:27017'
}
16 changes: 15 additions & 1 deletion db/redis.js
Expand Up @@ -2,7 +2,21 @@ const redis = require('redis')

class RedisManager {
constructor() {
this.client = redis.createClient();
try {
// this.client = new redis({host:})
this.client = redis.createClient({host: 'redis'});
} catch(err) {
console.log(err);
}
this.client.on("error", function (err) {
console.log("Error " + err);
});

this.client.on("connect", () => {
console.log("Connected to Redis")
})


}

set(key, val) {
Expand Down
30 changes: 30 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,30 @@
version: '3.3'
services:
mongo:
container_name: homerouter-mongo
image: 'mongo:4'
ports:
- 27017:27017
redis:
container_name: homerouter-redis
image: 'redis:5'
command: redis-server
ports:
- 6376:6379
homerouter:
privileged: true
container_name: homerouter
restart: on-failure
build: .
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules
ports:
- 80:80
links:
- redis
- mongo
depends_on:
- redis
- mongo
command: npm start
Binary file added dump.rdb
Binary file not shown.

0 comments on commit 797bd2f

Please sign in to comment.