Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 91d3e99

Browse files
authored
Merge pull request #38 from topcoder-platform/develop
Sync master with dev
2 parents 0867a9c + 0a1e521 commit 91d3e99

27 files changed

+1290
-543
lines changed

README.md

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Dependencies
44

55
- Nodejs (v10)
6-
- Mongodb (v4)
6+
- AWS DynamoDB
77

88
## Configuration
99

@@ -12,16 +12,34 @@ The following parameters can be set in config files or in env variables:
1212

1313
- LOG_LEVEL: the log level
1414
- PORT: the server port
15-
- MONGODB_URL: Mongo DB URL
15+
- API_VERSION: the API version
1616
- CHALLENGE_API_URL: the Topcoder challenge API URL
1717
- MEMBER_API_URL: the Topcoder member API URL
18-
- GROUP_IDS: the valid group ids
1918
- AUTH0_URL: Auth0 URL, used to get TC M2M token
2019
- AUTH0_AUDIENCE: Auth0 audience, used to get TC M2M token
2120
- TOKEN_CACHE_TIME: Auth0 token cache time, used to get TC M2M token
2221
- AUTH0_CLIENT_ID: Auth0 client id, used to get TC M2M token
2322
- AUTH0_CLIENT_SECRET: Auth0 client secret, used to get TC M2M token
2423
- AUTH0_PROXY_SERVER_URL: Proxy Auth0 URL, used to get TC M2M token
24+
- AMAZON.AWS_ACCESS_KEY_ID: The Amazon certificate key to use when connecting. For local dynamodb you can set fake value.
25+
- AMAZON.AWS_SECRET_ACCESS_KEY: The Amazon certificate access key to use when connecting. For local dynamodb you can set fake value.
26+
- AMAZON.AWS_REGION: The Amazon region to use when connecting. For local dynamodb you can set fake value.
27+
- AMAZON.DYNAMODB_READ_CAPACITY_UNITS: the AWS DynamoDB read capacity units
28+
- AMAZON.DYNAMODB_WRITE_CAPACITY_UNITS: the AWS DynamoDB write capacity units
29+
- AMAZON.IS_LOCAL_DB: Use local or AWS Amazon DynamoDB
30+
- AMAZON.DYNAMODB_URL: The local url, if using local Amazon DynamoDB
31+
- HEALTH_CHECK_TIMEOUT: health check timeout in milliseconds
32+
- BUSAPI_URL: Topcoder Bus API URL
33+
- KAFKA_ERROR_TOPIC: The error topic at which bus api will publish any errors
34+
- KAFKA_MESSAGE_ORIGINATOR: The originator value for the kafka messages
35+
- LEADERBOARD_CREATE_TOPIC: Kafka topic for create message
36+
- LEADERBOARD_UPDATE_TOPIC: Kafka topic for update message
37+
- LEADERBOARD_DELETE_TOPIC: Kafka topic for delete message
38+
- LEADERBOARD_AGGREGATE_TOPIC: Kafka topic that is used to combine all create, update and delete message(s)
39+
40+
## Local DynamoDB
41+
Change to the ./docker-dynamodb directory and run `docker-compose up`.
42+
An instance of DynamoDB listening on port `8000` will be initialized inside docker.
2543

2644
## Local deployment
2745

@@ -39,6 +57,12 @@ npm run lint
3957
npm run lint:fix # To fix possible lint errors
4058
```
4159

60+
- Make sure DynamoDB instance is up and create tables
61+
62+
```bash
63+
npm run create-tables
64+
```
65+
4266
- Clear and Insert data into database
4367

4468
```bash
@@ -57,16 +81,8 @@ npm start
5781

5882
For verification purpose, we need a mock app for Topcoder Challenge API and Topcoder Member API. You can run command `npm run mock-api` to start the mock app.
5983

60-
## Heroku Deployment
61-
62-
- git init
63-
- git add .
64-
- git commit -m init
65-
- heroku create
66-
- heroku config:set MONGODB_URL=...
67-
- git push heroku master
68-
6984
## Verification
85+
First of all, ensure you have started local DynamoDB and created tables.
7086

7187
### Tests
7288

@@ -90,7 +106,7 @@ npm run e2e
90106
npm run mock-api
91107
```
92108

93-
- Ensure you have start MongoDB and properly configure `MONGODB_URL`. Run the following commands to clear and insert test data, step up environment variables and start the app.
109+
- Run the following commands clear and insert test data, step up environment variables and start the app.
94110

95111
```bash
96112
npm run init-db

