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

Commit 54f44a1

Browse files
author
Sachin Maheshwari
committed
CI/CD
1 parent e021187 commit 54f44a1

File tree

5 files changed

+167
-40
lines changed

5 files changed

+167
-40
lines changed

.circleci/config.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.3 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+
builddeploy_steps: &builddeploy_steps
27+
- checkout
28+
- setup_remote_docker
29+
- run: *install_dependency
30+
- run: *install_deploysuite
31+
- restore_cache: *restore_cache_settings_for_build
32+
- run: ./build.sh ${APPNAME}
33+
- save_cache: *save_cache_settings
34+
- deploy:
35+
name: Running MasterScript.
36+
command: |
37+
./awsconfiguration.sh $DEPLOY_ENV
38+
source awsenvconf
39+
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-deployvar
40+
source buildenvvar
41+
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${LOGICAL_ENV}-global-appvar,${LOGICAL_ENV}-${APPNAME}-appvar -i ${APPNAME}
42+
43+
44+
jobs:
45+
# Build & Deploy against development backend
46+
"build-dev":
47+
<<: *defaults
48+
environment:
49+
DEPLOY_ENV: "DEV"
50+
LOGICAL_ENV: "dev"
51+
APPNAME: "u-bahn-user-reconciliation-processor"
52+
steps: *builddeploy_steps
53+
54+
"build-prod":
55+
<<: *defaults
56+
environment:
57+
DEPLOY_ENV: "PROD"
58+
LOGICAL_ENV: "prod"
59+
APPNAME: "u-bahn-user-reconciliation-processor"
60+
steps: *builddeploy_steps
61+
62+
workflows:
63+
version: 2
64+
build:
65+
jobs:
66+
# Development builds are executed on "develop" branch only.
67+
- "build-dev":
68+
context : org-global
69+
filters:
70+
branches:
71+
only:
72+
- develop
73+
74+
# Production builds are exectuted only on tagged commits to the
75+
# master branch.
76+
- "build-prod":
77+
context : org-global
78+
filters:
79+
branches:
80+
only: master

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ The following parameters can be set in config files or in env variables:
2222
if provided, it can be either path to private key file or private key content
2323
- KAFKA_GROUP_ID: the Kafka group id, default value is 'user-reconciliation-processor'
2424
- USER_RECONCILATION_TOPIC: Kafka topic, default value is 'backgroundjob.reconcile.user'
25-
- UBAHN_API_URL: The ubahn api url, default value: 'https://api.topcoder-dev.com/v5'
26-
- MEMBERS_API_URL: The topcoder member api url, default value: 'https://api.topcoder-dev.com/v5/members'
25+
- V5_API_URL: The topcoder v5 api base url, default value: 'https://api.topcoder-dev.com/v5'
2726
- AUTH0_URL: The auth0 url, default value: 'https://topcoder-dev.auth0.com/oauth/token'
28-
- AUTH0_UBAHN_AUDIENCE: The auth0 audience for accessing ubahn api(s), default value: 'https://u-bahn.topcoder-dev.com'
29-
- AUTH0_TOPCODER_AUDIENCE: The auth0 audience for accessing ubahn api(s), default value: 'https://m2m.topcoder-dev.com/'
27+
- AUTH0_AUDIENCE: The auth0 audience for accessing ubahn api(s), default value: 'https://m2m.topcoder-dev.com/'
3028
- AUTH0_CLIENT_ID: The auth0 client id
3129
- AUTH0_CLIENT_SECRET: The auth0 client secret
3230
- AUTH0_PROXY_SERVER_URL: The auth0 proxy server url
33-
- SLEEP_TIME: The pause time between two create operations, default value: 1000 ms
31+
- PUBLISH_TOPIC: after processing publish to another kafka topic i.e. 'legacy.sync.user'
3432

3533
There is a `/health` endpoint that checks for the health of the app. This sets up an expressjs server and listens on the environment variable `PORT`. It's not part of the configuration file and needs to be passed as an environment variable
3634

config.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.3 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+
builddeploy_steps: &builddeploy_steps
27+
- checkout
28+
- setup_remote_docker
29+
- run: *install_dependency
30+
- run: *install_deploysuite
31+
- restore_cache: *restore_cache_settings_for_build
32+
- run: ./build.sh ${APPNAME}
33+
- save_cache: *save_cache_settings
34+
- deploy:
35+
name: Running MasterScript.
36+
command: |
37+
./awsconfiguration.sh $DEPLOY_ENV
38+
source awsenvconf
39+
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-deployvar
40+
source buildenvvar
41+
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${LOGICAL_ENV}-global-appvar,${LOGICAL_ENV}-${APPNAME}-appvar -i ${APPNAME}
42+
43+
44+
jobs:
45+
# Build & Deploy against development backend
46+
"build-dev":
47+
<<: *defaults
48+
environment:
49+
DEPLOY_ENV: "DEV"
50+
LOGICAL_ENV: "dev"
51+
APPNAME: "u-bahn-user-skills-processor"
52+
steps: *builddeploy_steps
53+
54+
"build-prod":
55+
<<: *defaults
56+
environment:
57+
DEPLOY_ENV: "PROD"
58+
LOGICAL_ENV: "prod"
59+
APPNAME: "u-bahn-user-skills-processor"
60+
steps: *builddeploy_steps
61+
62+
workflows:
63+
version: 2
64+
build:
65+
jobs:
66+
# Development builds are executed on "develop" branch only.
67+
- "build-dev":
68+
context : org-global
69+
filters:
70+
branches:
71+
only:
72+
- develop
73+
74+
# Production builds are exectuted only on tagged commits to the
75+
# master branch.
76+
- "build-prod":
77+
context : org-global
78+
filters:
79+
branches:
80+
only: master

