Skip to content

Commit 357145a

Browse files
author
vikasrohit
authored
Merge pull request #5 from topcoder-platform/develop
Prod Release - First production release
2 parents 4ed352e + 3b2114a commit 357145a

25 files changed

+7956
-103
lines changed

.circleci/config.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
version: 2
2+
defaults: &defaults
3+
docker:
4+
- image: circleci/python:2.7.18-stretch-browsers
5+
install_dependency: &install_dependency
6+
name: Installation of build and deployment dependencies.
7+
command: |
8+
sudo apt install jq
9+
sudo pip install awscli --upgrade
10+
sudo pip install docker-compose
11+
install_deploysuite: &install_deploysuite
12+
name: Installation of install_deploysuite.
13+
command: |
14+
git clone --branch v1.4.2 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
15+
cp ./../buildscript/master_deploy.sh .
16+
cp ./../buildscript/buildenv.sh .
17+
cp ./../buildscript/awsconfiguration.sh .
18+
restore_cache_settings_for_build: &restore_cache_settings_for_build
19+
key: docker-node-modules-{{ checksum "package-lock.json" }}
20+
21+
save_cache_settings: &save_cache_settings
22+
key: docker-node-modules-{{ checksum "package-lock.json" }}
23+
paths:
24+
- node_modules
25+
26+
27+
builddeploy_steps: &builddeploy_steps
28+
- checkout
29+
- setup_remote_docker
30+
- run: *install_dependency
31+
- run: *install_deploysuite
32+
- restore_cache: *restore_cache_settings_for_build
33+
- run: ./build.sh ${APPNAME}
34+
- save_cache: *save_cache_settings
35+
- deploy:
36+
name: Running MasterScript.
37+
command: |
38+
./awsconfiguration.sh $DEPLOY_ENV
39+
source awsenvconf
40+
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-deployvar
41+
source buildenvvar
42+
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${LOGICAL_ENV}-global-appvar,${LOGICAL_ENV}-${APPNAME}-appvar -i ${APPNAME}
43+
44+
45+
jobs:
46+
# Build & Deploy against development backend
47+
"build-dev":
48+
<<: *defaults
49+
environment:
50+
DEPLOY_ENV: "DEV"
51+
LOGICAL_ENV: "dev"
52+
APPNAME: "onboarding-processor"
53+
steps: *builddeploy_steps
54+
55+
"build-prod":
56+
<<: *defaults
57+
environment:
58+
DEPLOY_ENV: "PROD"
59+
LOGICAL_ENV: "prod"
60+
APPNAME: "onboarding-processor"
61+
steps: *builddeploy_steps
62+
63+
workflows:
64+
version: 2
65+
build:
66+
jobs:
67+
# Development builds are executed on "develop" branch only.
68+
- "build-dev":
69+
context : org-global
70+
filters:
71+
branches:
72+
only:
73+
- develop
74+
75+
# Production builds are exectuted only on tagged commits to the
76+
# master branch.
77+
- "build-prod":
78+
context : org-global
79+
filters:
80+
branches:
81+
only: master

.gitignore

Lines changed: 5 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,8 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
lerna-debug.log*
8-
9-
# Diagnostic reports (https://nodejs.org/api/report.html)
10-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11-
12-
# Runtime data
13-
pids
14-
*.pid
15-
*.seed
16-
*.pid.lock
17-
18-
# Directory for instrumented libs generated by jscoverage/JSCover
19-
lib-cov
20-
21-
# Coverage directory used by tools like istanbul
22-
coverage
23-
*.lcov
24-
25-
# nyc test coverage
1+
node_modules
262
.nyc_output
3+
coverage
274

28-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29-
.grunt
30-
31-
# Bower dependency directory (https://bower.io/)
32-
bower_components
33-
34-
# node-waf configuration
35-
.lock-wscript
36-
37-
# Compiled binary addons (https://nodejs.org/api/addons.html)
38-
build/Release
39-
40-
# Dependency directories
41-
node_modules/
42-
jspm_packages/
43-
44-
# TypeScript v1 declaration files
45-
typings/
46-
47-
# TypeScript cache
48-
*.tsbuildinfo
49-
50-
# Optional npm cache directory
51-
.npm
52-
53-
# Optional eslint cache
54-
.eslintcache
55-
56-
# Microbundle cache
57-
.rpt2_cache/
58-
.rts2_cache_cjs/
59-
.rts2_cache_es/
60-
.rts2_cache_umd/
61-
62-
# Optional REPL history
63-
.node_repl_history
64-
65-
# Output of 'npm pack'
66-
*.tgz
67-
68-
# Yarn Integrity file
69-
.yarn-integrity
70-
71-
# dotenv environment variables file
5+
.DS_Store
726
.env
73-
.env.test
74-
75-
# parcel-bundler cache (https://parceljs.org/)
76-
.cache
77-
78-
# Next.js build output
79-
.next
80-
81-
# Nuxt.js build / generate output
82-
.nuxt
83-
dist
84-
85-
# Gatsby files
86-
.cache/
87-
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88-
# https://nextjs.org/blog/next-9-1#public-directory-support
89-
# public
90-
91-
# vuepress build output
92-
.vuepress/dist
93-
94-
# Serverless directories
95-
.serverless/
96-
97-
# FuseBox cache
98-
.fusebox/
99-
100-
# DynamoDB Local files
101-
.dynamodb/
102-
103-
# TernJS port file
104-
.tern-port
7+
api.env
8+
.eslintrc.y*ml

