Skip to content

Commit 44b650e

Browse files
ArnaudPelmgechev
authored andcommitted
Exclude Cypress and Karma from docker images (#2309)
1 parent efb94cc commit 44b650e

6 files changed

+61
-18
lines changed

.docker/Dockerfile_dev

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:8.6
1+
FROM node:9.11
22

33
WORKDIR /home/node/angular-seed
44

@@ -10,10 +10,13 @@ COPY gulpfile.ts .
1010
COPY tsconfig.json .
1111
COPY tslint.json .
1212
COPY tools ./tools/
13-
COPY cypress ./cypress/
13+
COPY .docker/rm.optional.deps.js ./.docker/rm.optional.deps.js
1414

1515
# before switching to non-root user, change ownership of home
1616
RUN chown -R node:node .
1717
USER node
1818

19-
RUN npm install
19+
# NB: this is a workaround due to the fact that npm '--no-optional' flag doesn't work (open script below for more)
20+
RUN node .docker/rm.optional.deps.js
21+
22+
RUN npm install --no-optional

.docker/Dockerfile_prod

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:8.6 as builder
1+
FROM node:9.11 as builder
22

33
WORKDIR /home/node/angular-seed
44

@@ -9,8 +9,12 @@ COPY . .
99
RUN chown -R node:node .
1010
USER node
1111

12-
RUN npm install
13-
RUN npm run build.prod
12+
# NB: this is a workaround due to the fact that npm '--no-optional' flag doesn't work (open script below for more)
13+
RUN node .docker/rm.optional.deps.js
14+
RUN rm -r cypress && rm cypress.json
15+
16+
RUN npm install --no-optional
17+
RUN npm run build.prod.rollup.aot
1418

1519
FROM nginx:1.13
1620
COPY --from=builder /home/node/angular-seed/dist/prod /var/www/dist/prod

.docker/rm.optional.deps.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const fs = require('fs');
2+
3+
/**
4+
* This is a workaround due to 'npm install --no-optional' not working as expected:
5+
* https://github.com/npm/npm/issues/17633
6+
* https://github.com/npm/npm/issues/20769
7+
* To be used when building docker images, since they don't need test libraries installed
8+
*/
9+
// package.json
10+
const npmPackage = JSON.parse(fs.readFileSync('package.json'));
11+
delete npmPackage['optionalDependencies'];
12+
fs.writeFileSync('package.json', JSON.stringify(npmPackage, null, 2));
13+
14+
/**
15+
* Todo is there a better way to handdle optional types in tsconfig.json ?
16+
*/
17+
let tsConfigJson = 'src/client/tsconfig.json'; // only copied in the prod image
18+
if (fs.existsSync(tsConfigJson)) {
19+
const tsConfig = JSON.parse(fs.readFileSync(tsConfigJson));
20+
tsConfig['compilerOptions']['types'] = tsConfig['compilerOptions']['types'].filter(t => t !== 'jasmine');
21+
fs.writeFileSync(tsConfigJson, JSON.stringify(tsConfig, null, 2));
22+
}

.dockerignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,25 @@ bower_components
1414
.classpath
1515
*.launch
1616
.settings/
17+
.editorconfig
1718

1819
# misc
1920
.sass-cache
2021
connect.lock
2122
coverage/*
23+
coverage_js/*
2224
libpeerconnection.log
2325
npm-debug.log
2426
testem.log
2527
typings
2628

27-
# e2e
29+
# test
30+
*.spec.ts
2831
e2e/*.js
2932
e2e/*.map
33+
test-config.js
34+
test-main.js
35+
karma.conf.js
3036

3137
#System Files
3238
.DS_Store

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ The application provides full Docker support. You can use it for both developmen
131131
Please note that prod and dev are built into their own separate image, which can lead to unexpected differences in the
132132
npm dependencies and the state of the sources in the container, if you are not familiar with Docker. See below.
133133

134+
Please also note that karma tests (`npm test`) are independent from the docker environment.
135+
Even if an angular-seed container is up and running, karma will run in the context of your **local** npm install,
136+
which may differ from that of the container. In fact, the docker containers don't have karma installed at all.
137+
138+
Cypress tests are however fully supported and recommended to test the app served by either the dev or prod docker containers.
139+
134140
## Development build and deployment
135141

136142
The dev image only contains the npm libraries installed, but not the sources. The sources are mounted at runtime,

package.json

+13-11
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,23 @@
5050
"node": ">=6.9.0",
5151
"npm": ">=3.10.3"
5252
},
53+
"optionalDependencies": {
54+
"@bahmutov/add-typescript-to-cypress": "^2.0.0",
55+
"@types/jasmine": "^2.8.6",
56+
"cypress": "^3.0.1",
57+
"jasmine-core": "^3.1.0",
58+
"jasmine-spec-reporter": "^4.2.1",
59+
"karma": "~2.0.0",
60+
"karma-chrome-launcher": "~2.2.0",
61+
"karma-coverage": "^1.1.1",
62+
"karma-jasmine": "^1.1.1",
63+
"karma-mocha-reporter": "^2.2.5",
64+
"karma-remap-istanbul": "^0.6.0"
65+
},
5366
"devDependencies": {
5467
"@angular/compiler-cli": "^6.0.1",
5568
"@angular/language-service": "^6.0.1",
5669
"@angular/platform-server": "^6.0.1",
57-
"@bahmutov/add-typescript-to-cypress": "^2.0.0",
5870
"@compodoc/compodoc": "^1.1.1",
5971
"@types/async": "^2.0.48",
6072
"@types/browser-sync": "^0.0.41",
@@ -65,7 +77,6 @@
6577
"@types/gulp-load-plugins": "^0.0.31",
6678
"@types/gulp-sass": "^0.0.31",
6779
"@types/gulp-util": "^3.0.34",
68-
"@types/jasmine": "^2.8.6",
6980
"@types/node": "^10.3.5",
7081
"@types/rimraf": "2.0.2",
7182
"@types/run-sequence": "^0.0.30",
@@ -77,7 +88,6 @@
7788
"codelyzer": "^4.2.1",
7889
"connect-history-api-fallback": "^1.5.0",
7990
"cssnano": "^3.10.0",
80-
"cypress": "^3.0.1",
8191
"deep-extend": "^0.6.0",
8292
"event-stream": "^3.3.4",
8393
"express": "~4.16.3",
@@ -107,14 +117,6 @@
107117
"gulp-watch": "^5.0.0",
108118
"is-ci": "^1.1.0",
109119
"isstream": "^0.1.2",
110-
"jasmine-core": "^3.1.0",
111-
"jasmine-spec-reporter": "^4.2.1",
112-
"karma": "~2.0.0",
113-
"karma-chrome-launcher": "~2.2.0",
114-
"karma-coverage": "^1.1.1",
115-
"karma-jasmine": "^1.1.1",
116-
"karma-mocha-reporter": "^2.2.5",
117-
"karma-remap-istanbul": "^0.6.0",
118120
"merge-stream": "^1.0.1",
119121
"minimatch": "^3.0.4",
120122
"node-sass-magic-importer": "^5.1.3",

0 commit comments

Comments
 (0)