Skip to content

Commit ab2f48f

Browse files
author
vikasrohit
authored
Merge pull request #295 from topcoder-platform/dev
Supporting Release Connect 2.4.11
2 parents dafc612 + bf86adf commit ab2f48f

File tree

127 files changed

+12313
-2518
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+12313
-2518
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ deploy_steps: &deploy_steps
3232
./buildenv.sh -e $DEPLOY_ENV -b ${VAR_ENV}-tc-project-service-deployvar
3333
source buildenvvar
3434
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${VAR_ENV}-global-appvar,${VAR_ENV}-tc-project-service-appvar -i tc-project-service -p FARGATE
35+
3536
echo "======= Running Masterscript - deploy tc-project-service-consumers ==========="
3637
if [ -e ${VAR_ENV}-tc-project-service-appvar.json ]; then sudo rm -vf ${VAR_ENV}-tc-project-service-appvar.json; fi
3738
./buildenv.sh -e $DEPLOY_ENV -b ${VAR_ENV}-tc-project-service-consumers-deployvar

.eslintignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
config/local.js
2-
config/sample.local.js
2+
config/mock.local.js
3+
config/m2m.local.js
4+
local/seed/
35
node_modules
46
dist
57
.ebextensions

README.md

Lines changed: 104 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,89 +4,123 @@ 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
2214

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
2890
```
91+
This command will create sample metadata entries in the DB (duplicate what is currently in development environment).
2992

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.
3294

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
3596

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
3799

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.
39104

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.
41111

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*.
43113

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.
72115

73116
### 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.
74121

75122
Each of the individual modules/services are unit tested.
76123

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-
90124
#### JWT Authentication
91125
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.
92126
```
@@ -95,6 +129,9 @@ eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJhZG1pbmlzdHJhdG9yIl0sImlzcyI
95129
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
96130

97131
### 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+
98135
Build image:
99136
`docker build -t tc_projects_services .`
100137
Run image:
@@ -104,4 +141,4 @@ You may replace 172.17.0.1 with your docker0 IP.
104141
You can paste **swagger.yaml** to [swagger editor](http://editor.swagger.io/) or import **postman.json** and **postman_environment.json** to verify endpoints.
105142

106143
#### 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`.

build.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
JQ="jq --raw-output --exit-status"
55

66
ENV=$1
7-
AWS_REGION=$(eval "echo \$${ENV}_AWS_REGION")
8-
ACCOUNT_ID=$(eval "echo \$${ENV}_AWS_ACCOUNT_ID")
7+
#AWS_REGION=$(eval "echo \$${ENV}_AWS_REGION")
8+
#ACCOUNT_ID=$(eval "echo \$${ENV}_AWS_ACCOUNT_ID")
99
AWS_REPOSITORY=$(eval "echo \$${ENV}_AWS_REPOSITORY")
1010

1111
build() {
12-
docker build -t $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$AWS_REPOSITORY:$CIRCLE_SHA1 .
12+
docker build -t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$AWS_REPOSITORY:$CIRCLE_SHA1 .
1313
}
1414

15-
build
15+
build

config/default.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@
5858
"inviteEmailSubject": "You are invited to Topcoder",
5959
"inviteEmailSectionTitle": "Project Invitation",
6060
"connectUrl":"https://connect.topcoder-dev.com",
61-
"accountsAppUrl": "https://accounts.topcoder-dev.com"
62-
61+
"accountsAppUrl": "https://accounts.topcoder-dev.com",
62+
"MAX_REVISION_NUMBER": 100
6363
}