README.md

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,117 @@
1-
# onboarding-processor
2-
Processor to act on various platform events to update the onboarding statuses of new users
1+
# Onboarding API Checklist
2+
3+
## Dependencies
4+
5+
- Nodejs(v14+)
6+
- Kafka
7+
8+
## Configuration
9+
10+
Configuration is at `config/default.js`.
11+
The following parameters can be set in config files or in env variables:
12+
13+
- `PORT`: port number the health check dropin listening on
14+
- `LOG_LEVEL`: the log level
15+
- `KAFKA_URL`: comma separated Kafka hosts
16+
- `KAFKA_CLIENT_CERT`: Kafka connection certificate, optional;
17+
if not provided, then SSL connection is not used, direct insecure connection is used;
18+
if provided, it can be either path to certificate file or certificate content
19+
- `KAFKA_CLIENT_CERT_KEY`: Kafka connection private key, optional;
20+
if not provided, then SSL connection is not used, direct insecure connection is used;
21+
if provided, it can be either path to private key file or private key content
22+
- `KAFKA_GROUP_ID`: the Kafka group id
23+
- `MEMBER_API_URL`: the member api url
24+
- `STANDARD_TERMS_ID`: The Topcoder standard terms id
25+
- `NDA_TERMS_ID`: The NDA terms id
26+
- `TERMS_USER_AGREEMENT_TOPIC`: The kafka topic on which the processor will listen to terms agreement events
27+
- `USER_TAXFORM_UPDATE_TOPIC`: The Kafka topic to which to listen to user tax form updated events
28+
- `auth0.AUTH0_URL`: Auth0 URL, used to get TC M2M token
29+
- `auth0.AUTH0_AUDIENCE`: Auth0 audience, used to get TC M2M token
30+
- `auth0.AUTH0_CLIENT_ID`: Auth0 client id, used to get TC M2M token
31+
- `auth0.AUTH0_CLIENT_SECRET`: Auth0 client secret, used to get TC M2M token
32+
- `auth0.AUTH0_PROXY_SERVER_URL`: Proxy Auth0 URL, used to get TC M2M token
33+
- `auth0.TOKEN_CACHE_TIME`: Auth0 token cache time, used to get TC M2M token
34+
35+
## Local Kafka setup
36+
37+
1. Navigate to the directory `local`
38+
39+
2. Run the following command
40+
41+
```bash
42+
docker-compose up -d
43+
```
44+
45+
## Local deployment
46+
47+
0. Make sure to use Node v14+ by command `node -v`. We recommend using [NVM](https://github.com/nvm-sh/nvm) to quickly switch to the right version:
48+
49+
```bash
50+
nvm use
51+
```
52+
53+
1. From the project root directory, run the following command to install the dependencies
54+
55+
```bash
56+
npm install
57+
```
58+
59+
2. To run linters if required
60+
61+
```bash
62+
npm run lint
63+
```
64+
65+
To fix possible lint errors:
66+
67+
```bash
68+
npm run lint:fix
69+
```
70+
71+
3. Local config
72+
73+
In the `onboarding-checklist-processor` root directory create `.env` file with the next environment variables. Values for **Auth0 config** should be shared with you on the forum.<br>
74+
75+
```bash
76+
# Auth0 config
77+
AUTH0_URL=
78+
AUTH0_AUDIENCE=
79+
AUTH0_CLIENT_ID=
80+
AUTH0_CLIENT_SECRET=
81+
AUTH0_PROXY_SERVER_URL=
82+
```
83+
84+
- Values from this file would be automatically used by many `npm` commands.
85+
- ⚠️ Never commit this file or its copy to the repository!
86+
87+
4. Start the processor and health check dropin
88+
89+
```bash
90+
npm start
91+
```
92+
93+
5. Run unit tests
94+
```bash
95+
npm run test
96+
npm run test:cov
97+
```
98+
99+
## Local Deployment with Docker
100+
101+
To run the processor using docker, follow the below steps
102+
103+
1. Navigate to the directory `docker`
104+
105+
2. Rename the file `sample.api.env` to `api.env`
106+
107+
3. Set the required configuration parameters in the file `api.env`.
108+
109+
Note that you can also add other variables to `api.env`, with `<key>=<value>` format per line.
110+
111+
4. Once that is done, run the following command
112+
113+
```bash
114+
docker-compose up
115+
```
116+
117+
5. When you are running the application for the first time, It will take some time initially to download the image and install the dependencies

Verification.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
The following verification steps expect that the member-api is properly working
2+
3+
# Start Kafka:
4+
- `cd local`
5+
- `docker-compose up`
6+
7+
# Start the processor:
8+
- `npm start`
9+
10+
# Start Kafka producer:
11+
12+
`docker exec -it onboarding-checklist-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic terms.notification.user.agreed`
13+
14+
# Post the following message in the producer console:
15+
- message for standard terms completion (userId = 251280 is the id of 'denis' member in tc dev environment )
16+
`{"topic":"terms.notification.user.agreed","originator":"onboarding-api","timestamp":"2021-09-14T00:00:00.000Z","mime-type":"application/json","payload":{"userId":251280,"termsOfUseId":"0dedac8f-5a1a-4fe7-001f-e1d04dc65b7d","legacyId":123456,"created":"2021-09-14T00:00:00.000Z"}}`
17+
18+
- message for nda terms completion
19+
`{"topic":"terms.notification.user.agreed","originator":"onboarding-api","timestamp":"2021-09-14T00:00:00.000Z","mime-type":"application/json","payload":{"userId":251280,"termsOfUseId":"0dedac8f-5a1a-4fe7-002f-e1d04dc65b7d","legacyId":123456,"created":"2021-09-14T00:00:00.000Z"}}`
20+
21+
- message for unsupported terms id
22+
`{"topic":"terms.notification.user.agreed","originator":"onboarding-api","timestamp":"2021-09-14T00:00:00.000Z","mime-type":"application/json","payload":{"userId":251280,"termsOfUseId":"0dedac8f-5a1a-4fe7-003f-e1d04dc65b7d","legacyId":123456,"created":"2021-09-14T00:00:00.000Z"}}`
23+
24+
- Invalid topic message:
25+
`{"topic":"terms.notification.user.invalid","originator":"onboarding-api","timestamp":"2021-09-14T00:00:00.000Z","mime-type":"application/json","payload":{"userId":251280,"termsOfUseId":"0dedac8f-5a1a-4fe7-001f-e1d04dc65b7d","legacyId":123456,"created":"2021-09-14T00:00:00.000Z"}}`
26+
27+
- Malformed JSON message:
28+
`{"topic":"terms.notification.user.invalid","originator":"onboarding-api","timestamp":"2021-09-14T00:00:00.000Z","mime-type":"application/json","payload":{"userId":251280,"termsOfUseId":"0dedac8f-5a1a-4fe7-001f-e1d04dc65b7d","legacyId":123456,"created":"2021-09-14T00:00:`
29+
30+
## Verify tax form processor service
31+
32+
`docker exec -it onboarding-checklist-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic terms.notification.user.taxform.updated`
33+
34+
- message for user tax form updated
35+
`{"topic":"terms.notification.user.taxform.updated","originator":"onboarding-api","timestamp":"2021-09-14T00:00:00.000Z","mime-type":"application/json","payload":{"userId":251280,"taxForm":"W-9(TopCoder)","Handle":"denis","created":"2021-09-14T00:00:00.000Z"}}`
36+
37+
38+
# Unit tests
39+
To run unit tests, execute the following command `npm run test`
40+
41+
# Unit tests with coverage
42+
To run unit tests with coverage run `npm run test:cov`

build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
APP_NAME=$1
4+
UPDATE_CACHE=""
5+
echo "" > docker/api.env
6+
docker-compose -f docker/docker-compose.yml build $APP_NAME
7+
docker create --name app $APP_NAME:latest
8+
9+
if [ -d node_modules ]
10+
then
11+
mv package-lock.json old-package-lock.json
12+
docker cp app:/$APP_NAME/package-lock.json package-lock.json
13+
set +eo pipefail
14+
UPDATE_CACHE=$(cmp package-lock.json old-package-lock.json)
15+
set -eo pipefail
16+
else
17+
UPDATE_CACHE=1
18+
fi
19+
20+
if [ "$UPDATE_CACHE" == 1 ]
21+
then
22+
docker cp app:/$APP_NAME/node_modules .
23+
fi

0 commit comments

Comments
 (0)