forked from d2iq-archive/dcos-commons
-
Notifications
You must be signed in to change notification settings - Fork 6
/
new-standalone-service.sh
executable file
·128 lines (100 loc) · 3.91 KB
/
new-standalone-service.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
set -e
CLEANUP_PATH=`pwd`
VERSION="0.15.0"
cleanup() {
debug "Cleaning up"
rm -rf $CLEANUP_PATH/template.zip
}
trap cleanup INT TERM
error_msg() {
echo "---"
echo "Failed to generate the project: Exited early at $0:L$1"
echo "To try again, re-run this script."
echo "---"
}
trap 'error_msg ${LINENO}' ERR
info() {
echo $1
}
debug() {
if [[ -z "${DEBUG// }" ]]; then
return
fi
echo "DEBUG: $1"
}
PROJECT_NAME=$1
PROJECT_PATH=$2
if [[ -z "${PROJECT_NAME// }" ]]; then
echo "You must provide the name of the project as the first argument"
echo "Usage: ./new-standalone-service.sh project-name"
echo "Example: ./new-standalone-service.sh kafka"
cleanup
exit 1
fi
if [[ -z "${PROJECT_PATH// }" ]]; then
PROJECT_PATH=$(pwd)
fi
debug "Scaffolding $PROJECT_NAME from template"
cp -R frameworks/template $PROJECT_PATH/$PROJECT_NAME
cp -R tools $PROJECT_PATH/$PROJECT_NAME/tools
cp -R testing $PROJECT_PATH/$PROJECT_NAME/testing
cp ./.gitignore $PROJECT_PATH/$PROJECT_NAME
rm -rf $PROJECT_PATH/$PROJECT_NAME/build
rm -rf $PROJECT_PATH/$PROJECT_NAME/cli/dcos-*/*template*
rm -rf $PROJECT_PATH/$PROJECT_NAME/cli/dcos-*/.*template*
rm -rf $PROJECT_PATH/$PROJECT_NAME/build.sh
cat > $PROJECT_PATH/$PROJECT_NAME/build.sh <<'EOF'
#!/bin/bash
set -e
FRAMEWORK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BUILD_DIR=$FRAMEWORK_DIR/build/distributions
PUBLISH_STEP=${1-none}
export REPO_NAME="$(basename $FRAMEWORK_DIR)"
export BUILD_BOOTSTRAP=no
export TOOLS_DIR=${FRAMEWORK_DIR}/tools
export CLI_DIR=${FRAMEWORK_DIR}/cli
export ORG_PATH=github.com/$REPO_NAME
${FRAMEWORK_DIR}/tools/build_framework.sh $PUBLISH_STEP $REPO_NAME $FRAMEWORK_DIR $BUILD_DIR/$REPO_NAME-scheduler.zip
EOF
chmod +x $PROJECT_PATH/$PROJECT_NAME/build.sh
cat > $PROJECT_PATH/$PROJECT_NAME/settings.gradle << EOF
rootProject.name = '$PROJECT_NAME'
EOF
cat > $PROJECT_PATH/$PROJECT_NAME/tests/__init__.py << EOF
import sys
import os.path
# Add /testing/ to PYTHONPATH:
this_file_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.normpath(os.path.join(this_file_dir, '..', 'testing')))
EOF
cat > $PROJECT_PATH/$PROJECT_NAME/test.sh << 'EOF'
#!/usr/bin/env bash
set -e
if [ -z "$CLUSTER_URL" ]; then
if [ -z "$1" ]; then
echo "Syntax: $0 <cluster-url>, or CLUSTER_URL=<cluster-url> $0"
exit 1
fi
export CLUSTER_URL=$1
fi
REPO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
${REPO_ROOT_DIR}/tools/run_tests.py shakedown ${REPO_ROOT_DIR}/tests/
EOF
chmod +x $PROJECT_PATH/$PROJECT_NAME/test.sh
mv $PROJECT_PATH/$PROJECT_NAME/cli/dcos-template $PROJECT_PATH/$PROJECT_NAME/cli/dcos-$PROJECT_NAME
mv $PROJECT_PATH/$PROJECT_NAME/src/main/java/com/mesosphere/sdk/template/ $PROJECT_PATH/$PROJECT_NAME/src/main/java/com/mesosphere/sdk/$PROJECT_NAME/
mv $PROJECT_PATH/$PROJECT_NAME/src/test/java/com/mesosphere/sdk/template/ $PROJECT_PATH/$PROJECT_NAME/src/test/java/com/mesosphere/sdk/$PROJECT_NAME/
UPPER_CASE_PROJECT_NAME=$(echo $PROJECT_NAME | awk '{print toupper($0)}')
find $PROJECT_PATH/$PROJECT_NAME -type f -exec sed -i.bak "s/template/$PROJECT_NAME/g; s/TEMPLATE/$UPPER_CASE_PROJECT_NAME/g; s/template/$PROJECT_NAME/g" {} \;
sed -i.bak -e '21,$ d' $PROJECT_PATH/$PROJECT_NAME/src/main/dist/svc.yml
find $PROJECT_PATH/$PROJECT_NAME -type f -name *.bak -exec rm -f {} \;
sed -i.bak "s/compile project(\":scheduler\")/compile \"mesosphere:scheduler:$VERSION\"/g" $PROJECT_PATH/$PROJECT_NAME/build.gradle
sed -i.bak "s/compile project(\":executor\")/compile \"mesosphere:executor:$VERSION\"/g" $PROJECT_PATH/$PROJECT_NAME/build.gradle
sed -i.bak "s/testCompile project(\":testing\")/testCompile \"mesosphere:testing:$VERSION\"/g" $PROJECT_PATH/$PROJECT_NAME/build.gradle
rm -f $PROJECT_PATH/$PROJECT_NAME/build.gradle.bak
GRADLEW=$(pwd)/gradlew
pushd $PROJECT_PATH/$PROJECT_NAME
$GRADLEW wrapper --gradle-version 3.4.1
popd
echo "New project created successfully"