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

Commit 21659dc

Browse files
Merge pull request #37 from topcoder-platform/dynamodb
Replace mongodb with dynamodb
2 parents 6e04ab5 + 88f4b7f commit 21659dc

26 files changed

+1131
-525
lines changed

README.md

Lines changed: 21 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,26 @@ 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
1615
- CHALLENGE_API_URL: the Topcoder challenge API URL
1716
- MEMBER_API_URL: the Topcoder member API URL
18-
- GROUP_IDS: the valid group ids
1917
- AUTH0_URL: Auth0 URL, used to get TC M2M token
2018
- AUTH0_AUDIENCE: Auth0 audience, used to get TC M2M token
2119
- TOKEN_CACHE_TIME: Auth0 token cache time, used to get TC M2M token
2220
- AUTH0_CLIENT_ID: Auth0 client id, used to get TC M2M token
2321
- AUTH0_CLIENT_SECRET: Auth0 client secret, used to get TC M2M token
2422
- AUTH0_PROXY_SERVER_URL: Proxy Auth0 URL, used to get TC M2M token
23+
- AMAZON.AWS_ACCESS_KEY_ID: The Amazon certificate key to use when connecting. For local dynamodb you can set fake value.
24+
- AMAZON.AWS_SECRET_ACCESS_KEY: The Amazon certificate access key to use when connecting. For local dynamodb you can set fake value.
25+
- AMAZON.AWS_REGION: The Amazon region to use when connecting. For local dynamodb you can set fake value.
26+
- AMAZON.DYNAMODB_READ_CAPACITY_UNITS: the AWS DynamoDB read capacity units
27+
- AMAZON.DYNAMODB_WRITE_CAPACITY_UNITS: the AWS DynamoDB write capacity units
28+
- AMAZON.IS_LOCAL_DB: Use local or AWS Amazon DynamoDB
29+
- AMAZON.DYNAMODB_URL: The local url, if using local Amazon DynamoDB
30+
- HEALTH_CHECK_TIMEOUT: health check timeout in milliseconds
31+
32+
## Local DynamoDB
33+
Change to the ./docker-dynamodb directory and run `docker-compose up`.
34+
An instance of DynamoDB listening on port `8000` will be initialized inside docker.
2535

2636
## Local deployment
2737

@@ -39,6 +49,12 @@ npm run lint
3949
npm run lint:fix # To fix possible lint errors
4050
```
4151

52+
- Make sure DynamoDB instance is up and create tables
53+
54+
```bash
55+
npm run create-tables
56+
```
57+
4258
- Clear and Insert data into database
4359

4460
```bash
@@ -57,16 +73,8 @@ npm start
5773

5874
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.
5975

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-
6976
## Verification
77+
First of all, ensure you have started local DynamoDB and created tables.
7078

7179
### Tests
7280

@@ -90,7 +98,7 @@ npm run e2e
9098
npm run mock-api
9199
```
92100

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.
101+
- Run the following commands clear and insert test data, step up environment variables and start the app.
94102

95103
```bash
96104
npm run init-db

config/default.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,27 @@ module.exports = {
99
VALID_ISSUERS: process.env.VALID_ISSUERS ? process.env.VALID_ISSUERS.replace(/\\"/g, '')
1010
: '["https://topcoder-dev.auth0.com/", "https://api.topcoder.com"]',
1111

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

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

2017
AUTH0_URL: process.env.AUTH0_URL || 'https://topcoder-dev.auth0.com/oauth/token',
2118
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE || 'https://m2m.topcoder-dev.com/',
2219
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
20+
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
21+
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
22+
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,
23+
24+
AMAZON: {
25+
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
26+
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,
27+
AWS_REGION: process.env.AWS_REGION || 'us-east-1',
28+
DYNAMODB_READ_CAPACITY_UNITS: process.env.DYNAMODB_READ_CAPACITY_UNITS || 10,
29+
DYNAMODB_WRITE_CAPACITY_UNITS: process.env.DYNAMODB_WRITE_CAPACITY_UNITS || 5,
30+
IS_LOCAL_DB: process.env.IS_LOCAL_DB ? process.env.IS_LOCAL_DB === 'true' : false,
31+
// Below configuration is required if IS_LOCAL_DB is true
32+
DYNAMODB_URL: process.env.DYNAMODB_URL || 'http://localhost:8000'
33+
},
34+
HEALTH_CHECK_TIMEOUT: process.env.HEALTH_CHECK_TIMEOUT || 3000
2635
}

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)