Skip to content

Commit 8d23ccd

Browse files
authored
Issue #SB-30224 merge: Merge pull request #284 from project-sunbird/release-4.8.5
Issue #SB-30224 merge: merge release-4.8.5 to master
2 parents f24dd6a + 32a7ac9 commit 8d23ccd

32 files changed

Lines changed: 6448 additions & 5054 deletions

.circleci/config.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,34 @@ version: 2.1
22
jobs:
33
build:
44
docker:
5-
- image: node:6-alpine
5+
- image: circleci/node:12.13.0
6+
parallelism: 2
7+
working_directory: ~/project/src
68
steps:
79
- checkout
8-
- run: apk add zip git
9-
- run: apk add python make g++
10+
- run: npm cache clean --force
1011
- run: git submodule update --init --recursive src/libs
1112
- run: mkdir -p opt/content && cp -r src/* opt/content/
1213
- restore_cache:
13-
key: dependency-cache-{{ checksum "package.json" }}
14+
key: dependency-cache-{{ checksum "src/package.json" }}
1415
- run: cd opt/content/ && npm install --unsafe-perm
1516
- save_cache:
16-
key: dependency-cache-{{ checksum "package.json" }}
17-
paths: ./node_modules
17+
key: dependency-cache-{{ checksum "src/package.json" }}
18+
paths: ./node_modules
1819
- run: cd opt && zip -r content.zip content
1920
- store_artifacts:
2021
path: opt/content.zip
21-
destination: content.zip
22+
destination: content.zip
23+
- run:
24+
name: Run test cases
25+
command: 'cd src && npm install --unsafe-perm && npm run coverage'
26+
- run:
27+
name: install sonar scanner
28+
command: sudo npm install -g sonarqube-scanner@2.8.0
29+
- run:
30+
name: Run SonarScan
31+
command: sonar-scanner
32+
2233
workflows:
2334
version: 2.1
2435
build_and_test:

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/src/node_modules/
22
/src/npm-debug.log
33
/src/coverage/
4-
/src/**/*.log
4+
/src/**/*.log
5+
src/.env
6+
/src/.nyc_output

Jenkinsfile

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,17 @@ node('build-slave') {
1515
else
1616
println(ANSI_BOLD + ANSI_GREEN + "Found environment variable named hub_org with value as: " + hub_org + ANSI_NORMAL)
1717
cleanWs()
18-
if (params.github_release_tag == "") {
19-
checkout scm
20-
commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
21-
branch_name = sh(script: 'git name-rev --name-only HEAD | rev | cut -d "/" -f1| rev', returnStdout: true).trim()
22-
build_tag = branch_name + "_" + commit_hash
23-
println(ANSI_BOLD + ANSI_YELLOW + "github_release_tag not specified, using the latest commit hash: " + commit_hash + ANSI_NORMAL)
24-
}
25-
else {
26-
def scmVars = checkout scm
27-
checkout scm: [$class: 'GitSCM', branches: [[name: "refs/tags/$params.github_release_tag"]], userRemoteConfigs: [[url: scmVars.GIT_URL]]]
28-
build_tag = params.github_release_tag
29-
println(ANSI_BOLD + ANSI_YELLOW + "github_release_tag specified, building from github_release_tag: " + params.github_release_tag + ANSI_NORMAL)
30-
}
18+
checkout scm
19+
commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
20+
build_tag = sh(script: "echo " + params.github_release_tag.split('/')[-1] + "_" + commit_hash + "_" + env.BUILD_NUMBER, returnStdout: true).trim()
3121
echo "build_tag: " + build_tag
3222
}
3323

3424
stage('Build') {
3525
env.NODE_ENV = "build"
3626
print "Environment will be : ${env.NODE_ENV}"
3727
sh('git submodule update --init')
38-
sh('git submodule update --init --recursive --remote')
28+
// sh('git submodule update --init --recursive --remote')
3929
sh('chmod 777 build.sh')
4030
sh("./build.sh ${build_tag} ${env.NODE_NAME} ${hub_org}")
4131
}

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ The code in this repository is licensed under MIT unless otherwise noted. Please
3636
* sunbird_telemetry_sync_batch_size e.g: 20
3737
* sunbird_learner_service_local_base_url e.g: 'http://learner-service:9000'
3838
* sunbird_content_service_local_base_url e.g: 'http://localhost:5000'
39+
* sunbird_content_upload_data_limit: Content upload data limit e.g.: 50mb (string)
3940

