topcoder-platform / challenge-api

This microservice provides access and interaction with all sorts of Challenge data
16 stars 49 forks source link
api aws docker dynamodb elasticsearch nodejs

Topcoder Challenge API

This microservice provides access and interaction with all sorts of Challenge data.

Devlopment status

Total alertsLanguage grade: JavaScript

Deployment status

Dev: CircleCI Prod: CircleCI

Swagger definition

Intended use

Related repos

Prerequisites

Configuration

Configuration for the application is at config/default.js. The following parameters can be set in config files or in env variables:

You can find sample .env files inside the /docs directory.

Available commands

  1. Drop/delete tables: npm run drop-tables
  2. Creating tables: npm run create-tables
  3. Seed/Insert data to tables: npm run seed-tables
  4. Initialize/Clear database in default environment: npm run init-db
  5. View table data in default environment: npm run view-data <ModelName>, ModelName can be Challenge, ChallengeType, AuditLog, Phase, TimelineTemplateor Attachment
  6. Create Elasticsearch index: npm run init-es, or to re-create index: npm run init-es force
  7. Synchronize ES data and DynamoDB data: npm run sync-es
  8. Start all the depending services for local deployment: npm run services:up
  9. Stop all the depending services for local deployment: npm run services:down
  10. Check the logs of all the depending services for local deployment: npm run services:logs
  11. Initialize the local environments: npm run local:init
  12. Reset the local environments: npm run local:reset

Notes

Local Deployment

  1. Make sure to use Node v10+ by command node -v. We recommend using NVM to quickly switch to the right version:

    nvm use
  2. 📦 Install npm dependencies

    # export the production AWS credentials to access the topcoder-framework private repos in AWS codeartifact
    aws codeartifact login --tool npm --repository topcoder-framework --domain topcoder --domain-owner 409275337247 --region us-east-1 --namespace @topcoder-framework
    
    # install dependencies
    yarn install
  3. ⚙ Local config
    In the challenge-api root directory create .env file with the next environment variables. Values for Auth0 config should be shared with you on the forum.

    # Auth0 config
    AUTH0_URL=
    AUTH0_PROXY_SERVER_URL=
    AUTH0_AUDIENCE=
    AUTH0_CLIENT_ID=
    AUTH0_CLIENT_SECRET=
    
    # Locally deployed services (via docker-compose)
    IS_LOCAL_DB=true
    DYNAMODB_URL=http://localhost:8000
    • Values from this file would be automatically used by many npm commands.
    • ⚠️ Never commit this file or its copy to the repository!
  4. 🚢 Start docker-compose with services which are required to start Topcoder Challenges API locally

    npm run services:up
  5. ♻ Update following two parts:

  1. ♻ Create tables.

    npm run create-tables
    # Use `npm run drop-tables` to drop tables.
  2. ♻ Init DB, ES

    npm run local:init

    This command will do 3 things:

  1. 🚀 Start Topcoder Challenge API

    npm start

    The Topcoder Challenge API will be served on http://localhost:3000

Production deployment

Running tests

Configuration

Test configuration is at config/test.js. You don't need to change them. The following test parameters can be set in config file or in env variables:

Prepare

Seeding db data is not needed.

Running unit tests

To run unit tests alone

npm run test

To run unit tests with coverage report

npm run test:cov

Running integration tests

To run integration tests alone

npm run e2e

To run integration tests with coverage report

npm run e2e:cov

Verification

Refer to the verification document Verification.md

Notes