config/m2m.local.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// force using test.json for unit tests
2+
3+
let config;
4+
if (process.env.NODE_ENV === 'test') {
5+
config = require('./test.json');
6+
} else {
7+
config = {
8+
identityServiceEndpoint: "https://api.topcoder-dev.com/v3/",
9+
authSecret: 'secret',
10+
authDomain: 'topcoder-dev.com',
11+
logLevel: 'debug',
12+
captureLogs: 'false',
13+
logentriesToken: '',
14+
rabbitmqURL: 'amqp://dockerhost:5672',
15+
fileServiceEndpoint: 'https://api.topcoder-dev.com/v3/files/',
16+
directProjectServiceEndpoint: 'https://api.topcoder-dev.com/v3/direct',
17+
connectProjectsUrl: 'https://connect.topcoder-dev.com/projects/',
18+
memberServiceEndpoint: 'https://api.topcoder-dev.com/v3/members',
19+
dbConfig: {
20+
masterUrl: 'postgres://coder:mysecretpassword@dockerhost:5432/projectsdb',
21+
maxPoolSize: 50,
22+
minPoolSize: 4,
23+
idleTimeout: 1000,
24+
},
25+
elasticsearchConfig: {
26+
host: 'dockerhost:9200',
27+
// target elasticsearch 2.3 version
28+
apiVersion: '2.3',
29+
indexName: 'projects',
30+
docType: 'projectV4'
31+
},
32+
whitelistedOriginsForUserIdAuth: "[\"\"]",
33+
};
34+
}
35+
module.exports = config;
File renamed without changes.

