Skip to content

Commit b1484a7

Browse files
author
vikasrohit
authored
Merge pull request #260 from maxceem/feature/improve-readme
improve local development guide in README
2 parents f375a1d + bd0f599 commit b1484a7

File tree

1 file changed

+81
-31
lines changed

1 file changed

+81
-31
lines changed

README.md

Lines changed: 81 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,98 @@ Microservice to manage CRUD operations for all things Projects.
44

55
### Note : Steps mentioned below are best to our capability as guide for local deployment, however, we expect from contributor, being a developer, to resolve run-time issues (e.g. OS and node version issues etc), if any.
66

7-
### Local Development
7+
## Local Development
88

9-
* We use docker-compose for running dependencies locally. Instructions for Docker compose setup - https://docs.docker.com/compose/install/
9+
### Requirements
10+
11+
* [docker-compose](https://docs.docker.com/compose/install/) - We use docker-compose for running dependencies locally.
1012
* Nodejs 8.9.4 - consider using [nvm](https://github.com/creationix/nvm) or equivalent to manage your node version
1113
* Install [libpg](https://www.npmjs.com/package/pg-native)
12-
* Install node dependencies
13-
`npm install`
14-
15-
* Start local services
16-
```~/Projects/tc-projects-service
17-
> cd local/
18-
~/Projects/tc-projects-service/local
19-
> docker-compose up
20-
```
21-
Copy config/sample.local.js as config/local.js, update the properties and according to your env setup
22-
23-
#### Database
24-
Once you start your PostgreSQL database through docker, it will create a projectsdb.
25-
*To create tables - note this will drop tables if they already exist*
26-
```
27-
NODE_ENV=development npm run sync:db
28-
```
2914

30-
#### Redis
31-
Docker compose command will start a local redis instance as well. You should be able to connect to this instance using url `$(docker-machine ip):6379`
15+
### Steps to run locally
16+
1. Install node dependencies
17+
```bash
18+
npm install
19+
```
20+
21+
* Run docker with dependant services
22+
```bash
23+
cd local/
24+
docker-compose up
25+
```
26+
This will run several services locally:
27+
- `postgres`
28+
- `elasticsearch`
29+
- `rabbitmq`
30+
- `mock-services` - mocks some Topcoder API
31+
32+
*NOTE: In production these dependencies / services are hosted & managed outside tc-projects-service.*
33+
34+
* Local config
35+
```bash
36+
# in the tc-project-service root folder, not inside local/ as above
37+
cp config/sample.local.js config/local.js
38+
```
39+
Copy `config/sample.local.js` as `config/local.js`.<br>
40+
As project service depend on many third-party services we have to config how to access them. Some services are run locally and some services are used from Topcoder DEV environment. `config/local.js` has a prepared configuration which would replace values no matter what `NODE_ENV` value is.
41+
42+
**IMPORTANT** This configuration file assumes that services run by docker use domain `dockerhost`. Depend on your system you have to make sure that domain `dockerhost` points to the IP address of docker.
43+
For example, you can add a the next line to your `/etc/hosts` file, if docker is run on IP `127.0.0.1`.
44+
```
45+
127.0.0.1 dockerhost
46+
```
47+
Alternatively, you may update `config/local.js` and replace `dockerhost` with your docker IP address.<br>
48+
You may try using command `docker-machine ip` to get your docker IP, but it works not for all systems.
49+
50+
* Create tables in DB
51+
```bash
52+
NODE_ENV=development npm run sync:db
53+
```
54+
This command will crate tables in `postgres` db.
55+
56+
*NOTE: this will drop tables if they already exist.*
57+
58+
* Sync ES indices
59+
```bash
60+
NODE_ENV=development npm run sync:es
61+
```
62+
Helper script to sync the indices and mappings with the elasticsearch.
63+
64+
*NOTE: This will first clear all the indices and than recreate them. So use with caution.*
65+
66+
* Run
67+
```bash
68+
npm run start:dev
69+
```
70+
Runs the Project Service using nodemon, so it would be restarted after any of the files is updated.
71+
The project service will be served on `http://localhost:8001`.
3272

33-
#### Elasticsearch
34-
Docker compose includes elasticsearch instance as well. It will open ports 9200 & 9300 (kibana)
35-
36-
#### Sync indices and mappings
73+
### Import sample metadata
74+
```bash
75+
node migrations/seedMetadata.js
76+
```
77+
To create sample metadata entries (duplicate what is currently in development environment).
3778

38-
There is a helper script to sync the indices and mappings with the elasticsearch.
79+
### Run Connect App with Project Service locally
3980

40-
Run `npm run sync:es` from the root of project to execute the script.
81+
To be able to run [Connect App](https://github.com/appirio-tech/connect-app) with the local setup of Project Service we have to do two things:
82+
1. Configurate Connect App to use locally deployed Project service inside `connect-app/config/constants/dev.js` set
4183

42-
> NOTE: This will first clear all the indices and than recreate them. So use with caution.
84+
```js
85+
PROJECTS_API_URL: 'http://localhost:8001'
86+
```
87+
2. Bypass token validation in Project Service.
4388

44-
**NOTE**: In production these dependencies / services are hosted & managed outside tc-projects-service.
89+
In `tc-project-service/node_modules/tc-core-library-js/lib/auth/verifier.js` add this to line 23:
90+
```js
91+
callback(undefined, decodedToken.payload);
92+
return;
93+
```
94+
Connect App when making requests to the Project Service uses token retrieved from the Topcoder service deployed online. Project Service validates the token. For this purpose Project Service have to know the `secret` which has been used to generate the token. But we don't know the `secret` which is used by Topcoder for both DEV and PROD environment. So to bypass token validation we change these lines in the auth library.
4595

46-
### Import sample metadata
96+
*NOTE: this change only let us bypass validation during local development process*.
4797

48-
To create sample metadata entries (duplicate what is currently in development environment) run `node migrations/seedMetadata.js`
98+
3. Restart both Connect App and Project Service if they were running.
4999

50100
### Test
51101

0 commit comments

Comments
 (0)