4041
## Setup Instructions
4142
* Clone the project.eg .(git clone --recursive url)
42-
* Run "git submodule foreach git pull origin master" to pull the latest sunbird-js-utils sub module
43+
* Run "git submodule init"
44+
* Run "git submodule update"
45+
* Run "git submodule update --init --recursive" to pull the latest sunbird-js-utils sub module (if you want to pull from specific branch, "git submodule foreach git pull origin 'branch_name'" )
4346
* Change to src folder
4447
* Run `npm install`
4548
* Run `node app.js`

auto_build_deploy

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@Library('deploy-conf') _
2+
node('build-slave') {
3+
try {
4+
String ANSI_GREEN = "\u001B[32m"
5+
String ANSI_NORMAL = "\u001B[0m"
6+
String ANSI_BOLD = "\u001B[1m"
7+
String ANSI_RED = "\u001B[31m"
8+
String ANSI_YELLOW = "\u001B[33m"
9+
10+
ansiColor('xterm') {
11+
stage('Checkout') {
12+
tag_name = env.JOB_NAME.split("/")[-1]
13+
pre_checks()
14+
if (!env.hub_org) {
15+
println(ANSI_BOLD + ANSI_RED + "Uh Oh! Please set a Jenkins environment variable named hub_org with value as registery/sunbidrded" + ANSI_NORMAL)
16+
error 'Please resolve the errors and rerun..'
17+
}
18+
else
19+
println(ANSI_BOLD + ANSI_GREEN + "Found environment variable named hub_org with value as: " + hub_org + ANSI_NORMAL)
20+
cleanWs()
21+
def scmVars = checkout scm
22+
checkout scm: [$class: 'GitSCM', branches: [[name: "refs/tags/$tag_name"]], userRemoteConfigs: [[url: scmVars.GIT_URL]]]
23+
build_tag = tag_name + "_" + env.BUILD_NUMBER
24+
commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
25+
artifact_version = tag_name + "_" + commit_hash
26+
echo "build_tag: " + build_tag
27+
28+
}
29+
30+
// stage Build
31+
env.NODE_ENV = "build"
32+
print "Environment will be : ${env.NODE_ENV}"
33+
sh('git submodule update --init')
34+
// sh('git submodule update --init --recursive --remote')
35+
sh('chmod 777 build.sh')
36+
sh("./build.sh ${build_tag} ${env.NODE_NAME} ${hub_org}")
37+
38+
// stage ArchiveArtifacts
39+
archiveArtifacts "metadata.json"
40+
currentBuild.description = "${build_tag}"
41+
42+
}
43+
currentBuild.result = "SUCCESS"
44+
slack_notify(currentBuild.result, tag_name)
45+
email_notify()
46+
auto_build_deploy()
47+
48+
}
49+
catch (err) {
50+
currentBuild.result = "FAILURE"
51+
slack_notify(currentBuild.result, tag_name)
52+
email_notify()
53+
throw err
54+
}
55+
56+
}

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Build script
33
set -eo pipefail
44
build_tag=$1
5-
name=content-service
5+
name=knowledge-mw-service
66
node=$2
77
org=$3
88

setup.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
##Setup Instructions
2727
* Clone the project.
28-
* Run "git submodule foreach git pull origin master" to pull the latest sunbird-js-utils sub module
28+
* RUN "git submodule init" followed by "git submodule update" to load submodules to the latest version.
29+
* Run "git submodule foreach git pull origin master" to pull the latest sunbird-js-utils sub module. Rename `master` to specific remote branch name if you want to load from specific branch.
2930
* Change to src folder
3031
* Run `npm install`
3132
* Run `node app.js`

