You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -4,89 +4,123 @@ Microservice to manage CRUD operations for all things Projects.
4
4
5
5
### 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.
6
6
7
-
###Local Development
7
+
## Local Development
8
8
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.
10
12
* Nodejs 8.9.4 - consider using [nvm](https://github.com/creationix/nvm) or equivalent to manage your node version
Copy config/sample.local.js as config/local.js, update the properties and according to your env setup
22
14
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
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` - two instances: for app and for unit tests
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
+
36
+
There are two prepared configs:
37
+
- if you have M2M environment variables provided: `AUTH0_CLIENT_ID`, `AUTH0_CLIENT_SECRET`, `AUTH0_URL`, `AUTH0_AUDIENCE`, `AUTH0_PROXY_SERVER_URL` then use `config/m2m.local.js`
38
+
- otherwise use `config/mock.local.js`.
39
+
40
+
To apply any of these config copy it to `config/local.js`:
41
+
42
+
```bash
43
+
cp config/mock.local.js config/local.js
44
+
# or
45
+
cp config/m2m.local.js config/local.js
46
+
```
47
+
48
+
`config/local.js` has a prepared configuration which would replace values no matter what `NODE_ENV` value is.
49
+
50
+
**IMPORTANT** These configuration files assume that docker containers are run on domain `dockerhost`. Depend on your system you have to make sure that domain `dockerhost` points to the IP address of docker.
51
+
For example, you can add a the next line to your `/etc/hosts` file, if docker is run on IP `127.0.0.1`.
52
+
```
53
+
127.0.0.1 dockerhost
54
+
```
55
+
Alternatively, you may update `config/local.js` and replace `dockerhost` with your docker IP address.<br>
56
+
You may try using command `docker-machine ip` to get your docker IP, but it works not for all systems.
57
+
58
+
Explanation of configs:
59
+
-`config/mock.local.js` - Use local `mock-services` from docker to mock Identity and Member services instead of using deployed at Topcoder dev environment.
60
+
-`config/m2m.local.js` - Use Identity and Member services deployed at Topcoder dev environment. This can be used only if you have M2M environment variables (`AUTH0_CLIENT_ID`, `AUTH0_CLIENT_SECRET`, `AUTH0_URL`, `AUTH0_AUDIENCE`, `AUTH0_PROXY_SERVER_URL`) provided to access Topcoder DEV environment services.
61
+
62
+
* Create tables in DB
63
+
```bash
64
+
NODE_ENV=development npm run sync:db
65
+
```
66
+
This command will crate tables in `postgres` db.
67
+
68
+
*NOTE: this will drop tables if they already exist.*
69
+
70
+
* Sync ES indices
71
+
```bash
72
+
NODE_ENV=development npm run sync:es
73
+
```
74
+
Helper script to sync the indices and mappings with the elasticsearch.
75
+
76
+
*NOTE: This will first clear all the indices and than recreate them. So use with caution.*
77
+
78
+
* Run
79
+
80
+
**NOTE** If you use `config/m2m.local.js` config, you should set M2M environment variables before running the next command.
81
+
```bash
82
+
npm run start:dev
83
+
```
84
+
Runs the Project Service using nodemon, so it would be restarted after any of the files is updated.
85
+
The project service will be served on `http://localhost:8001`.
86
+
87
+
### Import sample metadata & projects
88
+
```bash
89
+
CONNECT_USER_TOKEN=<connect user token> npm run demo-data
28
90
```
91
+
This command will create sample metadata entries in the DB (duplicate what is currently in development environment).
29
92
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`
93
+
To retrieve data from DEV env we need to provide a valid user token. You may login to http://connect.topcoder-dev.com and find the Bearer token in the request headers using browser dev tools.
32
94
33
-
#### Elasticsearch
34
-
Docker compose includes elasticsearch instance as well. It will open ports 9200 & 9300 (kibana)
95
+
### Run Connect App with Project Service locally
35
96
36
-
#### Sync indices and mappings
97
+
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:
98
+
1. Configurate Connect App to use locally deployed Project service inside `connect-app/config/constants/dev.js` set
37
99
38
-
There is a helper script to sync the indices and mappings with the elasticsearch.
100
+
```js
101
+
PROJECTS_API_URL:'http://localhost:8001'
102
+
```
103
+
2. Bypass token validation in Project Service.
39
104
40
-
Run `npm run sync:es` from the root of project to execute the script.
105
+
In `tc-project-service/node_modules/tc-core-library-js/lib/auth/verifier.js` add this to line 23:
106
+
```js
107
+
callback(undefined, decodedToken.payload);
108
+
return;
109
+
```
110
+
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.
41
111
42
-
> NOTE: This will first clear all the indices and than recreate them. So use with caution.
112
+
*NOTE: this change only let us bypass validation during local development process*.
43
113
44
-
**NOTE**: In production these dependencies / services are hosted & managed outside tc-projects-service.
45
-
46
-
#### Kafka
47
-
Kafka must be installed and configured prior starting the application.
48
-
Following topics must be created:
49
-
```
50
-
notifications.connect.project.updated
51
-
notifications.connect.project.files.updated
52
-
notifications.connect.project.team.updated
53
-
notifications.connect.project.plan.updated
54
-
notifications.connect.project.topic.created
55
-
notifications.connect.project.topic.updated
56
-
notifications.connect.project.post.created
57
-
notifications.connect.project.post.edited
58
-
```
59
-
60
-
New Kafka related configuration options has been introduced:
61
-
```
62
-
"kafkaConfig": {
63
-
"hosts": List of Kafka brokers. Default: localhost: 9092
64
-
"clientCert": SSL certificate
65
-
"clientCertKey": Certificate key
66
-
}
67
-
```
68
-
Environment variables:
69
-
-`KAFKA_HOSTS` - same as "hosts"
70
-
-`KAFKA_CLIENT_CERT` - same as "clientCert"
71
-
-`KAFKA_CLIENT_CERT_KEY` - same as "clientCertKey"
114
+
3. Restart both Connect App and Project Service if they were running.
72
115
73
116
### Test
117
+
```bash
118
+
npm run test
119
+
```
120
+
Tests are being executed with the `NODE_ENV` environment variable has a value `test` and `config/test.js` configuration is loaded.
74
121
75
122
Each of the individual modules/services are unit tested.
76
123
77
-
To run unit tests run `npm run test` from root of project.
78
-
79
-
While tests are being executed the `NODE_ENV` environment variable has a value `test` and `config/test.js` configuration is loaded. The default test configuration refers to `projectsdb_test` postgres database. So make sure that this database exists before running the tests. Since we are using docker-compose for local deployment change `local/docker-compose.yaml` postgres service with updated database name and re-create the containers.
80
-
81
-
```
82
-
// stop already executing containers if any
83
-
docker-compose stop -t 1
84
-
// clear the containers
85
-
docker-compose rm -f
86
-
// re-run the services with build flag
87
-
docker-compose up --build
88
-
```
89
-
90
124
#### JWT Authentication
91
125
Authentication is handled via Authorization (Bearer) token header field. Token is a JWT token. Here is a sample token that is valid for a very long time for a user with administrator role.
It's been signed with the secret 'secret'. This secret should match your entry in config/local.js. You can generate your own token using https://jwt.io
96
130
97
131
### Local Deployment
132
+
133
+
**NOTE: This part of README may contain inconsistencies and requires update. Don't follow it unless you know how to properly make configuration for these steps. It's not needed for regular development process.**
134
+
98
135
Build image:
99
136
`docker build -t tc_projects_services .`
100
137
Run image:
@@ -104,4 +141,4 @@ You may replace 172.17.0.1 with your docker0 IP.
104
141
You can paste **swagger.yaml** to [swagger editor](http://editor.swagger.io/) or import **postman.json** and **postman_environment.json** to verify endpoints.
105
142
106
143
#### Deploying without docker
107
-
If you don't want to use docker to deploy to localhost. You can simply run `npm run start` from root of project. This should start the server on default port `3000`.
144
+
If you don't want to use docker to deploy to localhost. You can simply run `npm run start:dev` from root of project. This should start the server on default port `8001`.
0 commit comments