Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit bafae32

Browse files
committed
Minimally sandboxified the mono-repo and added sub-sandbox configuration
1 parent c3d5267 commit bafae32

39 files changed

+648
-247
lines changed

api_server/bin/cs_api-vars

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,4 @@
22

33
#desc# Display sandbox environment variables
44

5-
# Find the root of the sandbox in a generic way (normally $XYZ_SANDBOX)
6-
# This is horrible but will work if the repo is a top level directory of the sandbox root.
7-
8-
# If not, replace these 3 lines of code and set sb_root to $XTZ_SANDBOX
9-
10-
sb_bin=`dirname $0`
11-
sb_top=`dirname $sb_bin`
12-
sb_root=`dirname $sb_top`
13-
dt-vars --sandbox_dir=$sb_root $*
5+
dt-vars --sandbox_dir=$CS_API_SANDBOX "$@"

api_server/hooks/git_hooks.sh

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,39 @@
33

44
# return 0 if file has changed, 1 if not
55
githook_file_has_changed() {
6-
local file=$1
7-
echo -n "Checking $file..."
8-
if [[ $(git diff HEAD@{1}..HEAD@{0} -- "${file}" | wc -l) -gt 0 ]]; then
9-
echo "modified"
10-
return 0
11-
fi
12-
echo "not modified"
13-
return 1
6+
local file=$1
7+
echo -n "Checking $file..."
8+
if [[ $(git diff HEAD@{1}..HEAD@{0} -- "${file}" | wc -l) -gt 0 ]]; then
9+
echo "modified"
10+
return 0
11+
fi
12+
echo "not modified"
13+
return 1
1414
}
1515

1616
# return 0 if any modues have been modified
1717
githook_module_is_modified() {
18-
local submod
19-
local tmpFile=/tmp/modupdated$$
20-
local rc=1
21-
for submod in `cat .gitmodules|grep '^\[submodule'|cut -f2 -d\"`; do
22-
[ ! -f /tmp/updated-mods ] && git status -s | grep "^ M" >$tmpFile
23-
grep -q "$submod$" $tmpFile && rc=0 && echo "git submodule $submod updated" && break
24-
done
25-
/bin/rm $tmpFile
26-
return $rc
18+
local submod
19+
local tmpFile=/tmp/modupdated$$
20+
local rc=1
21+
for submod in `cat .gitmodules|grep '^\[submodule'|cut -f2 -d\"`; do
22+
[ ! -f /tmp/updated-mods ] && git status -s | grep "^ M" >$tmpFile
23+
grep -q "$submod$" $tmpFile && rc=0 && echo "git submodule $submod updated" && break
24+
done
25+
/bin/rm $tmpFile
26+
return $rc
2727
}
2828

2929
# call the config-sandbox script if package.json, package-lock.json or yarn.lock changed or
3030
# if any git submodules' status is modified
3131
githook_reconfigure_sandbox() {
32-
[ -z "$CS_API_TOP" ] && echo "CS_API_TOP not set" && return
33-
local call_sandbox_config=0
34-
githook_module_is_modified && call_sandbox_config=1
35-
[ $call_sandbox_config -eq 0 -a -f package.json ] && githook_file_has_changed package.json && call_sandbox_config=1
36-
[ $call_sandbox_config -eq 0 -a -f package-lock.json ] && githook_file_has_changed package-lock.json && call_sandbox_config=1
37-
[ $call_sandbox_config -eq 0 -a "$CS_API_YARN" == "true" ] && githook_file_has_changed yarn.lock && call_sandbox_config=1
38-
[ $call_sandbox_config -eq 1 ] && echo "executing sandbox/configure-sandbox git-hook" && sandbox/configure-sandbox git-hook
32+
[ -z "$CS_API_TOP" ] && echo "CS_API_TOP not set" && return
33+
local call_sandbox_config=0
34+
githook_module_is_modified && call_sandbox_config=1
35+
[ $call_sandbox_config -eq 0 -a -f $CS_API_TOP/package.json ] && githook_file_has_changed $CS_API_TOP/package.json && call_sandbox_config=1
36+
[ $call_sandbox_config -eq 0 -a -f $CS_API_TOP/package-lock.json ] && githook_file_has_changed $CS_API_TOP/package-lock.json && call_sandbox_config=1
37+
# [ $call_sandbox_config -eq 0 -a "$CS_API_YARN" == "true" ] && githook_file_has_changed $CS_API_TOP/yarn.lock && call_sandbox_config=1
38+
[ $call_sandbox_config -eq 1 ] && echo "executing $CS_API_TOP/sandbox/configure-sandbox git-hook" && $CS_API_TOP/sandbox/configure-sandbox git-hook
3939
}
4040

