Skip to content

Commit c2132c1

Browse files
committed
wip
Signed-off-by: Nell Shamrell <[email protected]>
1 parent 99651fb commit c2132c1

File tree

1 file changed

+211
-0
lines changed

1 file changed

+211
-0
lines changed

walkthrough.md

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
# Clearly Defined Dev Environment Walk Through
2+
3+
Let's walk through creating a Clearly Defined Local Development Environment.
4+
5+
## Pre-reqs
6+
* Docker
7+
* Docker Compose
8+
* Docker Desktop (optional)
9+
10+
## Step 1. Set up your directories
11+
12+
First, create a Clearly Defined directory
13+
14+
```bash
15+
$ mkdir clearly_defined
16+
```
17+
18+
Next, change into that directory:
19+
20+
```bash
21+
$ cd clearly_defined
22+
```
23+
24+
And then, from within your clearly_defined repo, clone each of the three major Clearly Defined repos including:
25+
* [website](https://github.com/clearlydefined/website)
26+
* [service](https://github.com/clearlydefined/service)
27+
* [crawler](https://github.com/clearlydefined/crawler)
28+
29+
```bash
30+
$ git clone https://github.com/clearlydefined/website
31+
$ git clone https://github.com/clearlydefined/service
32+
$ git clone https://github.com/clearlydefined/crawler
33+
```
34+
35+
[NOTE - currently need to check out `nell/dev-docker-file` branch for each of those three repos]
36+
37+
Let's start off by getting the website running.
38+
39+
## Step 2. Set up the Clearly Defined Website
40+
41+
The Clearly Defined website is a React front end to the Clearly Defined service.
42+
43+
Take a look at what is in the website repo, you will see two Dockerfiles
44+
45+
```bash
46+
$ ls website
47+
(...)
48+
DevDockerfile
49+
Dockerfile
50+
(...)
51+
```
52+
53+
Since we are creating a Development environment, we will use the DevDockerFile.
54+
55+
Make sure you are still in your clearly_defined directory:
56+
57+
```bash
58+
$ pwd
59+
/path/to/clearly_defined
60+
```
61+
62+
And create a Docker compose file:
63+
64+
```bash
65+
$ touch docker-compose.yml
66+
```
67+
68+
And open it up in the editor of your choice.
69+
70+
Let's start off by adding some Docker compose boilerplate.
71+
72+
**docker-compose.yml**
73+
```
74+
version: "3.8"
75+
services:
76+
```
77+
78+
And then let's add in just what we need to build and run the website through Docker compose.
79+
80+
**docker-compose.yml**
81+
```
82+
version: "3.8"
83+
services:
84+
web:
85+
build:
86+
context: ./website
87+
dockerfile: DevDockerfile
88+
ports:
89+
- "3000:3000"
90+
stdin_open: true
91+
```
92+
93+
And if you head to http://localhost:3000 you will see the running Clearly Defined UI!
94+
95+
It looks really nice...but there's not a lot we can do with just the front end of the
96+
service.
97+
98+
Now, let's set up the backend service.
99+
100+
## Step 3. Set up the Clearly Defined service
101+
102+
The Clearly Defined service is an Node JS express application.
103+
104+
It requires some environmental variables to run.
105+
106+
Let's create a .env file to be used by our Docker compose file (NOTE: this is different from the env.json file used in the [historical dev evironment docs](https://docs.clearlydefined.io/contributing-code)).
107+
108+
```bash
109+
touch .env
110+
```
111+
112+
And then add in the minimum environmental variables the service needs to work.
113+
114+
(You will need a [GitHub token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) with minimal permissions)
115+
116+
**.env**
117+
```bash
118+
CURATION_GITHUB_TOKEN="<Your GitHub Personal Access Token>"
119+
```
120+
121+
And now let's add the service to our docker-compose file (right under the web service definition)
122+
123+
**docker-compose.yml**
124+
```
125+
version: "3.8"
126+
services:
127+
web:
128+
build:
129+
context: ./website
130+
dockerfile: DevDockerfile
131+
ports:
132+
- "3000:3000"
133+
stdin_open: true
134+
service:
135+
build:
136+
context: ./service
137+
dockerfile: DevDockerfile
138+
env_file: .env
139+
ports:
140+
- "4000:4000"
141+
```
142+
143+
And spin the containers back up:
144+
145+
```bash
146+
$ docker-compose up
147+
```
148+
149+
Now, you can both see the UI at http://localhost:3000 AND query the service API at http://localhost:4000
150+
151+
```bash
152+
$ curl http://localhost:4000
153+
```
154+
155+
And this will let you test a bare minimum of Clearly Defined functionality. However, it will be much more useful if we have some data.
156+
157+
## Step 4: Create the Clearly Defined Definitions Database
158+
159+
One of the main things Clearly Defined stores is license definitions for pieces of Open Source Software. If you head to the production deployment of Clearly Defined at https://clearlydefined.io/. you will see several definitions in the "Browse" window.
160+
161+
Let's create the database that will store these definitions.
162+
163+
Let's add it to our Docker Compose file - we will use a MongoDB container.
164+
165+
**docker-compose.yml**
166+
```
167+
version: "3.8"
168+
services:
169+
web:
170+
build:
171+
context: ./website
172+
dockerfile: DevDockerfile
173+
ports:
174+
- "3000:3000"
175+
stdin_open: true
176+
service:
177+
build:
178+
context: ./service
179+
dockerfile: DevDockerfile
180+
env_file: .env
181+
ports:
182+
- "4000:4000"
183+
curations_mongo_db:
184+
image: "mongo:latest"
185+
ports:
186+
- "27017:27017"
187+
environment:
188+
- MONGO_INITDB_DATABASE=curations-dev-docker
189+
- MONGO_INITDB_ROOT_USERNAME=admin
190+
- MONGO_INITDB_ROOT_PASSWORD=secret
191+
```
192+
193+
And let's add the appropriate info to the .env file:
194+
195+
**.env**
196+
```bash
197+
CURATION_GITHUB_TOKEN="<Your GitHub Personal Access Token>"
198+
199+
DEFINITION_MONGO_CONNECTION_STRING="mongodb://admin:secret@localhost:27018/definitions-dev-docker"
200+
DEFINITION_STORE_PROVIDER="mongo"
201+
DEFINITION_MONGO_COLLECTION_NAME="definitions-paged"
202+
```
203+
204+
Now let's spin it up with
205+
206+
```bash
207+
$ docker-compose up
208+
```
209+
210+
Alright, things are working together, but now let's get some data into our definitions database.
211+

0 commit comments

Comments
 (0)