Skip to content

Commit e058201

Browse files
Maksym LanovyyPatrickJS
Maksym Lanovyy
authored andcommitted
Upgraded Dockerfile to implement multi-staged build. Fixed E2E tests. Fixed Travis CI build.
1 parent db2af72 commit e058201

File tree

7 files changed

+68
-61
lines changed

7 files changed

+68
-61
lines changed

.travis.yml

+1-15
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ cache:
77
- node_modules
88

99
addons:
10-
apt:
11-
sources:
12-
- google-chrome
13-
packages:
14-
- google-chrome-stable
10+
chrome: stable
1511

1612
node_js:
1713
- "6"
@@ -30,15 +26,5 @@ before_install:
3026
install:
3127
- npm install
3228

33-
after_install:
34-
- npm rebuild node-sass
35-
36-
before_script:
37-
- node ./node_modules/protractor/bin/webdriver-manager update
38-
- npm rebuild node-sass
39-
- export DISPLAY=:99.0
40-
- sh -e /etc/init.d/xvfb start
41-
- sleep 3
42-
4329
script:
4430
- npm run ci:travis

Dockerfile

+28-28
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,31 @@
1515
# Run image as virtual host (read more: https://github.com/jwilder/nginx-proxy):
1616
# docker run -e VIRTUAL_HOST=angular-starter.your-domain.com --name angular-starter angular-starter &
1717

18-
FROM nginx:1.13.0-alpine
19-
20-
# install console and node
21-
RUN apk add --no-cache bash=4.3.46-r5 &&\
22-
apk add --no-cache openssl=1.0.2n-r0 &&\
23-
apk add --no-cache nodejs
24-
25-
# install npm ( in separate dir due to docker cache)
26-
ADD package.json /tmp/npm_inst/package.json
27-
RUN cd /tmp/npm_inst &&\
28-
npm install &&\
29-
mkdir -p /tmp/app &&\
30-
mv /tmp/npm_inst/node_modules /tmp/app/
31-
32-
# build and publish application
33-
ADD . /tmp/app
34-
RUN cd /tmp/app &&\
35-
npm run build:aot &&\
36-
mv ./dist/* /usr/share/nginx/html/
37-
38-
# clean
39-
RUN rm -Rf /tmp/npm_inst &&\
40-
rm -Rf /tmp/app &&\
41-
rm -Rf /root/.npm &&\
42-
apk del nodejs
43-
44-
# this is for virtual host purposes
45-
EXPOSE 80
18+
# Stage 1, based on Node.js, to build and compile Angular
19+
20+
FROM node:8.9.4-alpine as builder
21+
22+
COPY package.json ./
23+
24+
## Storing node modules on a separate layer will prevent unnecessary npm installs at each build
25+
RUN npm i && mkdir /ng-app && mv ./node_modules ./ng-app
26+
27+
WORKDIR /ng-app
28+
29+
COPY . .
30+
31+
RUN npm run build:aot:prod
32+
33+
# Stage 2, based on Nginx, to have only the compiled app, ready for production with Nginx
34+
35+
FROM nginx:1.13.9-alpine
36+
37+
COPY ./config/nginx-custom.conf /etc/nginx/conf.d/default.conf
38+
39+
## Remove default nginx website
40+
RUN rm -rf /usr/share/nginx/html/*
41+
42+
## From ‘builder’ stage copy over the artifacts in dist folder to default nginx public folder
43+
COPY --from=builder /ng-app/dist /usr/share/nginx/html
44+
45+
CMD ["nginx", "-g", "daemon off;"]

config/karma.conf.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,14 @@ module.exports = function (config) {
120120
* available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
121121
*/
122122
browsers: [
123-
'Chrome'
123+
'Chrome',
124+
'ChromeTravisCi'
124125
],
125126

126127
customLaunchers: {
127128
ChromeTravisCi: {
128-
base: 'Chrome',
129-
flags: ['--no-sandbox']
129+
base: 'ChromeHeadless',
130+
flags: ['--no-sandbox', '--disable-gpu']
130131
}
131132
},
132133

