Skip to content

Commit 7bd0790

Browse files
authored
Merge pull request #523 from creativecommons/improve-docker-use
Improve docker use and related documentation
2 parents 55d0b98 + b7bfee7 commit 7bd0790

File tree

7 files changed

+124
-85
lines changed

7 files changed

+124
-85
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/tests/e2e/reports/
2-
/chromedriver.log
31
.idea/
4-
dist/
2+
chromedriver.log
53
coverage/
4+
dist/
65
node_modules/
6+
tests/e2e/reports/
77
yarn.lock

Dockerfile

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

README.md

Lines changed: 85 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@
88
![GitHub Repo stars](https://img.shields.io/github/stars/creativecommons/chooser?style=social)
99
![GitHub forks](https://img.shields.io/github/forks/creativecommons/chooser?style=social)
1010

11+
1112
# Chooser
1213

1314
The Creative Commons License Chooser is meant to help people learn about CC licenses, and select the license that best fits their needs. The new version in this repo places greater importance on usability, and an educational experience of the six CC licenses.
1415

16+
1517
## About
1618

1719
Repository containing the source code for the new Creative Commons License Chooser. The new chooser is still in beta, and a beta deployment can be found [here](https://chooser-beta.creativecommons.org/).
1820

1921
This site is built using [Vue.js](https://vuejs.org/) (and vue-cli).
2022

23+
2124
### Roadmap
2225

2326
Tasks, issues, and discussion related to the release of the new chooser are tracked with the [`Launch Milestone`](https://github.com/creativecommons/chooser/milestone/1).
2427

28+
2529
## Code of conduct
2630

2731
[`CODE_OF_CONDUCT.md`][org-coc]:
@@ -35,42 +39,66 @@ Tasks, issues, and discussion related to the release of the new chooser are trac
3539
[code_of_conduct]: https://opensource.creativecommons.org/community/code-of-conduct/
3640
[reporting_guide]: https://opensource.creativecommons.org/community/code-of-conduct/enforcement/
3741

42+
43+
## Contributing
44+
45+
See [`CONTRIBUTING.md`][org-contrib].
46+
47+
[org-contrib]: https://github.com/creativecommons/.github/blob/main/CONTRIBUTING.md
48+
49+
3850
## Getting Started
3951

52+
4053
## Using Docker
4154

42-
Before proceeding, ensure you have Docker installed on your local machine. If not, download and install Docker Desktop by visiting [Docker's official website](https://www.docker.com/products/docker-desktop) and follow the installation instructions.
55+
Before proceeding, ensure you have Docker installed on your local machine. If
56+
not, download and install Docker Desktop by visiting [Docker's official
57+
website](https://www.docker.com/products/docker-desktop) and follow the
58+
installation instructions.
59+
60+
To deploy the Creative Commons Chooser application using Docker, follow these
61+
steps:
4362

44-
To deploy the Creative Commons Chooser application using Docker, follow these steps:
4563

4664
### Step 1: Install Docker Desktop
4765

48-
First, ensure you have Docker Desktop installed on your local machine. Open Docker Desktop app on your local machine and follow the installation instructions.
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+
4970

5071
### Step 2: Clone the Repository
5172

5273
Clone the Creative Commons Chooser repository to your local machine:
5374

54-
```bash
75+
```shell
5576
git clone https://github.com/creativecommons/chooser.git
5677
```
5778

79+
5880
### Step 3: Navigate to the Project Directory
5981

6082
Navigate into the project directory:
6183

62-
```bash
84+
```shell
6385
cd chooser
6486
```
6587

88+
6689
### Step 4: Build and Run the Docker Container
6790

68-
In order to have the code up and running on your machine, build the Docker container using docker-compose:
91+
In order to have the code up and running on your machine, build the Docker
92+
container using docker-compose:
6993

70-
```bash
71-
docker-compose up
94+
```shell
95+
docker compose up
7296
```
7397

98+
If there is `node_modules` directory, it will perform a clean install from
99+
`package-lock.json`.
100+
101+
74102
### Step 5: Access the Application
75103

76104
Once the container is running, you can access the Creative Commons Chooser application by navigating to the following URL in your web browser:
@@ -79,33 +107,24 @@ Once the container is running, you can access the Creative Commons Chooser appli
79107
http://localhost:8080
80108
```
81109

82-
## Manual Setup
83-
84-
### Prerequisite
85-
[nodeJS](https://nodejs.org/en/blog/release/v14.17.3) version 14 or below, as the version above 14 may give error.
86110

87-
### Commands
88-
Run the following commands in order to have the code up and running on your machine:
111+
### Building as web component
89112

90-
``` bash
91-
# install dependencies
92-
npm install
113+
To build the project as a web component, run:
114+
```shell
115+
docker compose exec web npm run build-component
93116
```
94117

95-
```bash
96-
# Build and serve assets with hot-reload
97-
npm run serve
98-
```
99-
100-
You should now have the application running and accessible at <http://localhost:8080> (note: will run on a different port if 8080 is occupied, most common alternative port is 8081).
101-
102-
## Building as web component
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.
103121

104-
To build the project as a web component, run the command `npm run build-component`. This will create a file in the `dist` folder named `license-chooser.min.js`. It can be used to load the web-component in any JS project. There is also a sample `demo.html` created.
122+
To be able to use the file it should either be rendered statically from the
123+
integrater's web-app or be published on a CDN. Following code can be used to
124+
integrate this in other apps.
105125

106-
To be able to use the file it should either be rendered statically from the integrater's web-app or be published on a CDN. Following code can be used to integrate this in other apps.
107-
108-
Note: the Chooser component depends on Vue 2.x, as can be seen in the following example.
126+
Note: the Chooser component depends on Vue 2.x, as can be seen in the following
127+
example.
109128

110129
```
111130
<script src="https://cdn.jsdelivr.net/npm/vue@2.x.x"></script>
@@ -114,48 +133,61 @@ Note: the Chooser component depends on Vue 2.x, as can be seen in the following
114133
<license-chooser></license-chooser>
115134
```
116135

117-
If the web component is intended to be built without header and footer, run `VUE_APP_CC_OUTPUT=embedded npm run build-component`
118-
119-
## Contributing
120-
121-
For information on contributing, please see [Creative Commons' Contribution Guidelines](https://opensource.creativecommons.org/contributing-code/)
122-
123-
If you create a PR for your work, but you are not finished yet, please include `WIP:` in the beginning of your PR title. When your work on your PR is completed, and you are ready for a final review, please remove the `WIP:` prefix from the title to indicate that your work is done.
124-
125-
Here's a [handy link](https://github.com/creativecommons/chooser/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22+-label%3A%22in+progress%22) that will show you all open issues in this repo that have the `help wanted` tag, but do not have the `in progress` tag.
126-
All issues in this list are up for grabs!
127-
If it says "No results matched your search", then there are no issues currently up for grabs.
128-
129-
*If no progress has been made on an issue for seven days after assignment, the assignment will be removed to allow others to contribute.*
136+
If the web component is intended to be built without header and footer, run
137+
```shell
138+
docker compose exec web VUE_APP_CC_OUTPUT=embedded npm run build-component
139+
```
130140

131-
See [`CONTRIBUTING.md`][org-contrib].
132-
133-
[org-contrib]: https://github.com/creativecommons/.github/blob/main/CONTRIBUTING.md
134141

135142
## Running Tests
136143

137144
You can run tests by executing:
145+
```shell
146+
docker compose exec web npm run test
147+
```
138148

139-
```bash
140-
npm run test
149+
For running tests on a web-component build, run:
150+
```shell
151+
docker compose exec npm run test-component
141152
```
142-
For running tests on a web-component build, run `npm run test-component`. It starts a server with the `dist/demo.html` on which tests can be run.
153+
154+
It starts a server with the `dist/demo.html` on which tests can be run.
143155

144156

145157
## CSS Build
146158

147-
The Chooser uses PostCSS plugin for PurgeCSS to make CSS bundle size smaller. It automatically removes unused CSS based on the classes found in the final built bundle. Some styles for dynamic components or dynamically-imported files can also be removed. If you find that the built site misses some styles, you can manually add the necessary classes or Regex expressions to the `safelist` array in the `postcss.config.js` file.
159+
The Chooser uses PostCSS plugin for PurgeCSS to make CSS bundle size smaller.
160+
It automatically removes unused CSS based on the classes found in the final
161+
built bundle. Some styles for dynamic components or dynamically-imported files
162+
can also be removed. If you find that the built site misses some styles, you
163+
can manually add the necessary classes or Regex expressions to the `safelist`
164+
array in the `postcss.config.js` file.
165+
148166

149167
## Deployment
150168

151-
The chooser is deployed to GitHub Pages. The source files for the beta deployment are contained in the `./docs/` dir, and are live. Any changes to this directory's contents will be automatically deployed, so please take care when making modifications to this location.
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/`.
152180

153-
To update the dist bundle, run ```$ npm run build```. This will also automatically copy the generated files from `./dist/` to `./docs/`.
154181

155182
## Output Modes
156183

157-
The site can be built in two different modes: `embedded` and `standalone`. `Embedded` mode removes the header and footer from the application, resulting in the following appearance:
184+
The site can be built in two different modes: `embedded` and `standalone`.
185+
`Embedded` mode removes the header and footer from the application, resulting
186+
in the following appearance:
158187

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

161-
To build into embedded mode, set the environment variable `VUE_APP_CC_OUTPUT=embedded` on your server before building. If `VUE_APP_CC_OUTPUT` is unset or set to a different value, the app will build in the default `standalone` mode, with its own header and footer.
190+
To build into embedded mode, set the environment variable
191+
`VUE_APP_CC_OUTPUT=embedded` on your server before building. If
192+
`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.

dev/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# https://docs.docker.com/reference/dockerfile/
2+
3+
# https://hub.docker.com/_/node/
4+
FROM node:14
5+
6+
WORKDIR /app
7+
8+
EXPOSE 8080
9+
10+
COPY startupservice.sh /usr/local/sbin/startupservice.sh
11+
RUN chmod +x /usr/local/sbin/startupservice.sh
12+
CMD /usr/local/sbin/startupservice.sh

dev/startupservice.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -o errexit
3+
set -o nounset
4+
5+
cd /app
6+
7+
if [[ ! -d node_modules ]]
8+
then
9+
echo 'Clean installing packages from package-lock.json'
10+
npm ci
11+
echo
12+
fi
13+
14+
npm run serve

docker-compose.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,12 @@ version: '2.4'
55
services:
66

77
web:
8-
# Build configuration in Dockerfile
9-
build: .
10-
11-
# Keep stdin open even if not attached
12-
stdin_open: true
13-
14-
restart: on-failure
15-
16-
# Allocate a pseudo-TTY
17-
tty: true
18-
19-
# Port mapping: Map host port 8080 to container port 8080
8+
# Build configuration in dev/Dockerfile
9+
build: dev
2010
ports:
2111
- '8080:8080'
22-
12+
restart: on-failure
13+
stdin_open: true
14+
tty: true
2315
volumes:
24-
# Mount the current directory from the host to /app in the container
2516
- '.:/app'
26-
# Mount the /app/node_modules directory from the host
27-
- '/app/node_modules'

publish.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
2-
32
set -o errexit
43
set -o errtrace
54
set -o nounset
@@ -12,10 +11,13 @@ trap '_es=${?};
1211

1312
echo "Deleting contents of dist folder"
1413
rm -rf dist/*
14+
echo
1515

1616
echo "Starting build"
17-
npm run build-component
17+
docker compose exec web npm run build-component
1818
echo "Finished build"
19+
echo
1920

2021
echo "Starting publish"
21-
npm publish --access public
22+
docker compose exec web npm publish --access public
23+
echo

0 commit comments

Comments
 (0)