Skip to content

Commit 894d2a9

Browse files
committed
Dockerization updates
1 parent e408d62 commit 894d2a9

File tree

8 files changed

+129
-18
lines changed

8 files changed

+129
-18
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.git
3+
.gitignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55

66
*.cer
77
*.key
8+
.env

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Use the base image with Node.js 8.12
2+
FROM node:8.12
3+
4+
# Set working directory for future use
5+
WORKDIR /topcoder-x-processor
6+
7+
COPY package.json .
8+
COPY package-lock.json .
9+
10+
# Install the dependencies from package.json
11+
RUN npm install
12+
13+
COPY . .
14+
15+
ENTRYPOINT npm start

build.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
# This script expects 2 arguments:
5+
# $BUILD_TYPE: The build type, like "local", "dev", "test", "prod". Required.
6+
# $ENV_FOLDER: The folder containing env files. Optional.
7+
#
8+
# If $ENV_FOLDER is not present, then environment values will be used;
9+
# otherwise the topcoder-x-processor.env.default and topcoder-x-processor.env.$BUILD_TYPE
10+
# files within $ENV_FOLDER will be used.
11+
12+
BUILD_TYPE=$1
13+
ENV_FOLDER="$2"
14+
APP="topcoder-x-processor"
15+
16+
if [ -z "$BUILD_TYPE" ]; then
17+
echo "Must provide the build type to build"
18+
exit 1
19+
fi
20+
21+
ENV_FILE=".env.$BUILD_TYPE.tmp"
22+
DEFAULT_FILE=".env.default.tmp"
23+
rm -f "$ENV_FILE"
24+
rm -f "$DEFAULT_FILE"
25+
26+
if [ -z "$ENV_FOLDER" ]; then
27+
# Use environment values
28+
touch "$ENV_FILE"
29+
touch "$DEFAULT_FILE"
30+
31+
# Loop the environment values, find the ones start with DEFAULT_ and $BUILD_TYPE_
32+
# Assuming given $BUILD_TYPE is "prod" and environment has following values:
33+
# DEFAULT_VERSION=1.0
34+
# DEFAULT_SECRET=111111
35+
# PROD_PORT=80
36+
# PROD_SECRET=654321
37+
# LOCAL_PORT=8080
38+
# LOCAL_SECRET=123456
39+
# Then the generated .env file will have following content:
40+
# VERSION=1.0
41+
# PORT=80
42+
# SECRET=654321
43+
BUILD_TYPE_UPPER=`echo $BUILD_TYPE | awk '{print toupper($0)}'`
44+
for var in $(compgen -e); do
45+
if [[ "$var" =~ ^DEFAULT\_.* ]]; then
46+
tripVar=${var#DEFAULT_}
47+
echo $tripVar=${!var} >> "$DEFAULT_FILE"
48+
fi
49+
if [[ "$var" =~ ^$BUILD_TYPE_UPPER\_.* ]]; then
50+
tripVar=${var#"$BUILD_TYPE_UPPER"_}
51+
echo $tripVar=${!var} >> "$ENV_FILE"
52+
fi
53+
done
54+
55+
else
56+
if [ ! -d "$ENV_FOLDER" ]; then
57+
echo "$ENV_FOLDER does not exist"
58+
exit 1
59+
fi
60+
61+
P_DEFAULT_FILE="$ENV_FOLDER/$APP.env.default"
62+
P_ENV_FILE="$ENV_FOLDER/$APP.env.$BUILD_TYPE"
63+
64+
if [ ! -f "$P_DEFAULT_FILE" ]; then
65+
echo "$P_DEFAULT_FILE does not exist"
66+
exit 1
67+
fi
68+
cp -f "$P_DEFAULT_FILE" "$DEFAULT_FILE"
69+
70+
if [ ! -f "$P_ENV_FILE" ]; then
71+
echo "Will only use default env since $P_ENV_FILE does not exist"
72+
touch "$ENV_FILE"
73+
else
74+
cp -f "$P_ENV_FILE" "$ENV_FILE"
75+
fi
76+
fi
77+
78+
awk -F= '!a[$1]++' "$ENV_FILE" "$DEFAULT_FILE" > .env
79+
80+
rm -f "$ENV_FILE"
81+
rm -f "$DEFAULT_FILE"
82+
83+
# Build docker image
84+
docker build -t $APP:$BUILD_TYPE -f Dockerfile .

config/default.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (c) 2017 TopCoder, Inc. All rights reserved.
33
*/
44
'use strict';
5+
require('dotenv').config();
56
const fs = require('fs');
67
/**
78
* This module is the configuration of the app.
@@ -14,14 +15,14 @@ const fs = require('fs');
1415

1516
module.exports = {
1617
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
17-
PARTITION: process.env.PARTITION || 0,
18+
PARTITION: process.env.PARTITION ? parseInt(process.env.PARTITION) : 0,
1819
TOPIC: process.env.TOPIC || 'tc-x-events',
1920
KAFKA_OPTIONS: {
2021
connectionString: process.env.KAFKA_HOST || 'localhost:9092',
2122
ssl: {
2223
cert: process.env.KAFKA_CLIENT_CERT || fs.readFileSync('./kafka_client.cer'), // eslint-disable-line no-sync
2324
key: process.env.KAFKA_CLIENT_CERT_KEY || fs.readFileSync('./kafka_client.key'), // eslint-disable-line no-sync
24-
passphrase: 'secret', // NOTE:* This configuration specifies the private key passphrase used while creating it.
25+
passphrase: process.env.KAFKA_CLIENT_CERT_KEY_PASS || 'secret', // NOTE:* This configuration specifies the private key passphrase used while creating it.
2526
}
2627
},
2728
MONGODB_URL: process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/topcoderx',
@@ -39,7 +40,7 @@ module.exports = {
3940
device: 'Browser'
4041
},
4142
TC_AUTHZ_URL: process.env.TC_AUTHZ_URL || 'https://api.topcoder-dev.com/v3/authorizations',
42-
NEW_CHALLENGE_TEMPLATE: process.env.NEW_CHALLENGE_TEMPLATE || {
43+
NEW_CHALLENGE_TEMPLATE: process.env.NEW_CHALLENGE_TEMPLATE ? JSON.parse(process.env.NEW_CHALLENGE_TEMPLATE) : {
4344
milestoneId: 1,
4445
subTrack: 'FIRST_2_FINISH',
4546
reviewType: 'COMMUNITY',
@@ -66,11 +67,11 @@ module.exports = {
6667

6768
// NOTE: if subTrack is FIRST_2_FINISH,
6869
// this config has no effect since the ***EndsAt will be set automatically by TC APIs
69-
NEW_CHALLENGE_DURATION_IN_DAYS: process.env.NEW_CHALLENGE_DURATION_IN_DAYS || 5,
70+
NEW_CHALLENGE_DURATION_IN_DAYS: process.env.NEW_CHALLENGE_DURATION_IN_DAYS ? parseInt(process.env.NEW_CHALLENGE_DURATION_IN_DAYS) : 5,
7071
// node mailer option
7172
NODE_MAILER_OPTIONS: {
7273
host: process.env.SMTP_HOST || process.env.MAILGUN_SMTP_SERVER || 'smtp.gmail.com',
73-
port: process.env.SMTP_PORT || process.env.MAILGUN_SMTP_POR || 465,
74+
port: process.env.SMTP_PORT || process.env.MAILGUN_SMTP_PORT || 465,
7475
secure: process.env.SMTP_IS_SECURE || true,
7576
auth: {
7677
user: process.env.SMTP_USERNAME || process.env.MAILGUN_SMTP_LOGIN || '',
@@ -84,9 +85,9 @@ module.exports = {
8485
PAID_ISSUE_LABEL: process.env.PAID_ISSUE_LABEL || 'tcx_Paid',
8586
FIX_ACCEPTED_ISSUE_LABEL: process.env.FIX_ACCEPTED_ISSUE_LABEL || 'tcx_FixAccepted',
8687
READY_FOR_REVIEW_ISSUE_LABEL: process.env.READY_FOR_REVIEW_ISSUE_LABEL || 'tcx_ReadyForReview',
87-
ASSIGNED_ISSUE_LABEL: process.env.READY_FOR_REVIEW_ISSUE_LABEL || 'tcx_Assigned',
88-
OPEN_FOR_PICKUP_ISSUE_LABEL: process.env.READY_FOR_REVIEW_ISSUE_LABEL || 'tcx_OpenForPickup',
88+
ASSIGNED_ISSUE_LABEL: process.env.ASSIGNED_ISSUE_LABEL || 'tcx_Assigned',
89+
OPEN_FOR_PICKUP_ISSUE_LABEL: process.env.OPEN_FOR_PICKUP_ISSUE_LABEL || 'tcx_OpenForPickup',
8990
TC_OR_DETAIL_LINK: process.env.TC_OR_DETAIL_LINK || 'https://software.topcoder-dev.com/review/actions/ViewProjectDetails?pid=',
90-
RETRY_COUNT: process.env.RETRY_COUNT || 3,
91-
RETRY_INTERVAL: process.env.RETRY_INTERVAL || 120000, // 2 minutes
91+
RETRY_COUNT: process.env.RETRY_COUNT ? parseInt(process.env.RETRY_COUNT) : 3,
92+
RETRY_INTERVAL: process.env.RETRY_INTERVAL ? parseInt(process.env.RETRY_INTERVAL) : 120000, // 2 minutes
9293
};

configuration.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,31 @@ The following config parameters are supported, they are defined in `config/defau
77
| LOG_LEVEL | the log level | debug |
88
| PARTITION | The Kafka partition | 0|
99
| 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 |
10-
|TOPIC | The Kafka topic where events are published. This must be the same as the configured value for topcoder-x-processor| |
10+
|TOPIC | The Kafka topic where events are published. This must be the same as the configured value for topcoder-x-processor| tc-x-events |
1111
|KAFKA_OPTIONS | Kafka connection options| |
1212
|KAFKA_HOST | The Kafka host to connect to| localhost:9092 |
1313
|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 |
1414
|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|
15-
|TC_DEV_ENV| the flag whether to use topcoder development api or production| false|
15+
|KAFKA_CLIENT_CERT_KEY_PASS | The passphrase of certificate key | |
16+
|TC_DEV_ENV| the flag whether to use topcoder development api or production. Set env variable `NODE_ENV` to "production" will cause TC_DEV_ENV evaluated to false. | false|
1617
| TC_AUTHN_URL | the Topcoder authentication url | https://topcoder-dev.auth0.com/oauth/ro |
1718
| TC_AUTHN_REQUEST_BODY | the Topcoder authentication request body. This makes use of some environment variables: `TC_USERNAME`, `TC_PASSWORD`, `TC_CLIENT_ID`, `CLIENT_V2CONNECTION` | see `default.js` |
1819
| TC_AUTHZ_URL | the Topcoder authorization url | https://api.topcoder-dev.com/v3/authorizations |
19-
| NEW_CHALLENGE_TEMPLATE | the body template for new challenge request. You can change the subTrack, reviewTypes, technologies, .. here | see `default.js` |
20+
| NEW_CHALLENGE_TEMPLATE | the body template for new challenge request. You can change the subTrack, reviewTypes, technologies, .. here | see `default.js`. Note when setup by environment, it must be a valid JSON string format. |
2021
| NEW_CHALLENGE_DURATION_IN_DAYS | the duration of new challenge | 5 |
21-
| NODE_MAILER_OPTIONS| the node mailer smtp options, see [here](https://nodemailer.com/smtp/ for more detail)| see `default.js` |
22+
| NODE_MAILER_OPTIONS| the node mailer smtp options, see [here](https://nodemailer.com/smtp/ for more detail).This makes use of some environment variables: `SMTP_HOST`/`MAILGUN_SMTP_SERVER`, `SMTP_PORT`/`MAILGUN_SMTP_PORT`, `SMTP_USERNAME`/`MAILGUN_SMTP_LOGIN`,`SMTP_PASSWORD`/`MAILGUN_SMTP_PASSWORD`, `SMTP_IS_SECURE` | see `default.js` |
2223
|EMAIL_SENDER_ADDRESS| the email sender email address||
2324
|ISSUE_BID_EMAIL_RECEIVER| the email receiver about bid email||
2425
|TC_URL| the base URL of topcoder to get the challenge URL| defaults to `https://www.topcoder-dev.com`|
2526
|GITLAB_API_BASE_URL| the URL for gitlab host| defaults to `https://gitlab.com`|
2627
|PAID_ISSUE_LABEL|the label name for paid, should be one of the label configured in topcoder x ui|'tcx_Paid'|
2728
|FIX_ACCEPTED_ISSUE_LABEL|the label name for fix accepted, should be one of the label configured in topcoder x ui|'tcx_FixAccepted'|
29+
|READY_FOR_REVIEW_ISSUE_LABEL|the label name for ready for review, should be one of the label configured in topcoder x ui|'tcx_ReadyForReview'|
2830
|ASSIGNED_ISSUE_LABEL| the label name for assigned, should be one of the label configured in topcoder x ui| 'tcx_Assigned'|
2931
|OPEN_FOR_PICKUP_ISSUE_LABEL| the label name for open for pickup, should be one of the label configured in topcoder x ui| 'tcx_OpenForPickup'|
3032
|TC_OR_DETAIL_LINK|the link to online review detail of challenge| see `default.js`, OR link for dev environment|
3133
|RETRY_COUNT| the number of times an event should be retried to process| 3|
3234
|RETRY_INTERVAL| the interval at which the event should be retried to process in milliseconds | 120000|
33-
|READY_FOR_REVIEW_ISSUE_LABEL| the label name for ready for review, should be one of the label configured in topcoder x ui|'tcx_ReadyForReview'|
3435

3536
KAFKA_OPTIONS should be object as described in https://github.com/oleksiyk/kafka#ssl
3637
For using with SSL, the options should be as
@@ -72,7 +73,7 @@ Configure a Github project with a webhook with a format like this: https://<rece
7273

7374
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.
7475

75-
## Github Verification
76+
## Gitlab Verification
7677

7778
#### Webhook configuration
7879

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"dependencies": {
2727
"axios": "^0.16.2",
2828
"config": "^1.30.0",
29+
"dotenv": "^6.0.0",
2930
"get-parameter-names": "^0.3.0",
3031
"github": "^12.1.0",
3132
"global-request-logger": "^0.1.1",

0 commit comments

Comments
 (0)