diff --git a/README.md b/README.md index 659693b04..0e02ec440 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,27 @@ It will start a local server using `webpack-dev-server` which will watch, build * single run: `npm run build` * build files and watch: `npm start` +## Docker support + +* run: `cd containers && ./build.sh && ./run.sh && cd ..` +* test: curl http://localhost:4000/ +* stop: `./containers/stop.sh` + +Container name and port can be specified: + +`cd containers +./build.sh [CONTAINER] [DIR] +./run.sh [CONTAINER] [PORT] +./stop.sh [CONTAINER]` + +DIR is a directory for Dockerfile inside of containers folder. For example to create separated container for database: + +* Create directory, for example "mongodb" of containers folder +* Create Dockerfile for MongoDB inside +* Build it like: ./build.sh mongo mongodb +* Finally run it: ./run.sh mongo 5000 +* Stop: ./stop.sh mongo + ## Testing #### 1. Unit Tests diff --git a/containers/build.sh b/containers/build.sh new file mode 100755 index 000000000..b606770b4 --- /dev/null +++ b/containers/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +CONTAINER=$([ $# -lt 1 ] && echo angularjs-webpack || echo $1) +DIR=$([ $# -lt 2 ] && echo web-client || echo $2) + +docker build -f $DIR/Dockerfile -t $CONTAINER ../ + diff --git a/containers/run.sh b/containers/run.sh new file mode 100755 index 000000000..8f73284e1 --- /dev/null +++ b/containers/run.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +CONTAINER=$([ $# -lt 1 ] && echo angularjs-webpack || echo $1) +PORT=$([ $# -lt 2 ] && echo 4000 || echo $2) + +docker run -d -p $PORT:8080 $CONTAINER \ No newline at end of file diff --git a/containers/stop.sh b/containers/stop.sh new file mode 100755 index 000000000..ea4e1f8ca --- /dev/null +++ b/containers/stop.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +CONTAINER=$([ $# -lt 1 ] && echo angularjs-webpack || echo $1) + +docker stop $(docker ps -q --filter ancestor=$CONTAINER) \ No newline at end of file diff --git a/containers/web-client/Dockerfile b/containers/web-client/Dockerfile new file mode 100644 index 000000000..1c4ae20c6 --- /dev/null +++ b/containers/web-client/Dockerfile @@ -0,0 +1,18 @@ +FROM ubuntu:14.04 + +RUN apt-get update; apt-get install -y apt-transport-https curl; curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - +RUN apt-get update; apt-get install -y --force-yes nodejs git ssh-client + +# Set the working directory to /app +WORKDIR /app + +# Copy the current directory contents into the container at /app +ADD . /app + +RUN npm install +RUN npm run build +COPY server.js ./dist/server.js + +CMD cd dist && node server.js + +EXPOSE 8080 \ No newline at end of file diff --git a/package.json b/package.json index c1c1569f6..243be8bc2 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "rimraf": "^2.5.1", "style-loader": "^0.13.0", "webpack": "2.2.0", - "webpack-dev-server": "2.2.0" + "webpack-dev-server": "2.2.0", + "express": "^4.15.2" } } diff --git a/server.js b/server.js new file mode 100644 index 000000000..88e85bf42 --- /dev/null +++ b/server.js @@ -0,0 +1,16 @@ +var express = require('express'); +var app = express(); +var fs = require('fs'); +var port = 8080; + +app.get('/', function(req, res) { + fs.readFile('./index.html', function (err, data) { + res.send( data.toString()); + }); +}); + +app.use(express.static('.')); + +app.listen(port); + +console.log('Listening on port ' + port);