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

Sync master with dev #38

Merged
merged 13 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Dependencies

- Nodejs (v10)
- Mongodb (v4)
- AWS DynamoDB

## Configuration

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

- LOG_LEVEL: the log level
- PORT: the server port
- MONGODB_URL: Mongo DB URL
- API_VERSION: the API version
- CHALLENGE_API_URL: the Topcoder challenge API URL
- MEMBER_API_URL: the Topcoder member API URL
- GROUP_IDS: the valid group ids
- AUTH0_URL: Auth0 URL, used to get TC M2M token
- AUTH0_AUDIENCE: Auth0 audience, used to get TC M2M token
- TOKEN_CACHE_TIME: Auth0 token cache time, used to get TC M2M token
- AUTH0_CLIENT_ID: Auth0 client id, used to get TC M2M token
- AUTH0_CLIENT_SECRET: Auth0 client secret, used to get TC M2M token
- AUTH0_PROXY_SERVER_URL: Proxy Auth0 URL, used to get TC M2M token
- AMAZON.AWS_ACCESS_KEY_ID: The Amazon certificate key to use when connecting. For local dynamodb you can set fake value.
- AMAZON.AWS_SECRET_ACCESS_KEY: The Amazon certificate access key to use when connecting. For local dynamodb you can set fake value.
- AMAZON.AWS_REGION: The Amazon region to use when connecting. For local dynamodb you can set fake value.
- AMAZON.DYNAMODB_READ_CAPACITY_UNITS: the AWS DynamoDB read capacity units
- AMAZON.DYNAMODB_WRITE_CAPACITY_UNITS: the AWS DynamoDB write capacity units
- AMAZON.IS_LOCAL_DB: Use local or AWS Amazon DynamoDB
- AMAZON.DYNAMODB_URL: The local url, if using local Amazon DynamoDB
- HEALTH_CHECK_TIMEOUT: health check timeout in milliseconds
- BUSAPI_URL: Topcoder Bus API URL
- KAFKA_ERROR_TOPIC: The error topic at which bus api will publish any errors
- KAFKA_MESSAGE_ORIGINATOR: The originator value for the kafka messages
- LEADERBOARD_CREATE_TOPIC: Kafka topic for create message
- LEADERBOARD_UPDATE_TOPIC: Kafka topic for update message
- LEADERBOARD_DELETE_TOPIC: Kafka topic for delete message
- LEADERBOARD_AGGREGATE_TOPIC: Kafka topic that is used to combine all create, update and delete message(s)

## Local DynamoDB
Change to the ./docker-dynamodb directory and run `docker-compose up`.
An instance of DynamoDB listening on port `8000` will be initialized inside docker.

## Local deployment

Expand All @@ -39,6 +57,12 @@ npm run lint
npm run lint:fix # To fix possible lint errors
```

- Make sure DynamoDB instance is up and create tables

```bash
npm run create-tables
```

- Clear and Insert data into database

```bash
Expand All @@ -57,16 +81,8 @@ npm start

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.

## Heroku Deployment

- git init
- git add .
- git commit -m init
- heroku create
- heroku config:set MONGODB_URL=...
- git push heroku master

## Verification
First of all, ensure you have started local DynamoDB and created tables.

### Tests

Expand All @@ -90,7 +106,7 @@ npm run e2e
npm run mock-api
```

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

```bash
npm run init-db
Expand Down
30 changes: 24 additions & 6 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,40 @@
module.exports = {
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
PORT: process.env.PORT || 3000,
API_VERSION: process.env.API_VERSION || '/v5',
AUTH_SECRET: process.env.AUTH_SECRET || 'mysecret',
VALID_ISSUERS: process.env.VALID_ISSUERS ? process.env.VALID_ISSUERS.replace(/\\"/g, '')
: '["https://topcoder-dev.auth0.com/", "https://api.topcoder.com"]',

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

GROUP_IDS: process.env.GROUP_IDS || '202343,20000000', // Comma separated string of Group IDs,

SCORE_RESET_TIME: process.env.SCORE_RESET_TIME || 10000, // 10 seconds default

AUTH0_URL: process.env.AUTH0_URL || 'https://topcoder-dev.auth0.com/oauth/token',
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE || 'https://m2m.topcoder-dev.com/',
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME || 90,
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID || '8QovDh27SrDu1XSs68m21A1NBP8isvOt',
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET || '3QVxxu20QnagdH-McWhVz0WfsQzA1F8taDdGDI4XphgpEYZPcMTF4lX3aeOIeCzh',
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,

AMAZON: {
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,
AWS_REGION: process.env.AWS_REGION || 'us-east-1',
DYNAMODB_READ_CAPACITY_UNITS: process.env.DYNAMODB_READ_CAPACITY_UNITS || 10,
DYNAMODB_WRITE_CAPACITY_UNITS: process.env.DYNAMODB_WRITE_CAPACITY_UNITS || 5,
IS_LOCAL_DB: process.env.IS_LOCAL_DB ? process.env.IS_LOCAL_DB === 'true' : false,
// Below configuration is required if IS_LOCAL_DB is true
DYNAMODB_URL: process.env.DYNAMODB_URL || 'http://localhost:8000'
},
HEALTH_CHECK_TIMEOUT: process.env.HEALTH_CHECK_TIMEOUT || 3000,

BUSAPI_URL: process.env.BUSAPI_URL || 'https://api.topcoder-dev.com/v5',
KAFKA_ERROR_TOPIC: process.env.KAFKA_ERROR_TOPIC || 'common.error.reporting',
KAFKA_MESSAGE_ORIGINATOR: process.env.KAFKA_MESSAGE_ORIGINATOR || 'leaderboard-api',
LEADERBOARD_CREATE_TOPIC: process.env.LEADERBOARD_CREATE_TOPIC || 'leaderboard.action.create',
LEADERBOARD_UPDATE_TOPIC: process.env.LEADERBOARD_UPDATE_TOPIC || 'leaderboard.action.update',
LEADERBOARD_DELETE_TOPIC: process.env.LEADERBOARD_DELETE_TOPIC || 'leaderboard.action.delete',
LEADERBOARD_AGGREGATE_TOPIC: process.env.LEADERBOARD_AGGREGATE_TOPIC || 'leaderboard.action.aggregate'
}
7 changes: 3 additions & 4 deletions config/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*/

module.exports = {
CHALLENGE_API_URL: 'https://api.topcoder-dev.com/v4/challenges',
MEMBER_API_URL: 'https://api.topcoder-dev.com/v3/users',
MOCK_API_PORT: 3001,
MONGODB_URL: process.env.TEST_MONGODB_URL || 'mongodb://localhost:27017/leaderboardDB_test'
CHALLENGE_API_URL: 'https://api.topcoder-dev.com/v5/challenges',
MEMBER_API_URL: 'https://api.topcoder-dev.com/v5/members',
MOCK_API_PORT: 3001
}
6 changes: 6 additions & 0 deletions docker-dynamodb/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3'
services:
dynamodb:
image: amazon/dynamodb-local
ports:
- "8000:8000"
Loading