config/test.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"AUTH_SECRET": "secret",
3+
"MAX_REVISION_NUMBER": 2,
34
"logLevel": "debug",
45
"captureLogs": "false",
56
"logentriesToken": "",
@@ -14,7 +15,7 @@
1415
"rabbitmqUrl": "amqp://localhost:5672",
1516
"connectProjectsUrl": "https://local.topcoder-dev.com/projects/",
1617
"dbConfig": {
17-
"masterUrl": "postgres://coder:mysecretpassword@localhost:5432/projectsdb_test",
18+
"masterUrl": "postgres://coder:mysecretpassword@localhost:5433/projectsdb_test",
1819
"maxPoolSize": 50,
1920
"minPoolSize": 4,
2021
"idleTimeout": 1000

deploy.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ JQ="jq --raw-output --exit-status"
55

66
ENV=$1
77
COUNTER_LIMIT=20
8-
ACCOUNT_ID=$(eval "echo \$${ENV}_AWS_ACCOUNT_ID")
9-
AWS_REGION=$(eval "echo \$${ENV}_AWS_REGION")
8+
#ACCOUNT_ID=$(eval "echo \$${ENV}_AWS_ACCOUNT_ID")
9+
#AWS_REGION=$(eval "echo \$${ENV}_AWS_REGION")
1010
AWS_ECS_CONTAINER_NAME="tc-project-service"
1111
AWS_REPOSITORY=$(eval "echo \$${ENV}_AWS_REPOSITORY")
1212
AWS_ECS_CLUSTER=$(eval "echo \$${ENV}_AWS_ECS_CLUSTER")
@@ -283,12 +283,12 @@ make_task_def(){
283283
INVITE_EMAIL_SUBJECT=$(eval "echo \$${ENV}_INVITE_EMAIL_SUBJECT")
284284
INVITE_EMAIL_SECTION_TITLE=$(eval "echo \$${ENV}_INVITE_EMAIL_SECTION_TITLE")
285285

286-
task_def=$(printf "$task_template" $1 $ACCOUNT_ID $ACCOUNT_ID $AWS_ECS_CONTAINER_NAME $ACCOUNT_ID $AWS_REGION $AWS_REPOSITORY $CIRCLE_SHA1 $2 $3 $4 $NODE_ENV $ENABLE_FILE_UPLOAD $LOG_LEVEL $CAPTURE_LOGS $LOGENTRIES_TOKEN $API_VERSION $AWS_REGION $AUTH_DOMAIN $AUTH_SECRET $VALID_ISSUERS $DB_MASTER_URL $MEMBER_SERVICE_ENDPOINT $IDENTITY_SERVICE_ENDPOINT $BUS_API_URL $MESSAGE_SERVICE_URL $SYSTEM_USER_CLIENT_ID $SYSTEM_USER_CLIENT_SECRET $PROJECTS_ES_URL $PROJECTS_ES_INDEX_NAME $RABBITMQ_URL $DIRECT_PROJECT_SERVICE_ENDPOINT $FILE_SERVICE_ENDPOINT $CONNECT_PROJECTS_URL $CONNECT_URL $ACCOUNTS_APP_URL $SEGMENT_ANALYTICS_KEY "$AUTH0_URL" "$AUTH0_AUDIENCE" $AUTH0_CLIENT_ID "$AUTH0_CLIENT_SECRET" $TOKEN_CACHE_TIME "$KAFKA_CLIENT_CERT" "$KAFKA_CLIENT_CERT_KEY" $KAFKA_GROUP_ID $KAFKA_URL "$AUTH0_PROXY_SERVER_URL" "$EMAIL_INVITE_FROM_NAME" "$EMAIL_INVITE_FROM_EMAIL" "$INVITE_EMAIL_SUBJECT" "$INVITE_EMAIL_SECTION_TITLE" $PORT $PORT $AWS_ECS_CLUSTER $AWS_REGION $NODE_ENV)
286+
task_def=$(printf "$task_template" $1 $AWS_ACCOUNT_ID $AWS_ACCOUNT_ID $AWS_ECS_CONTAINER_NAME $AWS_ACCOUNT_ID $AWS_REGION $AWS_REPOSITORY $CIRCLE_SHA1 $2 $3 $4 $NODE_ENV $ENABLE_FILE_UPLOAD $LOG_LEVEL $CAPTURE_LOGS $LOGENTRIES_TOKEN $API_VERSION $AWS_REGION $AUTH_DOMAIN $AUTH_SECRET $VALID_ISSUERS $DB_MASTER_URL $MEMBER_SERVICE_ENDPOINT $IDENTITY_SERVICE_ENDPOINT $BUS_API_URL $MESSAGE_SERVICE_URL $SYSTEM_USER_CLIENT_ID $SYSTEM_USER_CLIENT_SECRET $PROJECTS_ES_URL $PROJECTS_ES_INDEX_NAME $RABBITMQ_URL $DIRECT_PROJECT_SERVICE_ENDPOINT $FILE_SERVICE_ENDPOINT $CONNECT_PROJECTS_URL $CONNECT_URL $ACCOUNTS_APP_URL $SEGMENT_ANALYTICS_KEY "$AUTH0_URL" "$AUTH0_AUDIENCE" $AUTH0_CLIENT_ID "$AUTH0_CLIENT_SECRET" $TOKEN_CACHE_TIME "$KAFKA_CLIENT_CERT" "$KAFKA_CLIENT_CERT_KEY" $KAFKA_GROUP_ID $KAFKA_URL "$AUTH0_PROXY_SERVER_URL" "$EMAIL_INVITE_FROM_NAME" "$EMAIL_INVITE_FROM_EMAIL" "$INVITE_EMAIL_SUBJECT" "$INVITE_EMAIL_SECTION_TITLE" $PORT $PORT $AWS_ECS_CLUSTER $AWS_REGION $NODE_ENV)
287287
}
288288

289289
push_ecr_image(){
290290
eval $(aws ecr get-login --region $AWS_REGION --no-include-email)
291-
docker push $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$1:$CIRCLE_SHA1
291+
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$1:$CIRCLE_SHA1
292292
}
293293

294294
register_definition() {
@@ -319,11 +319,11 @@ check_service_status() {
319319
echo "$servicestatus"
320320
}
321321

322-
configure_aws_cli
322+
#configure_aws_cli
323323
push_ecr_image $AWS_REPOSITORY
324324
deploy_cluster $AWS_ECS_SERVICE "npm" "run" "start"
325325

326326
deploy_cluster $AWS_ECS_SERVICE_CONSUMERS "npm" "run" "startKafkaConsumers"
327327

328328
check_service_status $AWS_ECS_SERVICE
329-
check_service_status $AWS_ECS_SERVICE_CONSUMERS
329+
check_service_status $AWS_ECS_SERVICE_CONSUMERS

local/docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ services:
1212
- POSTGRES_PASSWORD=mysecretpassword
1313
- POSTGRES_USER=coder
1414
- POSTGRES_DB=projectsdb
15+
db_test:
16+
image: "postgres:9.5"
17+
ports:
18+
- "5433:5432"
19+
environment:
20+
- POSTGRES_PASSWORD=mysecretpassword
21+
- POSTGRES_USER=coder
22+
- POSTGRES_DB=projectsdb_test
1523
esearch:
1624
image: "elasticsearch:2.3"
1725
ports:

0 commit comments

Comments
 (0)