From b56d357ef70f13895d4231e2c6dca14c6bb64d88 Mon Sep 17 00:00:00 2001 From: DefeNder93 Date: Sat, 9 Sep 2017 16:12:24 +0800 Subject: [PATCH 1/6] docker support was added --- README.md | 6 ++++++ containers/build.sh | 4 ++++ containers/run.sh | 4 ++++ containers/stop.sh | 3 +++ containers/web-client/Dockerfile | 15 +++++++++++++++ package.json | 2 +- webpack.config.js | 2 +- 7 files changed, 34 insertions(+), 2 deletions(-) create mode 100755 containers/build.sh create mode 100755 containers/run.sh create mode 100755 containers/stop.sh create mode 100644 containers/web-client/Dockerfile diff --git a/README.md b/README.md index 659693b04..9abe6ded8 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,12 @@ 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 ..` +* stop: `./containers/stop.sh` +* open http://localhost:4000/ + ## Testing #### 1. Unit Tests diff --git a/containers/build.sh b/containers/build.sh new file mode 100755 index 000000000..edf98742d --- /dev/null +++ b/containers/build.sh @@ -0,0 +1,4 @@ +CONTAINER=angularjs-webpack + +docker build -f web-client/Dockerfile -t $CONTAINER ../ + diff --git a/containers/run.sh b/containers/run.sh new file mode 100755 index 000000000..f8c8a446c --- /dev/null +++ b/containers/run.sh @@ -0,0 +1,4 @@ +CONTAINER=angularjs-webpack +PORT=4000 + +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..2464a98fe --- /dev/null +++ b/containers/stop.sh @@ -0,0 +1,3 @@ +CONTAINER=angularjs-webpack + +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..7fe54a77e --- /dev/null +++ b/containers/web-client/Dockerfile @@ -0,0 +1,15 @@ +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 +CMD ["npm", "start"] + +EXPOSE 8080 \ No newline at end of file diff --git a/package.json b/package.json index c1c1569f6..2f403ed7c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A workflow for Angular made with Webpack", "scripts": { "build": "rimraf dist && webpack --bail --progress --profile", - "server": "webpack-dev-server --history-api-fallback --inline --progress", + "server": "webpack-dev-server --host 0.0.0.0 --port 8080 --history-api-fallback --inline --progress", "test": "karma start", "test-watch": "karma start --auto-watch --no-single-run", "start": "npm run server" diff --git a/webpack.config.js b/webpack.config.js index 0178162d6..905814f74 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -45,7 +45,7 @@ module.exports = function makeWebpackConfig() { // Output path from the view of the page // Uses webpack-dev-server in development - publicPath: isProd ? '/' : 'http://localhost:8080/', + publicPath: '/', // Filename for entry points // Only adds hash in build mode From 0b0a6782a9b8fadb9d4f7fd0fa86858ddf2d8211 Mon Sep 17 00:00:00 2001 From: DefeNder93 Date: Sat, 9 Sep 2017 16:14:01 +0800 Subject: [PATCH 2/6] fix readme section --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9abe6ded8..1925804fb 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ 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 +## Docker support * run: `cd containers && ./build.sh && ./run.sh && cd ..` * stop: `./containers/stop.sh` From cdd79f6c982f390ddbd082dea951dde2b63aae9a Mon Sep 17 00:00:00 2001 From: DefeNder93 Date: Sat, 9 Sep 2017 16:15:24 +0800 Subject: [PATCH 3/6] fix readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1925804fb..931354c11 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,8 @@ It will start a local server using `webpack-dev-server` which will watch, build ## Docker support * run: `cd containers && ./build.sh && ./run.sh && cd ..` -* stop: `./containers/stop.sh` * open http://localhost:4000/ +* stop: `./containers/stop.sh` ## Testing From e1b042f99cda564383c675053daf9758e8b49a60 Mon Sep 17 00:00:00 2001 From: DefeNder93 Date: Sat, 9 Sep 2017 16:16:39 +0800 Subject: [PATCH 4/6] fix readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 931354c11..6b342321b 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ It will start a local server using `webpack-dev-server` which will watch, build ## Docker support * run: `cd containers && ./build.sh && ./run.sh && cd ..` -* open http://localhost:4000/ +* test: curl http://localhost:4000/ * stop: `./containers/stop.sh` ## Testing From f98d44ed931d8b6377f679980b656ed76b9c3ab2 Mon Sep 17 00:00:00 2001 From: DefeNder93 Date: Mon, 11 Sep 2017 11:45:59 +0800 Subject: [PATCH 5/6] settings for containers was added, build was changed to production, express web server was added --- README.md | 15 +++++++++++++++ containers/build.sh | 7 +++++-- containers/run.sh | 8 +++++--- containers/stop.sh | 4 +++- containers/web-client/Dockerfile | 5 ++++- package.json | 3 ++- server.js | 16 ++++++++++++++++ webpack.config.js | 2 +- 8 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 server.js diff --git a/README.md b/README.md index 6b342321b..0e02ec440 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,21 @@ It will start a local server using `webpack-dev-server` which will watch, build * 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 index edf98742d..b606770b4 100755 --- a/containers/build.sh +++ b/containers/build.sh @@ -1,4 +1,7 @@ -CONTAINER=angularjs-webpack +#!/bin/bash -docker build -f web-client/Dockerfile -t $CONTAINER ../ +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 index f8c8a446c..8f73284e1 100755 --- a/containers/run.sh +++ b/containers/run.sh @@ -1,4 +1,6 @@ -CONTAINER=angularjs-webpack -PORT=4000 +#!/bin/bash -docker run -d -p $PORT:8080 $CONTAINER \ No newline at end of file +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 index 2464a98fe..ea4e1f8ca 100755 --- a/containers/stop.sh +++ b/containers/stop.sh @@ -1,3 +1,5 @@ -CONTAINER=angularjs-webpack +#!/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 index 7fe54a77e..1c4ae20c6 100644 --- a/containers/web-client/Dockerfile +++ b/containers/web-client/Dockerfile @@ -10,6 +10,9 @@ WORKDIR /app ADD . /app RUN npm install -CMD ["npm", "start"] +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 2f403ed7c..a146bd6b3 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); diff --git a/webpack.config.js b/webpack.config.js index 905814f74..0178162d6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -45,7 +45,7 @@ module.exports = function makeWebpackConfig() { // Output path from the view of the page // Uses webpack-dev-server in development - publicPath: '/', + publicPath: isProd ? '/' : 'http://localhost:8080/', // Filename for entry points // Only adds hash in build mode From c214f2ec7383a86889f09fe4af072e370c52381d Mon Sep 17 00:00:00 2001 From: DefeNder93 Date: Mon, 11 Sep 2017 11:48:46 +0800 Subject: [PATCH 6/6] revert of npm script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a146bd6b3..243be8bc2 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A workflow for Angular made with Webpack", "scripts": { "build": "rimraf dist && webpack --bail --progress --profile", - "server": "webpack-dev-server --host 0.0.0.0 --port 8080 --history-api-fallback --inline --progress", + "server": "webpack-dev-server --history-api-fallback --inline --progress", "test": "karma start", "test-watch": "karma start --auto-watch --no-single-run", "start": "npm run server"