Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/docker support #87

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions containers/build.sh
Original file line number Diff line number Diff line change
@@ -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 ../

6 changes: 6 additions & 0 deletions containers/run.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions containers/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

CONTAINER=$([ $# -lt 1 ] && echo angularjs-webpack || echo $1)

docker stop $(docker ps -q --filter ancestor=$CONTAINER)
18 changes: 18 additions & 0 deletions containers/web-client/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
16 changes: 16 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -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);