Skip to content
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
41 changes: 38 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
# Builds a Docker to deliver dist/
FROM nginx:latest
COPY dist/ /usr/share/nginx/html
FROM node:5

MAINTAINER [email protected]

ARG USERID=1000

RUN usermod -u $USERID www-data && \
mkdir -p /var/www && \
mkdir -p /app && \
chown -R www-data:www-data /var/www && \
chown -R www-data:www-data /app

RUN npm config set registry https://registry.npmjs.org/ && \
npm install --allow-root -g -d --silent \
webpack \
webpack-merge \
webpack-dev-server \
karma \
protractor \
typescript \
rimraf

USER www-data

ADD package.json /app/package.json

RUN cd /app/ && \
npm cache clear && \
npm config set registry https://registry.npmjs.org/ && \
/usr/local/bin/node --stack-size=192000 /usr/local/bin/npm install --no-bin-links --quiet

EXPOSE 3000 8080

WORKDIR /var/www/frontend

COPY entrypoint.sh /entrypoint.sh

CMD ["/bin/bash", "/entrypoint.sh"]
2 changes: 1 addition & 1 deletion config/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin');
* Webpack Constants
*/
const ENV = process.env.ENV = process.env.NODE_ENV = 'development';
const HOST = process.env.HOST || 'localhost';
const HOST = process.env.HOST || '0.0.0.0';
const PORT = process.env.PORT || 3000;
const HMR = helpers.hasProcessFlag('hot');
const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, {
Expand Down
2 changes: 1 addition & 1 deletion config/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const WebpackMd5Hash = require('webpack-md5-hash');
* Webpack Constants
*/
const ENV = process.env.NODE_ENV = process.env.ENV = 'production';
const HOST = process.env.HOST || 'localhost';
const HOST = process.env.HOST || '0.0.0.0';
const PORT = process.env.PORT || 8080;
const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, {
host: HOST,
Expand Down
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
frontend:
image: $APP_NAME:$APP_VERSION
volumes:
- .:/var/www/frontend

hub:
image: selenium/hub
environment:
- GRID_TIMEOUT=30000

firefox:
image: selenium/node-firefox
links:
- hub
- frontend
environment:
SCREEN_WIDTH: "1366"
SCREEN_HEIGHT: "768"

chrome:
image: selenium/node-chrome
links:
- hub
- frontend
environment:
SCREEN_WIDTH: "1366"
SCREEN_HEIGHT: "768"
119 changes: 119 additions & 0 deletions docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/bin/bash

export TASK_NAME=$1;
export APP_VERSION=$(echo $(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",\r]//g'))
echo "App image version: $APP_VERSION"
export APP_NAME=$(echo $(cat package.json | grep name | head -1 | awk -F: '{ print $2 }' | sed 's/[",\r]//g'))
echo $APP_NAME;
export USERID=$(id -u);
echo "User ID: $USERID";

function runBashInsideImage {
docker-compose run --service-ports --entrypoint /bin/bash frontend
}

function buildProject {
if docker history -q "${APP_NAME}:${APP_VERSION}" > /dev/null 2>&1; then
echo "${APP_NAME}:${APP_VERSION} exists"
else
docker build -t "${APP_NAME}:${APP_VERSION}" --build-arg USERID=$USERID .
fi
docker-compose kill > /dev/null 2>&1
docker-compose rm -f -v > /dev/null 2>&1
BUILD_STATUS=$(docker-compose up frontend)
docker-compose kill > /dev/null 2>&1
docker-compose rm -f -v > /dev/null 2>&1
echo "$BUILD_STATUS";
if echo "$BUILD_STATUS" | grep -q "exited with code 1"; then
return 1;
else
return 0;
fi
}

function runUnitTests {
if ! docker history -q "${APP_NAME}:${APP_VERSION}" > /dev/null 2>&1; then
buildProject
fi

docker-compose kill > /dev/null 2>&1
docker-compose rm -f -v > /dev/null 2>&1
BUILD_STATUS=`docker-compose up unit`
docker-compose kill > /dev/null 2>&1
docker-compose rm -f -v > /dev/null 2>&1
echo "$BUILD_STATUS";
if echo "$BUILD_STATUS" | grep -q "exited with code 1"; then
return 1;
else
return 0;
fi
}

function runAcceptanceTests {
if ! docker history -q "${APP_NAME}:${APP_VERSION}" > /dev/null 2>&1; then
buildProject
fi

docker-compose kill > /dev/null 2>&1
docker-compose rm -f -v > /dev/null 2>&1
docker-compose up -d hub
docker-compose up -d firefox
docker-compose up -d chrome
sleep 20;
BUILD_STATUS=`docker-compose up e2e`
docker-compose kill > /dev/null 2>&1
docker-compose rm -f -v > /dev/null 2>&1
echo "$BUILD_STATUS";
if echo "$BUILD_STATUS" | grep -q "exited with code 1"; then
return 1;
else
return 0;
fi
}

function gulpServe {
if ! docker history -q "${APP_NAME}:${APP_VERSION}" > /dev/null 2>&1; then
buildProject
fi
docker-compose kill > /dev/null 2>&1
docker-compose rm -f -v > /dev/null 2>&1
docker-compose -f docker-compose.yml -f docker-compose.local.yml run --service-ports -d --entrypoint bash frontend /var/www/frontend/entrypoint_serve.sh
}

if [[ $TASK_NAME == 'build' ]]
then
buildProject
fi

if [[ $TASK_NAME == 'unit' ]]
then
runUnitTests
fi

if [[ $TASK_NAME == 'e2e' ]]
then
runAcceptanceTests
fi

if [[ $TASK_NAME == 'run' ]]
then
runBashInsideImage
fi

if [[ $TASK_NAME == 'serve' ]]
then
gulpServe
fi


if [[ $TASK_NAME == '' ]]; then
echo -e "\n\033[0;31mAll tasks are running within docker containers !!! \033[0m\n"
echo -e "Available commands:";
echo -e "'build' \t- is running 'gulp build'";
echo -e "'unit' \t- is running unit tests";
echo -e "'e2e' \t- is running e2e tests";
echo -e "'run' \t- is running docker container in attach mode (you will be logged in)";
echo -e "'serve' \t- is running 'gulp server' task, app config available in 'docker-compose.local.yml' that extends from 'docker-compose.yml'";
fi

exit $?
5 changes: 5 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -e

export NODE_PATH="/app/node_modules"

npm run watch
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cv_generator_frontend",
"version": "1.0.0",
"version": "1.0.4",
"description": "Generator for CV's in PGS Software",
"keywords": [
"angular2",
Expand Down Expand Up @@ -128,7 +128,7 @@
"typedoc": "^0.4.5",
"typescript": "2.0.0",
"url-loader": "^0.5.7",
"webpack": "^2.1.0-beta.21",
"webpack": "^2.1.0-beta.22",
"webpack-dev-middleware": "^1.6.1",
"webpack-dev-server": "^2.1.0-beta.2",
"webpack-md5-hash": "^0.0.5",
Expand Down