config/default.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,40 @@
55
module.exports = {
66
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
77
PORT: process.env.PORT || 3000,
8+
API_VERSION: process.env.API_VERSION || '/v5',
89
AUTH_SECRET: process.env.AUTH_SECRET || 'mysecret',
910
VALID_ISSUERS: process.env.VALID_ISSUERS ? process.env.VALID_ISSUERS.replace(/\\"/g, '')
1011
: '["https://topcoder-dev.auth0.com/", "https://api.topcoder.com"]',
1112

12-
MONGODB_URL: process.env.MONGODB_URL || 'mongodb://localhost:27017/leaderboardDB',
1313
CHALLENGE_API_URL: process.env.CHALLENGE_API_URL || 'https://api.topcoder-dev.com/v5/challenges',
1414
MEMBER_API_URL: process.env.MEMBER_API_URL || 'https://api.topcoder-dev.com/v5/members',
1515

16-
GROUP_IDS: process.env.GROUP_IDS || '202343,20000000', // Comma separated string of Group IDs,
17-
1816
SCORE_RESET_TIME: process.env.SCORE_RESET_TIME || 10000, // 10 seconds default
1917

2018
AUTH0_URL: process.env.AUTH0_URL || 'https://topcoder-dev.auth0.com/oauth/token',
2119
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE || 'https://m2m.topcoder-dev.com/',
2220
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME || 90,
23-
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID || '8QovDh27SrDu1XSs68m21A1NBP8isvOt',
24-
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET || '3QVxxu20QnagdH-McWhVz0WfsQzA1F8taDdGDI4XphgpEYZPcMTF4lX3aeOIeCzh',
25-
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL
21+
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
22+
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
23+
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,
24+
25+
AMAZON: {
26+
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
27+
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,
28+
AWS_REGION: process.env.AWS_REGION || 'us-east-1',
29+
DYNAMODB_READ_CAPACITY_UNITS: process.env.DYNAMODB_READ_CAPACITY_UNITS || 10,
30+
DYNAMODB_WRITE_CAPACITY_UNITS: process.env.DYNAMODB_WRITE_CAPACITY_UNITS || 5,
31+
IS_LOCAL_DB: process.env.IS_LOCAL_DB ? process.env.IS_LOCAL_DB === 'true' : false,
32+
// Below configuration is required if IS_LOCAL_DB is true
33+
DYNAMODB_URL: process.env.DYNAMODB_URL || 'http://localhost:8000'
34+
},
35+
HEALTH_CHECK_TIMEOUT: process.env.HEALTH_CHECK_TIMEOUT || 3000,
36+
37+
BUSAPI_URL: process.env.BUSAPI_URL || 'https://api.topcoder-dev.com/v5',
38+
KAFKA_ERROR_TOPIC: process.env.KAFKA_ERROR_TOPIC || 'common.error.reporting',
39+
KAFKA_MESSAGE_ORIGINATOR: process.env.KAFKA_MESSAGE_ORIGINATOR || 'leaderboard-api',
40+
LEADERBOARD_CREATE_TOPIC: process.env.LEADERBOARD_CREATE_TOPIC || 'leaderboard.action.create',
41+
LEADERBOARD_UPDATE_TOPIC: process.env.LEADERBOARD_UPDATE_TOPIC || 'leaderboard.action.update',
42+
LEADERBOARD_DELETE_TOPIC: process.env.LEADERBOARD_DELETE_TOPIC || 'leaderboard.action.delete',
43+
LEADERBOARD_AGGREGATE_TOPIC: process.env.LEADERBOARD_AGGREGATE_TOPIC || 'leaderboard.action.aggregate'
2644
}

config/test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
*/
44

55
module.exports = {
6-
CHALLENGE_API_URL: 'https://api.topcoder-dev.com/v4/challenges',
7-
MEMBER_API_URL: 'https://api.topcoder-dev.com/v3/users',
8-
MOCK_API_PORT: 3001,
9-
MONGODB_URL: process.env.TEST_MONGODB_URL || 'mongodb://localhost:27017/leaderboardDB_test'
6+
CHALLENGE_API_URL: 'https://api.topcoder-dev.com/v5/challenges',
7+
MEMBER_API_URL: 'https://api.topcoder-dev.com/v5/members',
8+
MOCK_API_PORT: 3001
109
}

docker-dynamodb/docker-compose.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: '3'
2+
services:
3+
dynamodb:
4+
image: amazon/dynamodb-local
5+
ports:
6+
- "8000:8000"

0 commit comments

Comments
 (0)