Skip to content

Commit 209b00d

Browse files
author
sachin-maheshwari
authored
Merge pull request #99 from topcoder-platform/dev
STS (MSv1.3) migration
2 parents 08dac4b + 97949f4 commit 209b00d

File tree

6 files changed

+105
-77
lines changed

6 files changed

+105
-77
lines changed

.circleci/config.yml

+73-62
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,100 @@
1-
version: 2
21

3-
jobs:
4-
# Build & Deploy against development backend rer
5-
"build-dev":
2+
version: 2
3+
defaults: &defaults
64
docker:
75
- image: docker:17.06.1-ce-git
8-
steps:
9-
# Initialization.
10-
- checkout
11-
- setup_remote_docker
12-
- run:
13-
name: Installation of build dependencies.
14-
command: apk add --no-cache bash
6+
install_dependency: &install_dependency
7+
name: Installation of build and deployment dependencies.
8+
command: |
9+
apk update
10+
apk add --no-cache bash curl
11+
apk upgrade
12+
apk add --no-cache jq py-pip sudo
13+
sudo pip install awscli --upgrade
14+
install_deploysuite: &install_deploysuite
15+
name: Installation of install_deploysuite.
16+
#Git Clone -change back to v1.3 or latest once counter var is generalized.
17+
command: |
18+
git clone --branch master https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
19+
cp ./../buildscript/master_deploy.sh .
20+
cp ./../buildscript/buildenv.sh .
21+
cp ./../buildscript/awsconfiguration.sh .
22+
23+
restore_cache_settings_for_build: &restore_cache_settings_for_build
24+
key: docker-tc-notify-{{ checksum "package-lock.json" }}
1525

16-
# Restoration of node_modules from cache.
17-
- restore_cache:
18-
key: docker-tc-notify-{{ checksum "package-lock.json" }}
26+
save_cache_settings: &save_cache_settings
27+
key: docker-tc-notify-{{ checksum "package-lock.json" }}
28+
paths:
29+
- node_modules
1930

20-
# Build of Docker image.
21-
- run:
31+
run_build: &run_build
2232
name: Build of Docker image
23-
command: ./build.sh DEV
33+
command: ./build.sh
2434

25-
# Caching node modules.
26-
- save_cache:
27-
key: docker-tc-notify-{{ checksum "package-lock.json" }}
28-
paths:
29-
- node_modules
30-
31-
# Deployment.
32-
- run:
33-
name: Installing AWS client
34-
command: |
35-
apk add --no-cache jq py-pip sudo
36-
sudo pip install awscli --upgrade
3735

36+
jobs:
37+
# Build & Deploy against development backend rer
38+
"build-dev":
39+
<<: *defaults
40+
steps:
41+
- checkout
42+
- setup_remote_docker
43+
- run: *install_dependency
44+
- run: *install_deploysuite
45+
- restore_cache: *restore_cache_settings_for_build
46+
- run: *run_build
47+
- save_cache: *save_cache_settings
3848
- deploy:
39-
command: ./deploy.sh DEV $CIRCLE_SHA1
49+
name: Running Masterscript - deploy tc-notifications-api service
50+
command: |
51+
./awsconfiguration.sh DEV
52+
source awsenvconf
53+
./buildenv.sh -e DEV -b dev-tc-notifications-deployvar
54+
source buildenvvar
55+
./master_deploy.sh -d ECS -e DEV -t latest -s dev-global-appvar,dev-tc-notifications-appvar -i tc-notifications
56+
echo "Running Masterscript - deploy tc-notifications-consumers service"
57+
if [ -e dev-tc-notifications-deployvar.json ]; then sudo rm -vf dev-tc-notifications-deployvar.json; fi
58+
./buildenv.sh -e DEV -b dev-tc-notifications-consumers-deployvar
59+
source buildenvvar
60+
./master_deploy.sh -d ECS -e DEV -t latest -s dev-global-appvar,dev-tc-notifications-appvar -i tc-notifications
4061
4162
"build-prod":
42-
docker:
43-
- image: docker:17.06.1-ce-git
63+
<<: *defaults
4464
steps:
45-
# Initialization.
4665
- checkout
4766
- setup_remote_docker
48-
- run:
49-
name: Installation of build dependencies.
50-
command: apk add --no-cache bash
51-
52-
# Restoration of node_modules from cache.
53-
- restore_cache:
54-
key: docker-tc-notify-{{ checksum "package-lock.json" }}
55-
56-
# Build of Docker image.
57-
- run:
58-
name: Build of Docker image
59-
command: ./build.sh PROD
60-
61-
# Caching node modules.
62-
- save_cache:
63-
key: docker-tc-notify-{{ checksum "package-lock.json" }}
64-
paths:
65-
- node_modules
66-
67-
# Deployment.
68-
- run:
69-
name: Installing AWS client
70-
command: |
71-
apk add --no-cache jq py-pip sudo
72-
sudo pip install awscli --upgrade
73-
67+
- run: *install_dependency
68+
- run: *install_deploysuite
69+
- restore_cache: *restore_cache_settings_for_build
70+
- run: *run_build
71+
- save_cache: *save_cache_settings
7472
- deploy:
75-
command: ./deploy.sh PROD $CIRCLE_SHA1
76-
73+
name: Running Masterscript - prod deploy tc-notifications-api service
74+
command: |
75+
./awsconfiguration.sh PROD
76+
source awsenvconf
77+
./buildenv.sh -e PROD -b prod-tc-notifications-deployvar
78+
source buildenvvar
79+
./master_deploy.sh -d ECS -e PROD -t latest -s prod-global-appvar,prod-tc-notifications-appvar -i tc-notifications
80+
echo "========== Running Masterscript - prod deploy tc-notifications-consumers service ========="
81+
if [ -e prod-tc-notifications-deployvar.json ]; then sudo rm -vf prod-tc-notifications-deployvar.json; fi
82+
./buildenv.sh -e PROD -b prod-tc-notifications-consumers-deployvar
83+
source buildenvvar
84+
./master_deploy.sh -d ECS -e PROD -t latest -s prod-global-appvar,prod-tc-notifications-appvar -i tc-notifications
85+
7786
workflows:
7887
version: 2
7988
build:
8089
jobs:
8190
# Development builds are executed on "develop" branch only.
8291
- "build-dev":
92+
context : org-global
8393
filters:
8494
branches:
85-
only: [dev]
95+
only: ['dev']
8696
- "build-prod":
97+
context : org-global
8798
filters:
8899
branches:
89100
only: master

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ COPY . .
1010
RUN npm install
1111
RUN npm install dotenv --save
1212
RUN npm test
13-
CMD ["npm", "start"]
13+
ENTRYPOINT ["npm","run"]
14+
#CMD ["npm", "start"]

