Skip to content

Commit fd04800

Browse files
documentation changes
1 parent 4770676 commit fd04800

File tree

3 files changed

+74
-36
lines changed

3 files changed

+74
-36
lines changed

README.md

+66-34
Original file line numberDiff line numberDiff line change
@@ -81,50 +81,82 @@ You can find sample `.env` files inside the `/docs` directory.
8181
5. View table data in default environment: `npm run view-data <ModelName>`, ModelName can be `Challenge`, `ChallengeType`, `AuditLog`, `Phase`, `TimelineTemplate`or `Attachment`
8282
6. Create Elasticsearch index: `npm run init-es`, or to re-create index: `npm run init-es force`
8383
7. Synchronize ES data and DynamoDB data: `npm run sync-es`
84+
8. Start all the depending services for local deployment: `npm run services:up`
85+
9. Stop all the depending services for local deployment: `npm run services:down`
86+
10. Check the logs of all the depending services for local deployment: `npm run services:logs`
87+
11. Initialize the local environments: `npm run local:init`
88+
12. Reset the local environments: `npm run local:reset`
89+
8490

8591
### Notes
8692
- The seed data are located in `src/scripts/seed`
8793

8894
## Local Deployment
95+
0. Make sure to use Node v10+ by command `node -v`. We recommend using [NVM](https://github.com/nvm-sh/nvm) to quickly switch to the right version:
96+
97+
```bash
98+
nvm use
99+
```
100+
101+
1. 📦 Install npm dependencies
102+
103+
```bash
104+
npm install
105+
```
106+
107+
2. ⚙ Local config
108+
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.<br>
109+
```bash
110+
# Auth0 config
111+
AUTH0_URL=
112+
AUTH0_PROXY_SERVER_URL=
113+
AUTH0_AUDIENCE=
114+
AUTH0_CLIENT_ID=
115+
AUTH0_CLIENT_SECRET=
116+
117+
# Locally deployed services (via docker-compose)
118+
IS_LOCAL_DB=true
119+
DYNAMODB_URL=http://localhost:8000
120+
```
121+
122+
- Values from this file would be automatically used by many `npm` commands.
123+
- ⚠️ Never commit this file or its copy to the repository!
124+
125+
3. 🚢 Start docker-compose with services which are required to start Topcoder Challenges API locally
126+
127+
```bash
128+
npm run services:up
129+
```
130+
131+
4. ♻ Update following two parts:
132+
- https://github.com/topcoder-platform/challenge-api/blob/develop/src/models/Challenge.js#L116
133+
`throughput: 'ON_DEMAND',` should be updated to `throughput:{ read: 4, write: 2 },`
134+
- https://github.com/topcoder-platform/challenge-api/blob/develop/config/default.js#L27-L28
89135

90-
### AWS S3 Setup
91-
Go to https://console.aws.amazon.com/ and login. Choose S3 from Service folder and click `Create bucket`. Following the instruction to create S3 bucket.
136+
5. ♻ Create tables.
92137

93-
### Local services setup
94-
In the `local` folder, run `docker-compose up` to start Elasticsearch, DynamoDB, S3 compatible server and Mock API.
138+
```bash
139+
npm run create-tables
140+
# Use `npm run drop-tables` to drop tables.
141+
```
95142

96-
### Create Tables
97-
1. Make sure DynamoDB are running as per instructions above.
98-
2. Make sure you have configured all config parameters. Refer [Configuration](#configuration)
99-
3. Run `npm run create-tables` to create tables.
143+
6. ♻ Init DB, ES
100144

101-
### Mock API
102-
The provided mock API provides mock endpoint to fetch challenge resources and groups so you don't have to deploy the related services locally.
103-
You need to ensure DynamoDB configuration in `mock-api/config/default.js` is consistent with `config/default.js`
104-
Mock API starts after running `docker-compose up` and expose port 4000.
145+
```bash
146+
npm run local:init
147+
```
105148

106-
### Notes
107-
There are two parts need to be updated for local development
108-
- https://github.com/topcoder-platform/challenge-api/blob/develop/src/models/Challenge.js#L116
109-
`throughput: 'ON_DEMAND',` should be updated to `throughput:{ read: 4, write: 2 },`
110-
- https://github.com/topcoder-platform/challenge-api/blob/develop/config/default.js#L27-L28
111-
Two aws config should be uncommented
112-
113-
and AUTH0 related configuration must be set at config file or in env variables.
114-
115-
### Deploy the app
116-
117-
- Follow the Notes section above
118-
- Install dependencies `npm install`
119-
- Run lint `npm run lint`
120-
- Run lint fix `npm run lint:fix`
121-
- initialize Elasticsearch, create configured Elasticsearch index if not present: `npm run init-es`,
122-
or re-create the index: `npm run init-es force`
123-
- Create tables `npm run create-tables`
124-
- Clear and init db `npm run init-db`
125-
- Seed tables: `npm run seed-tables`
126-
- Start app `npm start`
127-
- App is running at `http://localhost:3000`
149+
This command will do 3 things:
150+
- create Elasticsearch indexes (drop if exists)
151+
- Initialize the database by cleaning all the records.
152+
- Import the data to the local database and index it to ElasticSearch
153+
154+
7. 🚀 Start Topcoder Challenge API
155+
156+
```bash
157+
npm start
158+
```
159+
The Topcoder Challenge API will be served on `http://localhost:3000`
128160

129161
## Production deployment
130162

config/default.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* The configuration file.
33
*/
4-
4+
require('dotenv').config()
55
module.exports = {
66
READONLY: process.env.READONLY === 'true' || false,
77
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
"test": "mocha --require test/prepare.js -t 20000 test/unit/*.test.js --exit",
2020
"e2e": "mocha --require test/prepare.js -t 20000 test/e2e/*.test.js --exit",
2121
"test:cov": "nyc --reporter=html --reporter=text npm test",
22-
"e2e:cov": "nyc --reporter=html --reporter=text npm run e2e"
22+
"e2e:cov": "nyc --reporter=html --reporter=text npm run e2e",
23+
"services:up": "docker-compose -f ./local/docker-compose.yml up -d",
24+
"services:down": "docker-compose -f ./local/docker-compose.yml down",
25+
"services:logs": "docker-compose -f ./local/docker-compose.yml logs",
26+
"local:init": "npm run local:reset && npm run seed-tables && npm run sync-es",
27+
"local:reset": "npm run init-es force && npm run init-db force"
2328
},
2429
"author": "TCSCODER",
2530
"license": "none",
@@ -39,6 +44,7 @@
3944
"body-parser": "^1.15.1",
4045
"config": "^3.0.1",
4146
"cors": "^2.7.1",
47+
"dotenv": "^8.2.0",
4248
"dynamoose": "^1.8.0",
4349
"elasticsearch": "^16.1.1",
4450
"express": "^4.15.4",

0 commit comments

Comments
 (0)