sonar-project.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sonar.projectName=sunbird-content-service
2+
sonar.language=js
3+
sonar.projectKey=project-sunbird_sunbird-content-service
4+
sonar.host.url=https://sonarcloud.io
5+
sonar.exclusions=src/test/**, **/node_modules/**
6+
sonar.javascript.lcov.reportPaths=src/coverage/lcov.info
7+
sonar.organization=project-sunbird
8+
sonar.projectVersion=1.0

src/app.js

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var fs = require('fs')
1010
var configUtil = require('sb-config-util')
1111
var _ = require('lodash')
1212
var logger = require('sb_logger_util_v2')
13+
var ApiInterceptor = require('sb_api_interceptor')
1314

1415
const contentProvider = require('sb_content_provider_util')
1516
var contentMetaProvider = require('./contentMetaFilter')
@@ -19,7 +20,7 @@ const contentProviderConfigPath = path.join(__dirname, '/config/contentProviderA
1920
var contentProviderApiConfig = JSON.parse(fs.readFileSync(contentProviderConfigPath))
2021
const telemtryEventConfig = JSON.parse(fs.readFileSync(path.join(__dirname, 'config/telemetryEventConfig.json')))
2122

22-
var reqDataLimitOfContentUpload = '50mb'
23+
var reqDataLimitOfContentUpload = process.env.sunbird_content_upload_data_limit || '50mb'
2324

2425
const port = process.env.sunbird_content_service_port ? process.env.sunbird_content_service_port : 5000
2526
const defaultChannel = process.env.sunbird_default_channel || 'sunbird'
@@ -29,6 +30,11 @@ globalEkstepProxyBaseUrl = process.env.sunbird_content_plugin_base_url ? process
2930
const contentRepoBaseUrl = process.env.sunbird_content_repo_api_base_url || 'https://qa.ekstep.in/api'
3031
const contentRepoApiKey = process.env.sunbird_content_repo_api_key
3132

33+
const contentServiceBaseUrl = process.env.sunbird_contnet_service_base_url || 'http://content-service:9000'
34+
const contentServiceAuthToken = process.env.sunbird_content_service_auth_token
35+
36+
const assessmentServiceBaseUrl = process.env.sunbird_assessment_service_base_url || 'http://assessment-service:9000'
37+
3238
const learnerServiceLocalBaseUrl = process.env.sunbird_learner_service_local_base_url
3339
? process.env.sunbird_learner_service_local_base_url
3440
: 'http://learner-service:9000'
@@ -50,10 +56,14 @@ const producerId = process.env.sunbird_environment + '.' + process.env.sunbird_i
5056
const sunbirdPortalBaseUrl = process.env.sunbird_portal_base_url || 'https://staging.open-sunbird.org'
5157
const lockExpiryTime = process.env.sunbird_lock_expiry_time || 3600
5258
const isHealthCheckEnabled = process.env.sunbird_health_check_enable || 'true'
53-
const contentServiceLocalBaseUrl = process.env.sunbird_content_service_local_base_url ? process.env.sunbird_content_service_local_base_url : 'http://content-service:5000'
59+
const contentServiceLocalBaseUrl = process.env.sunbird_content_service_local_base_url ? process.env.sunbird_content_service_local_base_url : 'http://knowledge-mw-service:5000'
5460
const sunbirdGzipEnable = process.env.sunbird_gzip_enable || 'true'
61+
const kidTokenPublicKeyBasePath = process.env.sunbird_kid_public_key_base_path || '/keys/'
5562

5663
configUtil.setContentProviderApi(contentProviderApiConfig.API)
64+
configUtil.setConfig('CONTENT_SERVICE_BASE_URL', contentServiceBaseUrl)
65+
configUtil.setConfig('CONTENT_SERVICE_AUTH_TOKEN', contentServiceAuthToken)
66+
configUtil.setConfig('ASSESSMENT_SERVICE_BASE_URL', assessmentServiceBaseUrl)
5767
configUtil.setConfig('CONTENT_REPO_BASE_URL', contentRepoBaseUrl)
5868
configUtil.setConfig('TELEMETRY_BASE_URL', telemetryBaseUrl)
5969
configUtil.setConfig('CONTENT_REPO_AUTHORIZATION_TOKEN', 'Bearer ' + contentRepoApiKey)
@@ -148,7 +158,7 @@ app.use(function (req, res, next) {
148158
res.sendStatus(200)
149159
} else {
150160
next()
151-
};
161+
}
152162
})
153163

154164
require('./routes/healthCheckRoutes')(app)
@@ -167,10 +177,34 @@ require('./routes/externalUrlMetaRoute')(app)
167177
require('./routes/pluginsRoutes')(app)
168178
require('./routes/collaborationRoutes')(app)
169179
require('./routes/lockRoutes')(app)
180+
require('./routes/questionRoutes')(app)
170181
// this middleware route add after all the routes
171182
require('./middlewares/proxy.middleware')(app)
172183

173-
function startServer () {
184+
async function startServer (cb) {
185+
var keyCloakConfig = {
186+
'authServerUrl': process.env.sunbird_keycloak_auth_server_url ? process.env.sunbird_keycloak_auth_server_url : 'https://staging.open-sunbird.org/auth',
187+
'realm': process.env.sunbird_keycloak_realm ? process.env.sunbird_keycloak_realm : 'sunbird',
188+
'clientId': process.env.sunbird_keycloak_client_id ? process.env.sunbird_keycloak_client_id : 'portal',
189+
'public': process.env.sunbird_keycloak_public ? process.env.sunbird_keycloak_public : true,
190+
'realmPublicKey': process.env.sunbird_keycloak_public_key
191+
}
192+
logger.info({ msg: 'keyCloakConfig', keyCloakConfig })
193+
194+
var cacheConfig = {
195+
store: process.env.sunbird_cache_store ? process.env.sunbird_cache_store : 'memory',
196+
ttl: process.env.sunbird_cache_ttl ? process.env.sunbird_cache_ttl : 1800
197+
}
198+
199+
var apiInterceptor = new ApiInterceptor(keyCloakConfig, cacheConfig)
200+
201+
await apiInterceptor.loadTokenPublicKeys(path.join(__dirname, kidTokenPublicKeyBasePath))
202+
203+
if (this.server) {
204+
cb && cb()
205+
return
206+
}
207+
174208
this.server = http.createServer(app).listen(port, function () {
175209
logger.info({ msg: `server running at PORT ${port}` })
176210
logger.debug({ msg: `server started at ${new Date()}` })
@@ -186,8 +220,9 @@ function startServer () {
186220
logger.fatal({ msg: 'error in getting meta filters', err })
187221
process.exit(1)
188222
})
223+
cb && cb()
189224
})
190-
this.server.keepAliveTimeout = 60000 * 5;
225+
this.server.keepAliveTimeout = 30000 * 5
191226
}
192227

193228
// Create server
@@ -206,12 +241,6 @@ if (defaultChannel) {
206241
startServer()
207242
}
208243

209-
// Close server, when we start for test cases
210-
exports.close = function () {
211-
logger.debug({ msg: `server stopped at ${new Date()}` })
212-
this.server.close()
213-
}
214-
215244
// Telemetry initialization
216245
const telemetryBatchSize = parseInt(process.env.sunbird_telemetry_sync_batch_size, 10) || 20
217246
telemtryEventConfig.pdata.id = producerId
@@ -226,3 +255,15 @@ const telemetryConfig = {
226255

227256
logger.debug({ msg: 'Telemetry is initialized.' })
228257
telemetry.init(telemetryConfig)
258+
process.on('unhandledRejection', (reason, p) => {
259+
console.log('Kp-mw Unhandled Rejection', p, reason)
260+
logger.error({ msg: 'Kp-mw Unhandled Rejection', p, reason })
261+
})
262+
process.on('uncaughtException', (err) => {
263+
console.log('Kp-mw Uncaught Exception', err)
264+
logger.error({ msg: 'Kp-mw Uncaught Exception', err })
265+
process.exit(1)
266+
})
267+
268+
exports.start = startServer
269+
exports.close = (cb) => { this.server.close(cb) }

src/config/constants.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"orgCacheExpiryTime": 1800,
33
"orgfieldsAllowedToSend": ["email","orgName"],
4-
"orgCacheKeyNamePrefix" : "orgdata-"
4+
"orgCacheKeyNamePrefix" : "orgdata-",
5+
"readableLicenseFields": ["name", "url", "description"],
6+
"licenseCacheKeyNamePrefix": "license-",
7+
"licenseCacheExpiryTime": 1800
58
}

0 commit comments

Comments
 (0)