config/default.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@ module.exports = {
1919

2020
V5_API_URL: process.env.V5_API_URL || 'https://api.topcoder-dev.com/v5',
2121

22-
UBAHN_API_URL: process.env.UBAHN_API_URL || 'https://api.topcoder-dev.com/v5',
23-
MEMBERS_API_URL: process.env.MEMBERS_API_URL || 'https://api.topcoder-dev.com/v5/members',
24-
2522
AUTH0_URL: process.env.AUTH0_URL || 'https://topcoder-dev.auth0.com/oauth/token', // Auth0 credentials
26-
AUTH0_UBAHN_AUDIENCE: process.env.AUTH0_UBAHN_AUDIENCE || 'https://u-bahn.topcoder.com',
27-
AUTH0_TOPCODER_AUDIENCE: process.env.AUTH0_TOPCODER_AUDIENCE || 'https://m2m.topcoder-dev.com/',
23+
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE || 'https://m2m.topcoder-dev.com/',
2824
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
2925
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
3026
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,
3127

32-
SLEEP_TIME: process.env.SLEEP_TIME ? parseInt(process.env.SLEEP_TIME, 10) : 1000
3328
}

src/common/helper.js

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,9 @@ const qs = require('querystring')
88
const m2mAuth = require('tc-core-library-js').auth.m2m
99
const logger = require('./logger')
1010

11-
const ubahnM2MConfig = _.pick(config, ['AUTH0_URL', 'AUTH0_UBAHN_AUDIENCE', 'AUTH0_PROXY_SERVER_URL'])
12-
const topcoderM2MConfig = _.pick(config, ['AUTH0_URL', 'AUTH0_TOPCODER_AUDIENCE', 'AUTH0_PROXY_SERVER_URL'])
11+
const topcoderM2MConfig = _.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'AUTH0_PROXY_SERVER_URL'])
1312

14-
const ubahnM2M = m2mAuth({ ...ubahnM2MConfig, AUTH0_AUDIENCE: ubahnM2MConfig.AUTH0_UBAHN_AUDIENCE })
15-
const topcoderM2M = m2mAuth({ ...topcoderM2MConfig, AUTH0_AUDIENCE: topcoderM2MConfig.AUTH0_TOPCODER_AUDIENCE })
16-
17-
/**
18-
* Use this function to halt execution
19-
* js version of sleep()
20-
* @param {Number} ms Timeout in ms
21-
*/
22-
async function sleep(ms) {
23-
if (!ms) {
24-
ms = config.SLEEP_TIME
25-
}
26-
27-
logger.debug(`Sleeping for ${ms} ms`)
28-
29-
return new Promise(resolve => setTimeout(resolve, ms))
30-
}
31-
32-
/* Function to get M2M token
33-
* (U-Bahn APIs only)
34-
* @returns {Promise}
35-
*/
36-
async function getUbahnM2Mtoken() {
37-
return ubahnM2M.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET)
38-
}
13+
const topcoderM2M = m2mAuth({ ...topcoderM2MConfig, AUTH0_AUDIENCE: topcoderM2MConfig.AUTH0_AUDIENCE })
3914

4015
/* Function to get M2M token
4116
* (Topcoder APIs only)
@@ -63,7 +38,7 @@ function getKafkaOptions() {
6338
* @param {String} handle The member handle
6439
*/
6540
async function getMember(handle, token) {
66-
const res = await axios.get(`${config.MEMBERS_API_URL}/${qs.escape(handle)}`, { headers: { Authorization: `Bearer ${token}` } })
41+
const res = await axios.get(`${config.V5_API_URL}/members${qs.escape(handle)}`, { headers: { Authorization: `Bearer ${token}` } })
6742
return _.get(res, 'data', {})
6843
}
6944

@@ -89,7 +64,6 @@ async function postEvent (topic, payload, token) {
8964
module.exports = {
9065
getKafkaOptions,
9166
getTopcoderM2Mtoken,
92-
getUbahnM2Mtoken,
9367
getMember,
9468
postEvent
9569
}

0 commit comments

Comments
 (0)