4141
[ "$CS_API_DISABLE_GIT_HOOKS" == 1 ] && echo "hooks disabled (CS_API_DISABLE_GIT_HOOKS=1)" && exit 0
Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
#!/bin/bash
22

33
[ -z "$1" ] && echo "Do not run this script directly. Run dt-configure-sandbox instead." && exit 1
4-
[ "$1" == "git-hook" ] && sb_git_hook=1 || sb_git_hook=0
4+
5+
# argument:
6+
# configure normal configuration mode. Run on a clean install or reconfigure (mode = configure)
7+
# git_hook run from within a git hook (mode = git_hook)
8+
# deploy run from within a deployment (dt-build)
9+
# configureNoAbort configuration mode but don't abort early if there's a build failure (mode = configure)
10+
mode=""
11+
abort_on_fail=1
12+
[ "$1" == "git-hook" ] && mode=git_hook
13+
[ "$1" == "configure" ] && mode=configure
14+
[ "$1" == "deploy" ] && mode=deploy
15+
[ "$1" == "configureNoAbort" ] && mode=configure && abort_on_fail=0
16+
[ -z "$mode" ] && echo "Error: bad configure mode" && exit 1
517

618
# This script is called from dt-configure-sandbox. Do not call it directly.
719
# It may also be called from a git hook.
820
#
921
# Place any commands needed to prepare the sandbox for use here. Assume all
1022
# environment variables have been set.
1123

12-
cd $CS_API_TOP
13-
[ ! -d .git ] && echo "nothing to configure for a pre-built asset sandbox" && exit 0
24+
[ ! -d $CS_API_REPO_ROOT/.git ] && echo "nothing to configure for a pre-built asset sandbox ($CS_API_REPO_ROOT/.git not found)" && exit 0
25+
[ -f $CS_API_REPO_ROOT/.gitmodules ] && echo "updating submodules" && (cd $CS_API_REPO_ROOT && git submodule update --init --recursive)
1426

15-
[ -f .gitmodules ] && echo "updating submodules" && git submodule update --init --recursive
27+
cd $CS_API_TOP
1628

1729
if [ -n "$CS_API_NODE_MODULES_DIR" ]; then
1830
[ -d "$CS_API_NODE_MODULES_DIR" ] && /bin/rm -rf $CS_API_NODE_MODULES_DIR
@@ -21,14 +33,8 @@ else
2133
[ -d $CS_API_TOP/node_modules ] && /bin/rm -rf $CS_API_TOP/node_modules
2234
fi
2335

24-
if [ "$CS_API_YARN" == true ]; then
25-
[ ! -f $CS_API_TOP/yarn.lock ] && echo "WARNING: yarn.lock not found - creating one"
26-
echo "yarn install (from `pwd`)"
27-
yarn install --frozen-lockfile
28-
else
29-
echo "npm install --no-save $CS_API_NPM_INSTALL_XTRA_OPTS (from `pwd`)"
30-
npm install --no-save $CS_API_NPM_INSTALL_XTRA_OPTS
31-
fi
36+
echo "npm install --no-save $CS_API_NPM_INSTALL_XTRA_OPTS (from `pwd`)"
37+
npm install --no-save $CS_API_NPM_INSTALL_XTRA_OPTS
3238

3339
# package integrity check
3440
# if [ -f sandbox/package-versions.txt ]; then
@@ -48,15 +54,16 @@ fi
4854
# /bin/rm $tmpfile
4955
# fi
5056

