Skip to content

Commit bdae8ce

Browse files
Merge pull request #39 from topcoder-platform/develop
deploy to prod
2 parents 8478d46 + 81761e8 commit bdae8ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+7322
-1662
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-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 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: "challenge-api"
52+
steps: *builddeploy_steps
53+
54+
"build-prod":
55+
<<: *defaults
56+
environment:
57+
DEPLOY_ENV: "PROD"
58+
LOGICAL_ENV: "prod"
59+
APPNAME: "challenge-api"
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ It starts Elasticsearch, DynamoDB and S3 compatible server.
7878
## Mock api
7979
For postman verification, please use the mock api under mock-api folder. It provides mock endpoint to fetch challenge resources and groups.
8080
You need to ensure DynamoDB configuration in `mock-api/config/default.js` is consistent with `config/default.js`
81-
Go to `mock-api` folder and run command `npm run start` to start the mock-api listening on port 4000
81+
Go to `mock-api` folder and run commands `npm i` and `npm start` to start the mock-api listening on port 4000
8282

8383
## Create Tables
8484
1. Make sure DynamoDB are running as per instructions above.
@@ -108,7 +108,7 @@ Go to `mock-api` folder and run command `npm run start` to start the mock-api li
108108
- Clear and init db `npm run init-db`
109109
- Start app `npm start`
110110
- App is running at `http://localhost:3000`
111-
- Start mock-api, go to `mock-api` folder and `npm start`, mock api is running at `http://localhost:4000`
111+
- Start mock-api, go to `mock-api` folder, run `npm i` and `npm start`, mock api is running at `http://localhost:4000`
112112

113113
## Running tests
114114

Verification.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- You need to run command `npm run sync-es` before you run `Challenges/get challenge` and `Challenges/search challenge` test case.
88

99
## DynamoDB Verification
10-
Run command `npm run view-data <ModelName>` to view table data, ModelName can be `Challenge`, `ChallengeType`, `ChallengeSetting`, `AuditLog`, `Phase`, `TimelineTemplate`or `Attachment`
10+
Run command `npm run view-data <ModelName>` to view table data, ModelName can be `Challenge`, `ChallengeType`, `ChallengeSetting`, `AuditLog`, `Phase`, `TimelineTemplate`, `Attachment` or `ChallengeTypeTimelineTemplate`
1111

1212
## S3 Verification
1313

app-constants.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ const Topics = {
3737
ChallengePhaseDeleted: 'test.new.bus.events', // 'challenge.action.phase.deleted',
3838
TimelineTemplateCreated: 'test.new.bus.events', // 'challenge.action.timeline.template.created',
3939
TimelineTemplateUpdated: 'test.new.bus.events', // 'challenge.action.timeline.template.updated',
40-
TimelineTemplateDeleted: 'test.new.bus.events' // 'challenge.action.timeline.template.deleted'
40+
TimelineTemplateDeleted: 'test.new.bus.events', // 'challenge.action.timeline.template.deleted',
41+
ChallengeTypeTimelineTemplateCreated: 'test.new.bus.events', // 'challenge.action.type.timeline.template.created',
42+
ChallengeTypeTimelineTemplateUpdated: 'test.new.bus.events', // 'challenge.action.type.timeline.template.updated',
43+
ChallengeTypeTimelineTemplateDeleted: 'test.new.bus.events' // 'challenge.action.type.timeline.template.deleted'
4144
}
4245

4346
module.exports = {

app-routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ module.exports = (app) => {
9494
}
9595

9696
actions.push(method)
97-
app[verb](path, helper.autoWrapExpress(actions))
97+
app[verb](`/${config.API_VERSION}${path}`, helper.autoWrapExpress(actions))
9898
})
9999
})
100100

build.sh

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

config/default.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
module.exports = {
66
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
77
PORT: process.env.PORT || 3000,
8+
API_VERSION: process.env.API_VERSION || 'v5',
89
AUTH_SECRET: process.env.AUTH_SECRET || 'mysecret',
910
VALID_ISSUERS: process.env.VALID_ISSUERS || '["https://api.topcoder-dev.com", "https://api.topcoder.com", "https://topcoder-dev.auth0.com/"]',
1011

@@ -64,6 +65,13 @@ module.exports = {
6465
UPDATE: process.env.SCOPE_CHALLENGE_TYPES_UPDATE || 'update:challenge_types',
6566
ALL: process.env.SCOPE_CHALLENGE_TYPES_ALL || 'all:challenge_types'
6667
},
68+
CHALLENGE_TYPE_TIMELINE_TEMPLATES: {
69+
READ: process.env.SCOPE_CHALLENGE_TYPE_TIMELINE_TEMPLATES_READ || 'read:challenge_type_timeline_templates',
70+
CREATE: process.env.SCOPE_CHALLENGE_TYPE_TIMELINE_TEMPLATES_CREATE || 'create:challenge_type_timeline_templates',
71+
UPDATE: process.env.SCOPE_CHALLENGE_TYPE_TIMELINE_TEMPLATES_UPDATE || 'update:challenge_type_timeline_templates',
72+
DELETE: process.env.SCOPE_CHALLENGE_TYPE_TIMELINE_TEMPLATES_DELETE || 'delete:challenge_type_timeline_templates',
73+
ALL: process.env.SCOPE_CHALLENGE_TYPE_TIMELINE_TEMPLATES_ALL || 'all:challenge_type_timeline_templates'
74+
},
6775
CHALLENGE_SETTINGS: {
6876
READ: process.env.SCOPE_CHALLENGE_SETTINGS_READ || 'read:challenge_settings',
6977
CREATE: process.env.SCOPE_CHALLENGE_SETTINGS_CREATE || 'create:challenge_settings',

config/test.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Use the base image with Node.js
2+
FROM node:latest
3+
4+
# Copy the current directory into the Docker image
5+
COPY . /challenge-api
6+
7+
# Set working directory for future use
8+
WORKDIR /challenge-api
9+
10+
# Install the dependencies from package.json
11+
RUN npm install
12+
RUN npm run lint
13+
RUN npm run lint:fix
14+
#RUN npm run build
15+
#RUN npm run test
16+
17+
CMD npm start

docker/docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: '3'
2+
services:
3+
challenge-api:
4+
image: challenge-api:latest
5+
build:
6+
context: ../
7+
dockerfile: docker/Dockerfile

0 commit comments

Comments
 (0)