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

Commit a501d39

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 3c5d798 + c84a9fd commit a501d39

15 files changed

+755
-402
lines changed

.circleci/config.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
version: 2
2+
defaults: &defaults
3+
docker:
4+
- image: circleci/python:2.7-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+
11+
install_deploysuite: &install_deploysuite
12+
name: Installation of install_deploysuite.
13+
command: |
14+
git clone --branch v1.4.1 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-la-{{ checksum "package-lock.json" }}
20+
21+
save_cache_settings: &save_cache_settings
22+
key: docker-node-modules-la-{{ 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: ./builddocker.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 ${DEPLOY_ENV}-${APPNAME}-deployvar
40+
source buildenvvar
41+
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${DEPLOY_ENV}-global-appvar,${DEPLOY_ENV}-${APPNAME}-appvar -i ${APPNAME}
42+
jobs:
43+
# Build & Deploy against development backend
44+
"build-dev":
45+
<<: *defaults
46+
environment:
47+
DEPLOY_ENV: "dev"
48+
APPNAME: "topcoder-x-receiver"
49+
steps: *builddeploy_steps
50+
51+
# Build & Deploy against production backend
52+
"build-prod":
53+
<<: *defaults
54+
environment:
55+
DEPLOY_ENV: "prod"
56+
APPNAME: "topcoder-x-receiver"
57+
steps: *builddeploy_steps
58+
59+
workflows:
60+
version: 2
61+
build:
62+
jobs:
63+
# Development builds are executed on "develop" branch only.
64+
- "build-dev":
65+
context : org-global
66+
filters:
67+
branches:
68+
only:
69+
- develop
70+
- "build-prod":
71+
context : org-global
72+
filters:
73+
branches:
74+
only:
75+
- master

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ npm-debug.log
3131

3232
/config/local.js
3333
.DS_Store
34+
35+
package-lock.json

app.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,27 @@
99
*/
1010
'use strict';
1111
const express = require('express');
12-
const logger = require('morgan');
1312
const cookieParser = require('cookie-parser');
1413
const bodyParser = require('body-parser');
14+
const healthcheck = require('topcoder-healthcheck-dropin');
15+
const logger = require('./utils/logger');
16+
17+
/**
18+
* Method to check the service status
19+
* @returns {Object} The returned status
20+
*/
21+
function check() {
22+
// No checks to run. The output of this itself is an indication that the app is actively running
23+
return {
24+
checksRun: 1
25+
};
26+
}
1527

1628
const webhooks = require('./routes/webhooks');
1729

1830
const app = express();
1931

20-
app.use(logger('dev'));
32+
// app.use(logger('dev'));
2133
app.use(bodyParser.json({
2234
verify: (req, res, buf) => {
2335
req.rawBody = buf.toString();
@@ -26,6 +38,8 @@ app.use(bodyParser.json({
2638
app.use(bodyParser.urlencoded({extended: false}));
2739
app.use(cookieParser());
2840

41+
app.use(healthcheck.middleware([check]));
42+
2943
app.use('/webhooks', webhooks);
3044

3145
// catch 404 and forward to error handler
@@ -35,7 +49,7 @@ app.use((req, res, next) => {
3549
next(err);
3650
});
3751

38-
// error handler
52+
// // error handler
3953
app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
4054
console.log(err);
4155
res.status(err.status || 500); // eslint-disable-line no-magic-numbers
@@ -45,4 +59,17 @@ app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
4559
});
4660
});
4761

62+
process.on('uncaughtException', (err) => {
63+
// Check if error related to Dynamodb conn
64+
if (err.code === 'NetworkingError' && err.region) {
65+
logger.error('DynamoDB connection failed.');
66+
}
67+
logger.logFullError(err, 'system');
68+
});
69+
70+
// handle and log unhanled rejection
71+
process.on('unhandledRejection', (err) => {
72+
logger.logFullError(err, 'system');
73+
});
74+
4875
module.exports = app;

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ AWS_REPOSITORY=$(eval "echo \$${ENV}_AWS_REPOSITORY")
2525
#App variables
2626
KAFKA_CLIENT_CERT=$(eval "echo \$${ENV}_KAFKA_CLIENT_CERT")
2727
KAFKA_CLIENT_CERT_KEY=$(eval "echo \$${ENV}_KAFKA_CLIENT_CERT_KEY")
28-
KAFKA_HOST=$(eval "echo \$${ENV}_KAFKA_URL")
28+
KAFKA_URL=$(eval "echo \$${ENV}_KAFKA_URL")
2929
ZOO_KEEPER=$(eval "echo \$${ENV}_ZOO_KEEPER")
3030
TOPIC=$(eval "echo \$${ENV}_TOPIC")
3131
MONGODB_URI=$(eval "echo \$${ENV}_MONGODB_URI")

builddocker.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 build -t $APP_NAME:latest .
8+
docker create --name app $APP_NAME:latest
9+
10+
if [ -d node_modules ]
11+
then
12+
mv package-lock.json old-package-lock.json
13+
docker cp app:/usr/src/app/package-lock.json package-lock.json
14+
set +eo pipefail
15+
UPDATE_CACHE=$(cmp package-lock.json old-package-lock.json)
16+
set -eo pipefail
17+
else
18+
UPDATE_CACHE=1
19+
fi
20+
21+
if [ "$UPDATE_CACHE" == 1 ]
22+
then
23+
docker cp app:/usr/src/app/node_modules .
24+
fi

config/default.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@ const fs = require('fs');
1414
*/
1515

1616
module.exports = {
17-
PORT: process.env.PORT || 3002, // eslint-disable-line no-magic-numbers
17+
PORT: process.env.PORT || 3000, // eslint-disable-line no-magic-numbers
1818
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
1919
TOPIC: process.env.TOPIC || 'tc-x-events',
2020
KAFKA_OPTIONS: {
21-
connectionString: process.env.KAFKA_HOST || 'localhost:9092',
21+
connectionString: process.env.KAFKA_URL || 'localhost:9092',
2222
ssl: {
2323
cert: process.env.KAFKA_CLIENT_CERT || fs.readFileSync('./kafka_client.cer'), // eslint-disable-line no-sync
2424
key: process.env.KAFKA_CLIENT_CERT_KEY || fs.readFileSync('./kafka_client.key') // eslint-disable-line no-sync
2525
}
2626
},
27-
MONGODB_URL: process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/topcoderx'
27+
DYNAMODB: {
28+
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID || '',
29+
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY || '',
30+
AWS_REGION: process.env.AWS_REGION || '',
31+
IS_LOCAL: process.env.IS_LOCAL || 'false'
32+
}
2833
};

configuration.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@ The following config parameters are supported, they are defined in `config/defau
66
| :------------------------------------- | :----------------------------------------: | :------------------------------: |
77
| PORT | The port the application will listen on | 3002 |
88
| LOG_LEVEL | The log level | info |
9-
| MONGODB_URI | The MongoDB URI. This needs to be the same MongoDB used by topcoder-x-receiver, topcoder-x-processor, and topcoder-x-site | mongodb://127.0.0.1:27017/topcoderx |
109
|TOPIC | The Kafka topic where events are published. This must be the same as the configured value for topcoder-x-processor| |
1110
|KAFKA_OPTIONS | Kafka connection options| |
12-
|KAFKA_HOST | The Kafka host to connect to| localhost:9092 |
11+
|KAFKA_URL | The Kafka host to connect to| localhost:9092 |
1312
|KAFKA_CLIENT_CERT | The Kafka SSL certificate to use when connecting| Read from kafka_client.cer file, but this can be set as a string like it is on Heroku |
1413
|KAFKA_CLIENT_CERT_KEY | The Kafka SSL certificate key to use when connecting| Read from kafka_client.key file, but this can be set as a string like it is on Heroku|
14+
|AWS_ACCESS_KEY_ID | The Amazon certificate key to use when connecting. Use local dynamodb you can set fake value|FAKE_ACCESS_KEY_ID |
15+
|AWS_SECRET_ACCESS_KEY | The Amazon certificate access key to use when connecting. Use local dynamodb you can set fake value|FAKE_SECRET_ACCESS_KEY |
16+
|AWS_REGION | The Amazon certificate region to use when connecting. Use local dynamodb you can set fake value|FAKE_REGION |
17+
|IS_LOCAL | Use Amazon DynamoDB Local or server | 'false' |
1518

1619
KAFKA_OPTIONS should be object as described in https://github.com/oleksiyk/kafka#ssl
1720
For using with SSL, the options should be as
1821
```
1922
{
2023
connectionString: '<server>',
2124
ssl: {
22-
cert: '<certificate>',
25+
cert: '<certificate>',
2326
key: '<key>'
2427
}
2528
}
@@ -39,7 +42,7 @@ Configure a Github project with a webhook with a format like this: https://<rece
3942
#### Smoke test
4043
- Create an issue in the repo, you can see the logs in `receiver`, the `issue.created` event is generated.
4144

42-
You can test other events, but just validating that an issue.created event is generated in Kafka is enough to smoke test the receiver is set up properly.
45+
You can test other events, but just validating that an issue.created event is generated in Kafka is enough to smoke test the receiver is set up properly.
4346

4447
## Gitlab Verification
4548

models/Project.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,33 @@
88
* @author TCSCODER
99
* @version 1.0
1010
*/
11-
const mongoose = require('mongoose');
11+
const dynamoose = require('dynamoose');
1212

13-
const schema = new mongoose.Schema({
13+
const Schema = dynamoose.Schema;
14+
15+
const schema = new Schema({
16+
id: {
17+
type: String,
18+
hashKey: true,
19+
required: true
20+
},
1421
title: {type: String, required: true},
15-
tcDirectId: {type: Number, required: true},
22+
tcDirectId: {
23+
type: Number,
24+
required: true,
25+
index: {
26+
global: true,
27+
rangeKey: 'id',
28+
project: true,
29+
name: 'TcDirectIdIndex'
30+
}
31+
},
1632
repoUrl: {type: String, required: true},
1733
rocketChatWebhook: {type: String, required: false},
1834
rocketChatChannelName: {type: String, required: false},
1935
archived: {type: String, required: true},
20-
username: {type: String, required: true},
36+
owner: {type: String, required: true},
2137
secretWebhookKey: {type: String, required: true}
2238
});
2339

24-
schema.index({tcDirectId: 1});
25-
26-
2740
module.exports = schema;

models/index.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,23 @@
1111
'use strict';
1212

1313
const config = require('config');
14-
const mongoose = require('mongoose');
14+
const dynamoose = require('dynamoose');
15+
16+
dynamoose.AWS.config.update({
17+
accessKeyId: config.DYNAMODB.AWS_ACCESS_KEY_ID,
18+
secretAccessKey: config.DYNAMODB.AWS_SECRET_ACCESS_KEY,
19+
region: config.DYNAMODB.AWS_REGION
20+
});
21+
22+
if (config.DYNAMODB.IS_LOCAL === 'true') {
23+
dynamoose.local();
24+
}
25+
26+
dynamoose.setDefaults({
27+
create: false,
28+
update: false
29+
});
1530

16-
mongoose.Promise = global.Promise;
17-
const connection = mongoose.createConnection(config.MONGODB_URL);
1831
const IssueCreatedEvent = require('./IssueCreatedEvent');
1932
const IssueUpdatedEvent = require('./IssueUpdatedEvent');
2033
const IssueClosedEvent = require('./IssueClosedEvent');
@@ -37,6 +50,6 @@ module.exports = {
3750
PullRequestCreatedEvent,
3851
PullRequestClosedEvent,
3952
LabelUpdatedEvent,
40-
Project: connection.model('Project', Project),
53+
Project: dynamoose.model('Topcoder_X.Project', Project),
4154
IssueClosedEvent
4255
};

0 commit comments

Comments
 (0)