57+
# This needs to work for both individual and mono-repo
5158
echo -n "Installing git hooks as sym links"
52-
cd $CS_API_TOP/.git/hooks
59+
cd $CS_API_REPO_ROOT/.git/hooks
60+
[ -d ../../api_server/hooks ] && hooksDir=../../api_server/hooks || hooksDir=../../hooks
5361
for hook in post-checkout post-merge post-rewrite
5462
do
55-
echo -n "...$hook"
56-
/bin/rm -f $hook
57-
ln -sf ../../hooks/$hook
63+
echo -n "__ $hooksDir/$hook __"
64+
ln -snf $hooksDir/$hook
5865
done
59-
echo "."
66+
echo
6067

6168
# You must exit with a status of '0' if the script was successful or '1' otherwise.
6269
exit 0

api_server/sandbox/defaults.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ sandutil_load_options $CS_API_SANDBOX || { echo "failed to load options" >&2 &&
88
export PATH=$CS_API_SANDBOX/node/bin:$CS_API_TOP/node_modules/.bin:$PATH
99

1010
export PATH=$CS_API_TOP/bin:$PATH
11+
12+
export NODE_PATH=$CS_API_TOP/node_modules:$NODE_PATH
13+
1114
[ -z "$CS_API_LOGS" ] && export CS_API_LOGS=$CS_API_SANDBOX/log
1215
[ -z "$CS_API_PIDS" ] && export CS_API_PIDS=$CS_API_SANDBOX/pid
1316
[ -z "$CS_API_TMP" ] && export CS_API_TMP=$CS_API_SANDBOX/tmp
@@ -21,12 +24,15 @@ if [ -n "$CSSVC_CFG_URL" ]; then
2124
apiPort=`eval echo $(get-json-property --config-url $CSSVC_CFG_URL -p apiServer.assetEnvironment)`
2225
else
2326
[ -n "$CS_API_CFG_FILE" ] && configParm=$CS_API_CFG_FILE || configParm="$CSSVC_CONFIGURATION"
24-
sandutil_get_codestream_cfg_file "$CS_API_SANDBOX" "$configParm" "$CSSVC_ENV"
27+
[ -z "$CSSVC_CFG_FILE" ] && sandutil_get_codestream_cfg_file "$CS_API_SANDBOX" "$configParm" "$CSSVC_ENV"
2528
export CSSVC_ENV=`eval echo $(get-json-property -j $CSSVC_CFG_FILE -p sharedGeneral.runTimeEnvironment)`
2629
export CS_API_ASSET_ENV=`eval echo $(get-json-property -j $CSSVC_CFG_FILE -p apiServer.assetEnvironment)`
2730
apiPort=`eval echo $(get-json-property -j $CSSVC_CFG_FILE -p apiServer.port)`
2831
fi
2932

33+
# sanity check
34+
[ -n "$CS_API_CFG_FILE" -a \( "$CSSVC_CFG_FILE" != "$CS_API_CFG_FILE" \) ] && echo "**** WARNING: CS_API_CFG_FILE != CSSVC_CFG_FILE"
35+
3036
# needed for the build process
3137
export CS_API_ENV=$CSSVC_ENV
3238

@@ -54,3 +60,9 @@ fi
5460
# Instructs the service init script to initialize the database and run
5561
# ensure_indexes.js whenever the api service is started
5662
export CS_API_SETUP_MONGO=true
63+
64+
65+
# Multiple installations - mono-repo and individual - have the same repo root ($REPO_ROOT/.git/)
66+
. $CS_API_SANDBOX/sb.info
67+
[ -n "$SB_REPO_ROOT" ] && export CS_API_REPO_ROOT=$CS_API_SANDBOX/$SB_REPO_ROOT || export CS_API_REPO_ROOT=$CS_API_TOP
68+
[ -z "$CSSVC_BACKEND_ROOT" ] && export CSSVC_BACKEND_ROOT=$CS_API_REPO_ROOT
Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
#!/bin/bash
22

3-
[ -z "$2" ] && echo "Run dt-install-sandbox-software to call this script" && exit 1
3+
# This script is a hook called via the dt-install-sandbox-software command.
4+
# Do not run it directly.
45

5-
# This script is called via the dt-install-sandbox-software command.
6-
# Do not run it directly. Further, this is called prior to the
7-
# sandbox environment being loaded into the shell so any variables
8-
# needed from the defaults.sh (or other env file) must be setup
9-
# manually.
10-
11-
export CS_API_SANDBOX=$1 # root of the sandbox
12-
export CS_API_TOP=$2 # root of the primary git project
13-
SB_ENV_FILE=$3 # name of the environment file to use
14-
export CS_API_NAME=`dirname $CS_API_SANDBOX`
15-
[ -z "$SB_ENV_FILE" ] && SB_ENV_FILE=defaults.sh
16-
17-
# With the previous 3 variables defined, you can now load a defaults file if
18-
# need be.
19-
. $CS_API_TOP/sandbox/$SB_ENV_FILE
6+
[ -z "$1" ] && echo "Run dt-install-sandbox-software to call this script" && exit 1
207

8+
if [ "$1" != "--env-loaded" ]; then
9+
[ -z "$2" ] && echo "Run dt-install-sandbox-software (version 1) to call this script" && exit 1
10+
[ -z "$CS_API_SANDBOX" ] && export CS_API_SANDBOX=$1 # root of the sandbox
11+
[ -z "$CS_API_TOP" ] && export CS_API_TOP=$2 # root of the primary git project
12+
SB_ENV_FILE=$3 # name of the environment file to use
13+
[ -z "$CS_API_NAME" ] && export CS_API_NAME=`dirname $CS_API_SANDBOX`
14+
[ -z "$SB_ENV_FILE" ] && SB_ENV_FILE=defaults.sh
15+
. $CS_API_TOP/sandbox/$SB_ENV_FILE
16+
fi
2117

2218
# Install additional git projects
2319
# cd $CS_API_SANDBOX
@@ -44,13 +40,10 @@ export CS_API_NAME=`dirname $CS_API_SANDBOX`
4440
# Install node if specified with CS_API_NODE_VER
4541
[ -n "$CS_API_NODE_VER" -a ! -L $CS_API_SANDBOX/node ] && dt-get-software -V $CS_API_NODE_VER node $CS_API_SANDBOX
4642

47-
# Install yarn if specified with CS_API_YARN_VER
48-
[ -n "$CS_API_YARN_VER" -a ! -L $CS_API_SANDBOX/yarn ] && dt-get-software -V $CS_API_YARN_VER yarn $CS_API_SANDBOX
49-
50-
[ ! -d $CS_API_TOP/.git ] && echo "This is a runtime environment installation" && exit 0
43+
[ ! -d $CS_API_REPO_ROOT/.git ] && echo "This is a runtime environment installation" && exit 0
5144

5245
# Install secondary git repos
53-
echo "Cloning TestRepo"
54-
(cd $CS_API_SANDBOX && git clone [email protected]:teamcodestream/TestRepo) || exit 1
46+
# echo "Cloning TestRepo"
47+
# (cd $CS_API_SANDBOX && git clone [email protected]:teamcodestream/TestRepo) || exit 1
5548

5649
exit 0

bin/csbe-help

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
#desc# brief command summary
4+
5+
dt-help "$CSBE_TOP/bin" "$@"

bin/csbe-service

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
#desc# csbackend service init script
4+
5+
function usage {
6+
echo "usage: $0 { start | stop | status } [-- service-args]" >&2
7+
exit 1
8+
}
9+
10+
echo "This is just a template - this script needs to be edited"; exit 1
11+
12+
service_name=XXXXX
13+
[ -z "$1" ] && usage
14+
[ -z "$CSBE_SANDBOX" ] && echo "sandbox not loaded">&2 && exit 1
15+
. $DT_TOP/lib/init_funcs.sh
16+
17+
ec=0
18+
case "$1" in
19+
start)
20+
# start the service here
21+
service_status $service_name
22+
ec=$?
23+
;;
24+
stop)
25+
service_stop $service_name
26+
ec=$?
27+
sleep 2
28+
service_status $service_name
29+
;;
30+
status)
31+
service_status $service_name
32+
;;
33+
*)
34+
usage
35+
;;
36+
esac
37+
exit $ec

