Skip to content

Commit 1186219

Browse files
committed
add nginx and update config & docs for node container to be more versatile
1 parent 7bd0790 commit 1186219

File tree

3 files changed

+94
-83
lines changed

3 files changed

+94
-83
lines changed

README.md

Lines changed: 79 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -47,77 +47,103 @@ See [`CONTRIBUTING.md`][org-contrib].
4747
[org-contrib]: https://github.com/creativecommons/.github/blob/main/CONTRIBUTING.md
4848

4949

50-
## Getting Started
50+
## Using Docker
5151

5252

53-
## Using Docker
53+
### Containers
54+
55+
The [`docker-compose.yml`](docker-compose.yml) file defines the following
56+
containers:
57+
1. **chooser-web** - simple NGINX container serving [`docs/`](docs)
58+
- [localhost:8888](http://localhost:8888/)
59+
2. **chooser-node** - Node14 container
60+
- [localhost:8080](http://localhost:8080/)
61+
- (requires **Run Node development server**, below)
62+
63+
64+
### Docker desktop required
5465

5566
Before proceeding, ensure you have Docker installed on your local machine. If
5667
not, download and install Docker Desktop by visiting [Docker's official
5768
website](https://www.docker.com/products/docker-desktop) and follow the
5869
installation instructions.
5970

60-
To deploy the Creative Commons Chooser application using Docker, follow these
61-
steps:
6271

72+
### Run Node development server
6373

64-
### Step 1: Install Docker Desktop
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
80+
```shell
81+
docker compose exec chooser-node npm run serve
82+
```
83+
- [localhost:8080](http://localhost:8080/)
6584

66-
First, ensure you have Docker Desktop installed on your local machine. Open
67-
Docker Desktop app on your local machine and follow the installation
68-
instructions.
69-
70-
71-
### Step 2: Clone the Repository
72-
73-
Clone the Creative Commons Chooser repository to your local machine:
74-
75-
```shell
76-
git clone https://github.com/creativecommons/chooser.git
77-
```
7885

86+
### Create production (standalone) build
7987

80-
### Step 3: Navigate to the Project Directory
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
94+
```shell
95+
docker compose exec chooser-node npm run build
96+
```
97+
- (this automatically copies the generated files from [`dist/`](dist) to
98+
[`docs/`](docs))
8199

82-
Navigate into the project directory:
100+
The chooser is deployed to GitHub Pages. The source files for the beta
101+
deployment are contained in the `./docs/` dir, and are live. Any changes to
102+
this directory's contents will be automatically deployed, so please take care
103+
when making modifications to this location.
83104
84-
```shell
85-
cd chooser
86-
```
87105
106+
### Create standalone (production) build
88107
89-
### Step 4: Build and Run the Docker Container
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
114+
```shell
115+
docker compose exec chooser-node npm run build
116+
```
117+
- (this automatically copies the generated files from [`dist/`](dist) to
118+
[`docs/`](docs))
90119
91-
In order to have the code up and running on your machine, build the Docker
92-
container using docker-compose:
120+
The chooser is deployed to GitHub Pages. The source files for the beta
121+
deployment are contained in the `./docs/` dir, and are live. Any changes to
122+
this directory's contents will be automatically deployed, so please take care
123+
when making modifications to this location.
93124

125+
For an embedded standalone build (no header nor footer), run:
94126
```shell
95-
docker compose up
96-
```
97-
98-
If there is `node_modules` directory, it will perform a clean install from
99-
`package-lock.json`.
100-
101-
102-
### Step 5: Access the Application
103-
104-
Once the container is running, you can access the Creative Commons Chooser application by navigating to the following URL in your web browser:
105-
106-
```
107-
http://localhost:8080
127+
docker compose exec chooser-node VUE_APP_CC_OUTPUT=embedded npm run build
108128
```
129+
**(please _don't_ commit embedded builds to `docs/`)**
109130
110131
111-
### Building as web component
132+
### Create a web component build
112133
113-
To build the project as a web component, run:
114-
```shell
115-
docker compose exec web npm run build-component
116-
```
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
140+
```shell
141+
docker compose exec chooser-node npm run build-component
142+
```
117143
118-
This will create a file in the `dist` folder named `license-chooser.min.js`. It
119-
can be used to load the web-component in any JS project. There is also a sample
120-
`demo.html` created.
144+
This will create a file in the [`dist/`](dist) folder named
145+
`license-chooser.min.js`. It can be used to load the web-component in any JS
146+
project. There is also a sample `demo.html` created.
121147
122148
To be able to use the file it should either be rendered statically from the
123149
integrater's web-app or be published on a CDN. Following code can be used to
@@ -133,22 +159,22 @@ example.
133159
<license-chooser></license-chooser>
134160
```
135161

136-
If the web component is intended to be built without header and footer, run
162+
For an embedded web component build (no header nor footer), run:
137163
```shell
138-
docker compose exec web VUE_APP_CC_OUTPUT=embedded npm run build-component
164+
docker compose exec chooser-node VUE_APP_CC_OUTPUT=embedded npm run build-component
139165
```
140166

141167

142168
## Running Tests
143169

144170
You can run tests by executing:
145171
```shell
146-
docker compose exec web npm run test
172+
docker compose exec chooser-node npm run test
147173
```
148174

149175
For running tests on a web-component build, run:
150176
```shell
151-
docker compose exec npm run test-component
177+
docker compose exec chooser-node npm run test-component
152178
```
153179

154180
It starts a server with the `dist/demo.html` on which tests can be run.
@@ -164,30 +190,15 @@ can manually add the necessary classes or Regex expressions to the `safelist`
164190
array in the `postcss.config.js` file.
165191

166192

167-
## Deployment
168-
169-
The chooser is deployed to GitHub Pages. The source files for the beta
170-
deployment are contained in the `./docs/` dir, and are live. Any changes to
171-
this directory's contents will be automatically deployed, so please take care
172-
when making modifications to this location.
173-
174-
To update the dist bundle, run:
175-
```shell
176-
docker compose exec npm run build
177-
```
178-
This will also automatically copy the generated files from `./dist/` to
179-
`./docs/`.
180-
181-
182-
## Output Modes
193+
## Embedded screenshot
183194

184195
The site can be built in two different modes: `embedded` and `standalone`.
185196
`Embedded` mode removes the header and footer from the application, resulting
186197
in the following appearance:
187198

188199
<img src="static/embedded-screenshot.png" alt="Application built in embedded mode">
189200

190-
To build into embedded mode, set the environment variable
201+
To build into _embedded_ mode, set the environment variable
191202
`VUE_APP_CC_OUTPUT=embedded` on your server before building. If
192203
`VUE_APP_CC_OUTPUT` is unset or set to a different value, the app will build in
193-
the default `standalone` mode, with its own header and footer.
204+
the default _standalone_ mode, with its own header and footer.

dev/Dockerfile

Lines changed: 0 additions & 12 deletions
This file was deleted.

docker-compose.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@ version: '2.4'
44

55
services:
66

7-
web:
8-
# Build configuration in dev/Dockerfile
9-
build: dev
7+
chooser-web:
8+
# https://hub.docker.com/_/nginx/
9+
image: 'nginx:latest'
10+
ports:
11+
- '8888:80'
12+
restart: on-failure
13+
volumes:
14+
- './docs:/usr/share/nginx/html:ro'
15+
16+
chooser-node:
17+
# continue running until shutdown (allows docker compose exec which is much
18+
# faster than docker compose run) per https://serverfault.com/a/1084975
19+
command: sh -c 'trap "exit" TERM; while true; do sleep 1; done'
20+
image: 'node:14'
1021
ports:
1122
- '8080:8080'
1223
restart: on-failure
1324
stdin_open: true
1425
tty: true
1526
volumes:
1627
- '.:/app'
28+
working_dir: /app

0 commit comments

Comments
 (0)