Skip to content

Commit d489b91

Browse files
authored
Merge pull request #529 from creativecommons/docker-improvements
improve behavior of docker containers and document local cypress testing
2 parents fd6b01e + 5c12439 commit d489b91

File tree

4 files changed

+86
-37
lines changed

4 files changed

+86
-37
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
.cache/
12
.idea/
3+
.npm/
24
chromedriver.log
35
coverage/
46
dist/

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# https://docs.docker.com/engine/reference/builder/
2+
3+
# In order for NGINX to consistently serve the docs directory the parent
4+
# directory (repository root) needs to be mounted because building the site
5+
# deletes and recreates the docs directory. If the docs directory itself is
6+
# mounted, the container will continue to serve an empty directory (resulting
7+
# in a 403) after it is deleted because it is mounting the original docs
8+
# directory and not the new one.
9+
10+
# https://hub.docker.com/_/nginx/
11+
FROM nginx:latest
12+
13+
RUN mkdir /app
14+
15+
WORKDIR /app
16+
17+
# Update the NGINX configuraiton to serve /app/docs
18+
RUN sed -e's#/usr/share/nginx/html#/app/docs#' -i \
19+
/etc/nginx/conf.d/default.conf

README.md

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,31 @@ website](https://www.docker.com/products/docker-desktop) and follow the
6969
installation instructions.
7070

7171

72+
### Startup containers
73+
74+
The containers can be started with:
75+
```shell
76+
docker compose up
77+
```
78+
(See [Docker Compose overview | Docker Docs](https://docs.docker.com/compose/)
79+
for more information on managing containes with `docker compose`.)
80+
81+
82+
### Initial setup
83+
84+
Before the chooser-node container can be used effectively, a clean install of
85+
NPM packages from `package-lock.json` is required:
86+
```shell
87+
docker compose exec chooser-node npm ci
88+
```
89+
**This step generally only needs to be done once.**
90+
91+
7292
### Run Node development server
7393

74-
1. Perform a clean install of NPM packages from `package-lock.json`
75-
```shell
76-
docker compose exec chooser-node npm ci
77-
```
78-
- (this initial step can be skipped if previously completed)
79-
2. Run Node development server
94+
1. Startup containers (see above)
95+
2. Complete initial setup (see above)
96+
3. Run Node development server
8097
```shell
8198
docker compose exec chooser-node npm run serve
8299
```
@@ -85,12 +102,9 @@ installation instructions.
85102

86103
### Create production (standalone) build
87104

88-
1. Perform a clean install of NPM packages from `package-lock.json`
89-
```shell
90-
docker compose exec chooser-node npm ci
91-
```
92-
- (this initial step can be skipped if previously completed)
93-
2. Run Node development server
105+
1. Startup containers (see above)
106+
2. Complete initial setup (see above)
107+
3. Run Node development server
94108
```shell
95109
docker compose exec chooser-node npm run build
96110
```
@@ -105,12 +119,9 @@ when making modifications to this location.
105119
106120
### Create standalone (production) build
107121
108-
1. Perform a clean install of NPM packages from `package-lock.json`
109-
```shell
110-
docker compose exec chooser-node npm ci
111-
```
112-
- (this initial step can be skipped if previously completed)
113-
2. Run Node development server
122+
1. Startup containers (see above)
123+
2. Complete initial setup (see above)
124+
3. Run Node development server
114125
```shell
115126
docker compose exec chooser-node npm run build
116127
```
@@ -131,12 +142,9 @@ docker compose exec chooser-node VUE_APP_CC_OUTPUT=embedded npm run build
131142
132143
### Create a web component build
133144
134-
1. Perform a clean install of NPM packages from `package-lock.json`
135-
```shell
136-
docker compose exec chooser-node npm ci
137-
```
138-
- (this initial step can be skipped if previously completed)
139-
2. Run Node development server
145+
1. Startup containers (see above)
146+
2. Complete initial setup (see above)
147+
3. Run Node development server
140148
```shell
141149
docker compose exec chooser-node npm run build-component
142150
```
@@ -165,19 +173,35 @@ docker compose exec chooser-node VUE_APP_CC_OUTPUT=embedded npm run build-compon
165173
```
166174

167175

168-
## Running Tests
176+
## Perform unit tests on standalone or embedded build
169177

170-
You can run tests by executing:
171-
```shell
172-
docker compose exec chooser-node npm run test
173-
```
178+
1. Startup containers (see above)
179+
2. Complete initial setup (see above)
180+
2. Run unit tests
181+
```shell
182+
docker compose exec chooser-node npm run test:unit
183+
```
174184

175-
For running tests on a web-component build, run:
176-
```shell
177-
docker compose exec chooser-node npm run test-component
178-
```
185+
## Perform unit tests on web-component build
179186

180-
It starts a server with the `dist/demo.html` on which tests can be run.
187+
1. Startup containers (see above)
188+
2. Complete initial setup (see above)
189+
3. Create a web component build (see above)
190+
2. Run unit tests
191+
```shell
192+
docker compose exec chooser-node npm run test-component
193+
```
194+
- It starts a server with the `dist/demo.html` on which tests can be run.
195+
196+
197+
## Perform Cypress tests
198+
199+
1. Startup containers (see above)
200+
2. Run Cypress tests
201+
```shell
202+
docker run -it -v $PWD:/e2e -w /e2e -e CYPRESS_baseUrl=http://host.docker.internal:8888 cypress/included:latest
203+
```
204+
- (This will download the cypress/included image when first run)
181205

182206

183207
## CSS Build

docker-compose.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ version: '2.4'
55
services:
66

77
chooser-web:
8-
# https://hub.docker.com/_/nginx/
9-
image: 'nginx:latest'
8+
build: .
109
ports:
1110
- '8888:80'
1211
restart: on-failure
1312
volumes:
14-
- './docs:/usr/share/nginx/html:ro'
13+
- '.:/app:ro'
1514

1615
chooser-node:
1716
# continue running until shutdown (allows docker compose exec which is much
1817
# faster than docker compose run) per https://serverfault.com/a/1084975
1918
command: sh -c 'trap "exit" TERM; while true; do sleep 1; done'
19+
environment:
20+
# Store caches in repository directory. This save time across container
21+
# runs.
22+
npm_config_cache: /app/.npm
23+
npm_config_devdir: /app/.cache/node-gyp
2024
image: 'node:14'
2125
ports:
2226
- '8080:8080'

0 commit comments

Comments
 (0)