bin/csbe-tc-buildstep

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python3
2+
3+
# desc# Standard interface to CodeStream's build process
4+
5+
# https://github.com/TeamCodeStream/teamcity_tools/blob/master/README.md#Structured_Builds
6+
7+
import os
8+
import sys
9+
10+
sys.path.append(os.environ['DT_TOP'] + "/lib")
11+
import sysUtils as su
12+
import buildUtils
13+
14+
su.printErr("this script needs to be customized")
15+
exit(1)
16+
17+
# 1. add filename extensions for all assets created (tgz, vsix, zip, ...)
18+
assetExtensionList = ['tgz']
19+
20+
# 2. add any additional repos to be included (do not include primary repo)
21+
additionalRepos = []
22+
23+
# 3. choose the build type (npm, intellijPlugin, custom)
24+
# https://github.com/TeamCodeStream/teamcity_tools/blob/master/README.project-build-types.md
25+
buildType = buildUtils.buildType.npm
26+
27+
args = buildUtils.parseStandardBuildArgs()
28+
buildOptions = {
29+
'verbose': args.verbose,
30+
'assetExtensionList': assetExtensionList,
31+
# 'buildDirectory': '...', # execute build in this subdirectory relative to repo root
32+
# 'useDistDir': True, # assets are created/managed in 'dist/' directory
33+
'additionalRepos': additionalRepos
34+
}
35+
36+
# 4. Set this if you want your applied git tags to be something other than 'v' (v1.2.3)
37+
# buildOptions['gitTagPrefix'] = "mytag-"
38+
39+
if args.verbose:
40+
print("buildstep running with", args.action)
41+
42+
build = buildUtils.build(buildType, **buildOptions)
43+
if not build:
44+
su.printErr("could not get a build object")
45+
exit(1)
46+
47+
# 5. Make sure the default actions apply, if not make changes as necessary.
48+
# Use 'build.execCmd("command string")' to execute custom actions.
49+
# https://github.com/TeamCodeStream/teamcity_tools/blob/master/README.build-configurations.md
50+
if args.action == 'prep':
51+
build.prep() # set teamcity variables / parameters
52+
elif args.action == 'build':
53+
build.build() # complete build so services can be started
54+
elif args.action == 'citest':
55+
build.citest() # run the continuous integration test suite
56+
elif args.action == 'pack':
57+
build.pack() # create asset info file and package assets
58+
elif args.action == 'publish':
59+
build.publish() # publish assets for distribution
60+
elif args.action == 'tag':
61+
build.tag() # update version info and apply tags
62+
elif args.action == 'release':
63+
build.release() # release assets to the general public
64+
else:
65+
su.printErr("invalid build args")
66+
exit(1)
67+
68+
exit(0)

