瀏覽代碼

Added Docker setup, which should eventually replace the Vagrant setup

Cameron Kline 8 年之前
父節點
當前提交
807db6a7c2
共有 7 個文件被更改,包括 101 次插入6 次删除
  1. 23 0
      backend/Dockerfile
  2. 3 5
      backend/app.js
  3. 4 0
      backend/package.json
  4. 20 0
      docker-compose.yml
  5. 1 1
      frontend/App.vue
  6. 26 0
      frontend/Dockerfile
  7. 24 0
      frontend/nginx.conf

+ 23 - 0
backend/Dockerfile

@@ -0,0 +1,23 @@
+FROM alpine
+
+RUN apk update && apk upgrade
+RUN apk add openssl
+RUN apk add curl
+RUN apk add git
+RUN apk add python
+RUN apk add nodejs
+RUN apk add gcc
+RUN apk add g++
+RUN apk add make
+
+RUN npm install nodemon -g
+
+RUN mkdir -p /opt
+WORKDIR /opt
+ADD package.json /opt/package.json
+
+RUN npm install
+
+EXPOSE 80
+
+CMD npm run development

+ 3 - 5
backend/app.js

@@ -5,7 +5,7 @@ const path = require('path'),
       fs   = require('fs'),
       os   = require('os');
 
-process.env.NODE_CONFIG_DIR = `${process.cwd()}/config`;
+process.env.NODE_CONFIG_DIR = `${__dirname}/config`;
 
 // npm modules
 const express          = require('express'),
@@ -26,7 +26,7 @@ const express          = require('express'),
 const global = require('./logic/global');
 
 // database
-const MongoDB = mongoose.connect('mongodb://localhost:27017/musare').connection;
+const MongoDB = mongoose.connect('mongodb://172.16.0.1:27017/musare').connection;
 
 MongoDB.on('error', (err) => {
 	console.log('Database error: ' + err.message);
@@ -113,9 +113,7 @@ function setupExpress() {
 	app.use(bodyParser.urlencoded({
 		extended: true
 	}));
-
-	app.use(express.static(__dirname + '/../frontend/build/'));
-
+	
 	app.get('*', (req, res) => {
 		res.redirect('/');
 	});

+ 4 - 0
backend/package.json

@@ -5,6 +5,10 @@
   "main": "app.js",
   "author": "Musare Team",
   "repository": "https://github.com/Musare/MusareNode",
+  "scripts": {
+    "development": "nodemon -L /opt/app",
+    "production": "node /opt/app/app.js"
+  },
   "dependencies": {
     "async": "2.0.1",
     "bcrypt": "^0.8.7",

+ 20 - 0
docker-compose.yml

@@ -0,0 +1,20 @@
+version: '2'
+services:
+  backend:
+    build: ./backend
+    ports:
+    - "8081:80"
+    volumes:
+    - ./backend:/opt/app
+    links:
+    - mongo
+  frontend:
+    build: ./frontend
+    ports:
+    - "8080:80"
+    volumes:
+    - ./frontend:/opt/app
+  mongo:
+    image: mongo
+    ports:
+    - "27017:27017"

+ 1 - 1
frontend/App.vue

@@ -101,7 +101,7 @@
 		},
 		ready: function () {
 			let local = this;
-			local.socket = io();
+			local.socket = io(window.location.protocol + '//' + window.location.hostname + ':8081');
 			local.socket.on("ready", status => {
 				local.loggedIn = status;
 				local.socket.emit("/user/ratings", result => {

+ 26 - 0
frontend/Dockerfile

@@ -0,0 +1,26 @@
+FROM alpine
+
+RUN apk update && apk upgrade
+RUN apk add openssl
+RUN apk add curl
+RUN apk add git
+RUN apk add python
+RUN apk add nodejs
+RUN apk add gcc
+RUN apk add g++
+RUN apk add make
+RUN apk add nginx
+
+RUN npm install -g webpack
+
+RUN mkdir -p /opt
+WORKDIR /opt
+ADD package.json /opt/package.json
+
+RUN npm install
+
+RUN mkdir -p /run/nginx
+
+EXPOSE 80
+
+CMD nginx -c /opt/app/nginx.conf; cd /opt/app; npm run development-watch

+ 24 - 0
frontend/nginx.conf

@@ -0,0 +1,24 @@
+worker_processes  1;
+
+events {
+    worker_connections  1024;
+}
+
+http {
+    include       /etc/nginx/mime.types;
+    default_type  application/octet-stream;
+
+    sendfile        on;
+
+    keepalive_timeout  65;
+
+    server {
+        listen       80;
+        server_name  localhost;
+
+        location / {
+            root   /opt/app/build;
+            index  index.html;
+        }
+    }
+}