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

Commit d446e1f

Browse files
committed
Dockerize updates
1 parent 96988f9 commit d446e1f

File tree

7 files changed

+118
-6
lines changed

7 files changed

+118
-6
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

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 8.12
2+
FROM node:8.12
3+
4+
# Set working directory for future use
5+
WORKDIR /topcoder-x-ui
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+
RUN npm run build
16+
17+
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-ui.env.default and topcoder-x-ui.env.$BUILD_TYPE
10+
# files within $ENV_FOLDER will be used.
11+
12+
BUILD_TYPE=$1
13+
ENV_FOLDER="$2"
14+
APP="topcoder-x-ui"
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 .

configuration.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ The following config parameters are supported, they are defined in `src/config.j
1616
| WEBSITE | used as base to construct various URLs | http://topcoderx.topcoder-dev.com/ |
1717
| GITLAB_API_BASE_URL | The Gitlab API base URL | https://gitlab.com|
1818
| 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 |
19-
|TOPIC | The Kafka topic where events are published. This must be the same as the configured value for topcoder-x-processor| |
19+
|TOPIC | The Kafka topic where events are published. This must be the same as the configured value for topcoder-x-processor| tc-x-events |
2020
|KAFKA_OPTIONS | Kafka connection options| |
2121
|KAFKA_HOST | The Kafka host to connect to| localhost:9092 |
2222
|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 |
2323
|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|
24+
|KAFKA_CLIENT_CERT_KEY_PASS | The passphrase of certificate key | |
2425
| HOOK_BASE_URL | The base URL of the topcoder-x-receiver, used when adding webhooks automatically to repositories | |
2526
| TOPCODER_ENV | The topcoder environment to use, can support 'dev' or 'prod' | 'dev' |
26-
|LABELS| Labels we are going to add to the repository in the form of array of object with `name` and `color` property. Color should be hex code without hash||
27-
|ALLOWED_TOPCODER_ROLES| The allowed Topcoder role to use Topcoder X app| see configuration |
27+
|LABELS| Labels we are going to add to the repository in the form of array of object with `name` and `color` property. Color should be hex code without hash|See configuration. Note when setup by environment, it must be a valid JSON string format.|
28+
|ALLOWED_TOPCODER_ROLES| The allowed Topcoder role to use Topcoder X app| See configuration. Note when setup by environment, it must be a valid JSON string format. |
2829
|COPILOT_ROLE| The role to identify copilot|'copilot'|
2930
|HELP_LINK| The link for help| 'https://github.com/topcoder-platform/topcoder-x-ui/wiki'|
3031

package-lock.json

Lines changed: 5 additions & 0 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
@@ -49,6 +49,7 @@
4949
"core-js": "^2.4.1",
5050
"cors": "^2.8.4",
5151
"debug": "~2.6.3",
52+
"dotenv": "^6.0.0",
5253
"express": "^4.15.4",
5354
"express-jwt": "^5.3.0",
5455
"express-session": "^1.15.5",

src/config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (c) 2017 TopCoder, Inc. All rights reserved.
33
*/
4+
require('dotenv').config();
45
const fs = require('fs');
56
/**
67
* Define config.
@@ -30,13 +31,13 @@ module.exports = {
3031
ssl: {
3132
cert: process.env.KAFKA_CLIENT_CERT || fs.readFileSync('./kafka_client.cer'), // eslint-disable-line no-sync
3233
key: process.env.KAFKA_CLIENT_CERT_KEY || fs.readFileSync('./kafka_client.key'), // eslint-disable-line no-sync
33-
passphrase: 'secret', // NOTE:* This configuration specifies the private key passphrase used while creating it.
34+
passphrase: process.env.KAFKA_CLIENT_CERT_KEY_PASS || 'secret', // NOTE:* This configuration specifies the private key passphrase used while creating it.
3435
},
3536
},
3637
HOOK_BASE_URL: process.env.HOOK_BASE_URL || 'http://topcoderx.topcoder-dev.com',
3738
TOPCODER_ENV: process.env.TOPCODER_ENV || 'dev',
38-
LABELS: process.env.LABELS || [{ name: 'tcx_OpenForPickup', color: '428BCA' }, { name: 'tcx_Assigned', color: '004E00' }, { name: 'tcx_ReadyForReview', color: 'D1D100' }, { name: 'tcx_Paid', color: '7F8C8D' }, { name: 'tcx_Feedback', color: 'FF0000' }, { name: 'tcx_FixAccepted', color: '69D100' }],
39-
ALLOWED_TOPCODER_ROLES: process.env.ALLOWED_TOPCODER_ROLES || ['administrator', 'admin', 'connect manager', 'connect admin', 'copilot', 'connect copilot'],
39+
LABELS: process.env.LABELS ? JSON.parse(process.env.LABELS) : [{ name: 'tcx_OpenForPickup', color: '428BCA' }, { name: 'tcx_Assigned', color: '004E00' }, { name: 'tcx_ReadyForReview', color: 'D1D100' }, { name: 'tcx_Paid', color: '7F8C8D' }, { name: 'tcx_Feedback', color: 'FF0000' }, { name: 'tcx_FixAccepted', color: '69D100' }],
40+
ALLOWED_TOPCODER_ROLES: process.env.ALLOWED_TOPCODER_ROLES ? JSON.parse(process.env.ALLOWED_TOPCODER_ROLES) : ['administrator', 'admin', 'connect manager', 'connect admin', 'copilot', 'connect copilot'],
4041
COPILOT_ROLE: process.env.COPILOT_ROLE || 'copilot',
4142
HELP_LINK: process.env.HELP_LINK || 'https://github.com/topcoder-platform/topcoder-x-ui/wiki',
4243
};

0 commit comments

Comments
 (0)