build.sh

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ set -eo pipefail
55
# This script expects a single argument: NODE_ENV, which must be either
66
# "development" or "production".
77

8-
NODE_ENV=$1
8+
# NODE_ENV=$1
99

10-
ENV=$1
11-
AWS_REGION=$(eval "echo \$${ENV}_AWS_REGION")
12-
AWS_ACCESS_KEY_ID=$(eval "echo \$${ENV}_AWS_ACCESS_KEY_ID")
13-
AWS_SECRET_ACCESS_KEY=$(eval "echo \$${ENV}_AWS_SECRET_ACCESS_KEY")
14-
AWS_ACCOUNT_ID=$(eval "echo \$${ENV}_AWS_ACCOUNT_ID")
15-
AWS_REPOSITORY=$(eval "echo \$${ENV}_AWS_REPOSITORY")
16-
17-
TAG=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/tc-notifications:$CIRCLE_SHA1
10+
#ENV=$1
11+
#AWS_REGION=$(eval "echo \$${ENV}_AWS_REGION")
12+
#AWS_ACCESS_KEY_ID=$(eval "echo \$${ENV}_AWS_ACCESS_KEY_ID")
13+
#AWS_SECRET_ACCESS_KEY=$(eval "echo \$${ENV}_AWS_SECRET_ACCESS_KEY")
14+
#AWS_ACCOUNT_ID=$(eval "echo \$${ENV}_AWS_ACCOUNT_ID")
15+
#AWS_REPOSITORY=$(eval "echo \$${ENV}_AWS_REPOSITORY")
1816

17+
#TAG=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/tc-notifications:$CIRCLE_SHA1
18+
TAG="tc-notifications:latest"
1919
docker build -t $TAG .
2020

2121
# Copies "node_modules" from the created image, if necessary for caching.

config/default.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ module.exports = {
1717
},
1818
},
1919

20-
AUTH_SECRET: process.env.authSecret,
21-
VALID_ISSUERS: process.env.validIssuers ? process.env.validIssuers.replace(/\\"/g, '') : null,
20+
AUTH_SECRET: process.env.AUTH_SECRET,
21+
VALID_ISSUERS: process.env.VALID_ISSUERS ? process.env.VALID_ISSUERS.replace(/\\"/g, '') : null,
2222
// keep it here for dev purposes, it's only needed by modified version of tc-core-library-js
2323
// which skips token validation when locally deployed
2424

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
"sequelize": "^4.21.0",
5353
"superagent": "^3.8.0",
5454
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.6",
55-
"winston": "^2.2.0"
55+
"winston": "^2.2.0",
56+
"topcoder-healthcheck-dropin": "^1.0.3"
5657
},
5758
"engines": {
5859
"node": "6.x"

src/app.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const logger = require('./common/logger');
1515
const errors = require('./common/errors');
1616
const models = require('./models');
1717
const Kafka = require('no-kafka');
18+
const healthcheck = require('topcoder-healthcheck-dropin')
1819

1920
/**
2021
* Start Kafka consumer for event bus events.
@@ -74,11 +75,25 @@ function startKafkaConsumer(handlers, notificationServiceHandlers) {
7475
});
7576
});
7677

78+
const check = function () {
79+
if (!consumer.client.initialBrokers && !consumer.client.initialBrokers.length) {
80+
return false
81+
}
82+
let connected = true
83+
consumer.client.initialBrokers.forEach(conn => {
84+
logger.debug(`url ${conn.server()} - connected=${conn.connected}`)
85+
connected = conn.connected & connected
86+
})
87+
return connected
88+
}
7789

7890
consumer
7991
.init()
80-
.then(() => _.each(_.keys(handlers),
81-
(topicName) => consumer.subscribe(topicName, dataHandler)))
92+
.then(() => {
93+
_.each(_.keys(handlers),
94+
(topicName) => consumer.subscribe(topicName, dataHandler))
95+
healthcheck.init([check])
96+
})
8297
.catch((err) => {
8398
logger.error('Kafka Consumer failed');
8499
logger.error(err);

0 commit comments

Comments
 (0)