diff --git a/.travis.yml b/.travis.yml index 2553162..66e4352 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,33 +2,18 @@ language: node_js node_js: - '0.10' -before_script: - - "export DISPLAY=:99.0" - - "sh -e /etc/init.d/xvfb start" - - 'npm install' - - 'npm install -g bower' - - 'npm install -g grunt-cli' - - 'bower install --config.interactive=false' - - cp app/scripts/config.js.dist app/scripts/config.js - - "sudo apt-get remove chromium-browser" - - "echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections" - - "sudo apt-get install ttf-mscorefonts-installer" - - "sudo apt-get install x-ttcidfont-conf" - - "sudo mkfontdir" - - "sudo apt-get install defoma libgl1-mesa-dri xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic" - - "wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" - - "sudo mkdir -p /usr/share/desktop-directories" - - "sudo dpkg -i google-chrome-stable_current_amd64.deb" - - "sudo apt-get install -f" - - "sudo dpkg -i google-chrome-stable_current_amd64.deb" - - "export CHROME_SANDBOX=/opt/google/chrome/chrome-sandbox" - - "sudo rm -f $CHROME_SANDBOX" - - "sudo wget https://googledrive.com/host/0B5VlNZ_Rvdw6NTJoZDBSVy1ZdkE -O $CHROME_SANDBOX" - - "sudo chown root:root $CHROME_SANDBOX; sudo chmod 4755 $CHROME_SANDBOX" - - "sudo md5sum $CHROME_SANDBOX" - - "export DISPLAY=:99.0" - - "Xvfb :99.0 -extension RANDR > /dev/null &" - - "sudo chmod 1777 /dev/shm" +before_install: + - sudo apt-get autoclean -y + - sudo apt-get autoremove -y + +install: + - sudo sh -c "wget -qO- https://get.docker.io/gpg | apt-key add -" + - sudo sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list" + - sudo apt-get update + - echo exit 101 | sudo tee /usr/sbin/policy-rc.d + - sudo chmod +x /usr/sbin/policy-rc.d + - sudo apt-get install -qy slirp lxc lxc-docker + - git clone git://github.com/jpetazzo/sekexe script: - - grunt test-travis + - sekexe/run "`pwd`/docker/scripts/travis.sh `pwd`" diff --git a/Dockerfile b/Dockerfile index ec3d200..8488b70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,25 +2,54 @@ FROM stackbrew/ubuntu:saucy ENV DEBIAN_FRONTEND noninteractive +MAINTAINER Kenny DITS "kenny.dits@m6.fr" +MAINTAINER Jérémy JOURDIN "jjourdin.externe@m6.fr" + RUN apt-get update -y -RUN apt-get install -y git nginx software-properties-common python-software-properties python g++ make bzip2 +RUN apt-get upgrade -y +RUN apt-get install -y wget git nginx software-properties-common python-software-properties python g++ make bzip2 +RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - +RUN sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' RUN apt-add-repository ppa:chris-lea/node.js RUN apt-get update -y -RUN apt-get install -y nodejs +RUN apt-get install -y --force-yes x11vnc openjdk-7-jre-headless google-chrome-stable xvfb nodejs xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic -ADD . /var/www +ADD . /var/www/tmp +ADD ./docker/scripts /var/www/scripts -WORKDIR /var/www +WORKDIR /var/www/tmp + +RUN cp docker/config.js.dist app/scripts/config.js RUN npm install -RUN npm install grunt -RUN npm install -g bower grunt-cli -RUN bower install --allow-root +RUN ./node_modules/.bin/bower install --allow-root -RUN cp app/scripts/config.js.dist app/scripts/config.js -RUN grunt build +# RUN ./node_modules/.bin/webdriver-manager update +RUN ./node_modules/.bin/grunt build ADD docker/nginx-vhost.conf /etc/nginx/sites-available/default -CMD ["-g", "daemon off;"] -ENTRYPOINT ["/usr/sbin/nginx"] \ No newline at end of file +RUN mv dist ../prod + +WORKDIR /var/www + +RUN rm -rf tmp + +RUN echo "daemon off;" >> /etc/nginx/nginx.conf + +RUN mkdir ~/.vnc + +VOLUME ['/var/www/dev'] + +EXPOSE 21 80 + +ENV DISPLAY :99 + +ENV BABITCH_WS_URL http://127.0.0.1:8081/app_dev.php/v1 +ENV BABITCH_LIVE_FAYE_URL http://faye-babitch.herokuapp.com/faye +ENV BABITCH_LIVE_FAYE_CHANNEL /test-channel-to-replace +ENV BABITCH_STATS_MIN_GAME_PLAYED 2 + +CMD ["prod"] + +ENTRYPOINT ["/var/www/scripts/starter.sh"] diff --git a/README.md b/README.md index 1f499aa..98de300 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ BabitchClient provides a simple responsive user interface. ![Babitch Screenshot](screenshot.png) +## Documentation + +Learn how to get your own private BabitchClient by reading our [documentation](./doc/). + ## Features * 2VS2 @@ -16,60 +20,6 @@ BabitchClient provides a simple responsive user interface. * Gravatar support * Lot of Stats by players and team -## Installation - -### Clone the project - -``` -$ git clone https://github.com/M6Web/BabitchClient.git -$ cd BabitchClient -$ cp app/scripts/config.js.dist app/scripts/config.js -``` - -### For production purposes -* Install the Babitch Server API => [M6Web/Babitch](https://github.com/M6Web/Babitch) -* Go to app/scripts/config.js and change server config - -``` -$ bower install -$ grunt build -``` - -Then, - -* Configure a Web Server (Apache/Nginx/...) with the `dist` folder as the doc root -* Launch `/` in a browser - -### For dev purposes -``` -$ npm install -$ bower install -$ grunt serve -``` -Then go to `http://127.0.0.1:8080/`, - -You have two options for the server side : - -* Install the Babitch Server API => [M6Web/Babitch](https://github.com/M6Web/Babitch) and change `app/scripts/config.js` -* Use the faked backend by adding `?nobackend` to the BabitchClient url - -#### Test (Unit & E2E) - -Only unit test : -* `grunt test-unit` - -Only E2E test : -* `grunt test-e2e` - -All test : -* `grunt test` - -## Live - -You need to configure `BABITCH_LIVE_FAYE_URL` and `BABITCH_LIVE_FAYE_CHANNEL` in `app/scripts/config.js` - -* User interface : `http://127.0.0.1:8080/#live` - ## Technical Stack * Yeoman, to boostrap the application @@ -79,18 +29,6 @@ You need to configure `BABITCH_LIVE_FAYE_URL` and `BABITCH_LIVE_FAYE_CHANNEL` in * Faye for realtime messaging * D3.js for data visualization -## Docker - -To use the `Dockerfile` in this repository, just clone and run (at the root): - - docker build -t m6web/babitch-client . - -Then run the container: - - docker run -p 8000:80 m6web/babitch-client - -You now have a BabitchClient listening on port `8000`! - ## Credits Developped by [M6 Web](http://tech.m6web.fr/). diff --git a/doc/contribute.md b/doc/contribute.md new file mode 100644 index 0000000..9a9d6c8 --- /dev/null +++ b/doc/contribute.md @@ -0,0 +1,17 @@ +# Contribute to BabitchClient + +Help us to improve the application by: + +* Giving us a feedback using Github Issues +* Sending us pull requests (with related tests) + +## Launch Tests (Unit & E2E) + +Only unit test : +* `./node_modules/.bin/grunt test-unit` + +Only E2E test : +* `./node_modules/.bin/grunt test-e2e` + +All test : +* `./node_modules/.bin/grunt test` \ No newline at end of file diff --git a/doc/index.md b/doc/index.md new file mode 100644 index 0000000..d9d060a --- /dev/null +++ b/doc/index.md @@ -0,0 +1,9 @@ +# BabitchClient Documentation + +* Install +..* [With GIT](./install/git.md) +..* [With Docker](./install/docker.md) +* Use +..* [With GIT](./use/git.md) +..* [With Docker](./use/docker.md) +* [Contribute](./contribute.md) \ No newline at end of file diff --git a/doc/install/docker.md b/doc/install/docker.md new file mode 100644 index 0000000..1d62675 --- /dev/null +++ b/doc/install/docker.md @@ -0,0 +1,13 @@ +# Install with Docker + +You have to do this step only if you wan't to build your own custom image, otherwise go to [the next step](../usage/docker.md). + +## Prepare image + +Follow the [GIT Installation process](./git.md). + +## Build image + +```shell +$ docker build -t m6web/babitch-client . +``` \ No newline at end of file diff --git a/doc/install/git.md b/doc/install/git.md new file mode 100644 index 0000000..bbf4633 --- /dev/null +++ b/doc/install/git.md @@ -0,0 +1,33 @@ +# Install with GIT + +## Clone the project + +```shell +$ git clone https://github.com/M6Web/BabitchClient.git +``` + +## Configure + +```shell +$ cd BabitchClient +$ cp app/scripts/config.js.dist app/scripts/config.js +``` + +Then edit app/scripts/config.js to match your requirements + +## For production purposes + +* Install the Babitch Server API => [M6Web/Babitch](https://github.com/M6Web/Babitch) +* Go to app/scripts/config.js and change server config + +``` +$ ./node_modules/.bin/bower install +$ ./node_modules/.bin/grunt build +``` + +## For dev purposes + +``` +$ npm install +$ ./node_modules/.bin/bower install +``` \ No newline at end of file diff --git a/doc/use/docker.md b/doc/use/docker.md new file mode 100644 index 0000000..18c5287 --- /dev/null +++ b/doc/use/docker.md @@ -0,0 +1,38 @@ +# Usage of Docker version + +## Development mode + +This mode make contribution easier, it run the container with the following component: + +- X11VNC: VNC Server used to render browser while protractor is running (port binding: `-p :5999`) +- XVFB: Virtual frame buffer used to simulate a display for protractor purposes +- ProFTPd: FTP server used to edit files in container from your favorite editor (port binding: `-p :21`) + +There is no Nginx running on dev mode as your will prefer to use `grunt serve` for development purpose. + +```shell +$ sudo docker run --privileged -t -i -p 8000:80 -p 5999:5999 -p 2121:21 m6web/babitch-client dev +``` + +## Production mode + +This mode provide a lightweight server, it run the container with the following component: + +- Nginx: Web server (port binding: `-p :80`) + +```shell +$ sudo docker run --privileged -t -i -p 8000:80 m6web/babitch-client prod +``` + +You now have a BabitchClient listening on port `8000`! + +## Test mode + +This mode simply launch test suites, it run the container with the following component: + +- X11VNC: VNC Server used to render browser while protractor is running (port binding: `-p :5999`) +- XVFB: Virtual frame buffer used to simulate a display for protractor purposes + +```shell +$ sudo docker run --privileged -t -i -p 5999:5999 m6web/babitch-client test +``` \ No newline at end of file diff --git a/doc/use/git.md b/doc/use/git.md new file mode 100644 index 0000000..c2e5342 --- /dev/null +++ b/doc/use/git.md @@ -0,0 +1,21 @@ +## Usage of GIT version + +## For production purposes + +* Configure a Web Server (Apache/Nginx/...) with the `dist` folder as the doc root +* Launch `/` in a browser + +### For dev purposes + +Launch: + +``` +$ grunt serve +``` + +Then go to `http://127.0.0.1:8080/`, + +You have two options for the server side : + +* Install the Babitch Server API => [M6Web/Babitch](https://github.com/M6Web/Babitch) and change `app/scripts/config.js` +* Use the faked backend by adding `?nobackend` to the BabitchClient url \ No newline at end of file diff --git a/docker/config.js.dist b/docker/config.js.dist new file mode 100644 index 0000000..1249f89 --- /dev/null +++ b/docker/config.js.dist @@ -0,0 +1,9 @@ +'use strict'; + +angular.module('babitchServer', []) + .constant('CONFIG', { + 'BABITCH_WS_URL': '%BABITCH_WS_URL%', + 'BABITCH_LIVE_FAYE_URL' :'%BABITCH_LIVE_FAYE_URL%', + 'BABITCH_LIVE_FAYE_CHANNEL' :'%BABITCH_LIVE_FAYE_CHANNEL%', + 'BABITCH_STATS_MIN_GAME_PLAYED' : '%BABITCH_STATS_MIN_GAME_PLAYED%' + }); diff --git a/docker/nginx-vhost.conf b/docker/nginx-vhost.conf index eadeda7..9d4293f 100644 --- a/docker/nginx-vhost.conf +++ b/docker/nginx-vhost.conf @@ -1,4 +1,4 @@ server { listen 80; - root /var/www/dist/; + root /var/www/prod/; } \ No newline at end of file diff --git a/docker/scripts/starter.sh b/docker/scripts/starter.sh new file mode 100755 index 0000000..47269a1 --- /dev/null +++ b/docker/scripts/starter.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +sed -i -e "s|%BABITCH_WS_URL%|${BABITCH_WS_URL}|"\ + -e "s|%BABITCH_LIVE_FAYE_URL%|${BABITCH_LIVE_FAYE_URL}|"\ + -e "s|%BABITCH_LIVE_FAYE_CHANNEL%|${BABITCH_LIVE_FAYE_CHANNEL}|"\ + -e "s|%BABITCH_STATS_MIN_GAME_PLAYED%|${BABITCH_STATS_MIN_GAME_PLAYED}|"\ + prod/scripts/*.scripts.js + +case "$1" in + "prod") + service nginx start + ;; + "dev") + if [ ! -d "/var/www/dev" ] + then + echo "[Error] No dev volume mounted." + exit 1 + fi + cd /var/www/dev + /var/www/scripts/xvfb.sh start + /var/www/scripts/x11vnc.sh start + /bin/bash + ;; + "test") + if [ ! -d "/var/www/dev" ] + then + echo "[Error] No dev volume mounted." + exit 1 + fi + cd /var/www/dev + /var/www/scripts/xvfb.sh start + /var/www/scripts/x11vnc.sh start + /var/www/dev/node_modules/.bin/grunt test + exit $? + ;; +esac \ No newline at end of file diff --git a/docker/scripts/travis.sh b/docker/scripts/travis.sh new file mode 100755 index 0000000..c67c2bb --- /dev/null +++ b/docker/scripts/travis.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Exit on first error +set -e + +# Mount rount +mount -t tmpfs none /root + +# Kill background processes on exit +trap 'kill $(jobs -p)' SIGINT SIGTERM EXIT + +# Workaround with cgroup for recent version of docker +cgroups-umount +cgroups-mount + +# Start docker daemon +docker -d & +sleep 2 + +# Use docker +docker build -t babitch_client_travis $1 +docker run --privileged -it --rm -v $1:/var/www/dev babitch_client_travis test \ No newline at end of file diff --git a/docker/scripts/x11vnc.sh b/docker/scripts/x11vnc.sh new file mode 100755 index 0000000..06b756a --- /dev/null +++ b/docker/scripts/x11vnc.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +X11VNC=/usr/bin/x11vnc +X11VNCARGS="-display $DISPLAY -N -forever" +PIDFILE=/var/run/x11vnc.pid +case "$1" in + start) + echo -n "Starting VNC Server: X11VNC" + start-stop-daemon --start --pidfile $PIDFILE --make-pidfile --background --exec $X11VNC -- $X11VNCARGS + echo "." + ;; + stop) + echo -n "Stopping VNC Server: X11VNC" + start-stop-daemon --stop --pidfile $PIDFILE + echo "." + ;; + restart) + $0 stop + $0 start + ;; +esac + +exit 0 \ No newline at end of file diff --git a/docker/scripts/xvfb.sh b/docker/scripts/xvfb.sh new file mode 100755 index 0000000..1f40d86 --- /dev/null +++ b/docker/scripts/xvfb.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +XVFB=/usr/bin/Xvfb +XVFBARGS="$DISPLAY -shmem -screen 0 1366x768x16" +PIDFILE=/var/run/xvfb.pid +case "$1" in + start) + echo -n "Starting virtual X frame buffer: Xvfb" + start-stop-daemon --start --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS + echo "." + ;; + stop) + echo -n "Stopping virtual X frame buffer: Xvfb" + start-stop-daemon --stop --pidfile $PIDFILE + echo "." + ;; + restart) + $0 stop + $0 start + ;; + *) + echo "Usage: /etc/init.d/xvfb {start|stop|restart}" + exit 1 +esac + +exit 0 \ No newline at end of file diff --git a/package.json b/package.json index f1a5398..a377db3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,9 @@ "name": "babitchfrontend", "version": "0.0.0", "dependencies": { - "faye": "~1.0.1" + "faye": "~1.0.1", + "bower": "~1.3.5", + "grunt-cli": "~0.1.13" }, "devDependencies": { "grunt": "~0.4.1",