config/nginx-custom.conf

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
server {
2+
listen 80;
3+
4+
gzip on;
5+
gzip_http_version 1.1;
6+
gzip_disable "MSIE [1-6]\.";
7+
gzip_min_length 1100;
8+
gzip_vary on;
9+
gzip_proxied expired no-cache no-store private auth;
10+
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
11+
gzip_comp_level 9;
12+
13+
root /usr/share/nginx/html;
14+
15+
location / {
16+
index index.html index.htm;
17+
try_files $uri $uri/ /index.html =404;
18+
}
19+
}

config/protractor.conf.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,23 @@ exports.config = {
1717
],
1818
exclude: [],
1919

20-
framework: 'jasmine2',
20+
framework: 'jasmine',
2121

22-
allScriptsTimeout: 110000,
22+
allScriptsTimeout: 11000,
2323

2424
jasmineNodeOpts: {
2525
showTiming: true,
2626
showColors: true,
2727
isVerbose: false,
2828
includeStackTrace: false,
29-
defaultTimeoutInterval: 400000
29+
defaultTimeoutInterval: 40000
3030
},
31-
directConnect: true,
3231

32+
directConnect: true,
3333
capabilities: {
34-
'browserName': 'chrome',
35-
'chromeOptions': {
36-
//'args': ["--headless", "--disable-gpu", "--window-size=1280x800", "--no-sandbox"]
37-
'args': ['show-fps-counter=true']
34+
browserName: 'chrome',
35+
chromeOptions: {
36+
args: [ "--headless", "--disable-gpu", "--window-size=800x600", "--no-sandbox" ]
3837
}
3938
},
4039

package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
"build:docker": "npm run build:prod && docker build -t angular2-webpack-start:latest .",
2424
"build:prod": "npm run clean:dist && npm run webpack -- --config config/webpack.prod.js --progress --profile --bail",
2525
"build": "npm run build:dev",
26-
"ci:aot": "cross-env BUILD_E2E=1 npm run lint && npm run test && npm run build:aot && npm run e2e",
27-
"ci:jit": "cross-env BUILD_E2E=1 npm run lint && npm run test && npm run build:prod && npm run e2e",
28-
"ci:nobuild": "npm run lint && npm test && npm run e2e",
29-
"ci:testall": "cross-env BUILD_E2E=1 npm run lint && npm run test && npm run build:prod && npm run e2e && npm run build:aot && npm run e2e",
30-
"ci:travis": "cross-env BUILD_E2E=1 npm run lint && npm run test && npm run build:aot && npm run e2e:travis",
26+
"ci:aot": "cross-env BUILD_E2E=1 npm run lint && npm run test:ci && npm run build:aot && npm run e2e",
27+
"ci:jit": "cross-env BUILD_E2E=1 npm run lint && npm run test:ci && npm run build:prod && npm run e2e",
28+
"ci:nobuild": "npm run lint && npm test:ci && npm run e2e",
29+
"ci:testall": "cross-env BUILD_E2E=1 npm run lint && npm run test:ci && npm run build:prod && npm run e2e && npm run build:aot && npm run e2e",
30+
"ci:travis": "cross-env BUILD_E2E=1 npm run lint && npm run test:ci && npm run build:aot && npm run e2e:travis",
3131
"ci": "npm run ci:testall",
3232
"clean:dll": "npm run rimraf -- dll",
3333
"clean:aot": "npm run rimraf -- compiled",
@@ -64,7 +64,8 @@
6464
"start:hmr": "npm run server:dev:hmr",
6565
"start": "npm run server:dev",
6666
"start:aot": "npm run server:aot:dev",
67-
"test": "npm run lint && karma start",
67+
"test": "karma start",
68+
"test:ci": "karma start --single-run --browsers ChromeTravisCi",
6869
"tslint": "tslint",
6970
"typedoc": "typedoc",
7071
"version": "npm run build",

src/app/home/home.e2e.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ describe('Home', () => {
77
/**
88
* Change hash depending on router LocationStrategy.
99
*/
10-
await browser.get('/#/home');
10+
await browser.get('/');
11+
await element(by.linkText('Home')).click();
1112
});
1213

1314
it('should have a title', async () => {

0 commit comments

Comments
 (0)