bin/csbe-vars

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
#desc# Display sandbox environment variables
4+
5+
# Find the root of the sandbox in a generic way (normally $XYZ_SANDBOX)
6+
# This is horrible but will work if the repo is a top level directory of the sandbox root.
7+
8+
# If not, replace these 3 lines of code and set sb_root to $XTZ_SANDBOX
9+
10+
sb_bin=`dirname $0`
11+
sb_top=`dirname $sb_bin`
12+
sb_root=`dirname $sb_top`
13+
dt-vars --sandbox_dir=$sb_root $*

broadcaster/bin/cs_broadcaster-vars

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,4 @@
22

33
#desc# Display sandbox environment variables
44

5-
# Find the root of the sandbox in a generic way (normally $XYZ_SANDBOX)
6-
# This is horrible but will work if the repo is a top level directory of the sandbox root.
7-
8-
# If not, replace these 3 lines of code and set sb_root to $XTZ_SANDBOX
9-
10-
sb_bin=`dirname $0`
11-
sb_top=`dirname $sb_bin`
12-
sb_root=`dirname $sb_top`
13-
dt-vars --sandbox_dir=$sb_root $*
5+
dt-vars --sandbox_dir=$CS_BROADCASTER_SANDBOX "$@"

0 commit comments

Comments
 (0)