This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·176 lines (144 loc) · 5.29 KB
/
build.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env bash
set -o errexit
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Only set colors if we're writing output to a terminal
if tty -s ; then
reset="$( tput sgr0 )"
red="$( tput setaf 1 )"
green="$( tput setaf 2 )"
yellow="$( tput setaf 3 )"
else
reset=''
red=''
green=''
yellow=''
fi
if [[ $( git describe --tags --abbrev=0 ) = $( git describe --tags ) ]] ; then
version="$( git describe --tags )"
else
if [[ "$VAMP_GIT_BRANCH" != "" && "$VAMP_GIT_BRANCH" != "master" ]]; then
version=${VAMP_GIT_BRANCH//\//_}
else
version="katana"
fi
fi
target=${dir}'/target'
target_docker=${target}'/docker'
cd ${dir}
function parse_command_line() {
flag_help=0
flag_make=0
flag_build=0
for key in "$@"
do
case ${key} in
-h|--help)
flag_help=1
;;
-m|--make)
flag_make=1
;;
-b|--build)
flag_make=1
flag_build=1
;;
*)
;;
esac
done
}
function join { local IFS="$1"; shift; echo "$*"; }
function print_help() {
echo "${green}Usage of $0:${reset}"
echo "${yellow} -h |--help ${green}Help.${reset}"
echo "${yellow} -m |--make ${green}Copy Docker files to '${target}' directory.${reset}"
echo "${yellow} -b |--build ${green}Build Docker images.${reset}"
}
function sbt_make {
cd ${dir}
echo "${green}building jar: ${yellow}sbt clean test assembly${reset}"
sbt clean test assembly
mkdir -p ${target_docker}
cp $(find "${target}/scala-2.11" -name "vamp-runner-*.jar" | sort | tail -1) ${target_docker}/vamp-runner.jar
}
function gulp_make {
cd ${dir}/ui
echo "${green}building ui${reset}"
rm -Rf bower_components node_modules dist ui ui.tar.bz2 2> /dev/null
npm install
npm run ng -- build --env=prod
mv dist ui && tar -cvjSf ui.tar.bz2 ui
rm -Rf ui 2> /dev/null && mv ui.tar.bz2 ${target_docker}/
}
function docker_make {
cd ${dir}
echo "${green}copying recipes${reset}"
tar -cvjSf recipes.tar.bz2 recipes
mv recipes.tar.bz2 ${target_docker}/
echo "${green}generating configuration files${reset}"
cp ${dir}/conf/logback.xml ${target_docker}
recipes=()
for file in $( find "recipes" -type f -name "recipe.json" ) ; do
recipes+=(\""/usr/local/vamp-runner/${file}\"")
done
recipe_list=$( join , "${recipes[@]}" )
cat > ${target_docker}/application.conf << EOF
vamp.runner {
info.interval = 10 seconds
http {
port = 8088
ui {
index = "/usr/local/vamp-runner/ui/index.html"
directory = "/usr/local/vamp-runner/ui"
}
}
recipes {
timeout = {
short = 5 seconds
long = 60 seconds
}
files = [
${recipe_list}
]
}
}
EOF
echo "${green}generating docker file${reset}"
cat > ${target_docker}/Dockerfile << EOF
FROM java:8-jre-alpine
RUN mkdir -p /usr/local/vamp-runner
ADD ui.tar.bz2 vamp-runner.jar recipes.tar.bz2 application.conf logback.xml /usr/local/vamp-runner/
CMD ["java", "-jar", "-Dlogback.configurationFile=/usr/local/vamp-runner/logback.xml", "-Dconfig.file=/usr/local/vamp-runner/application.conf", "/usr/local/vamp-runner/vamp-runner.jar"]
EOF
}
function docker_build {
cd ${target_docker}
echo "${green}building docker image: ${yellow}magneticio/vamp-runner:${VAMP_TAG_PREFIX}${version}${reset}"
docker build -t magneticio/vamp-runner:${VAMP_TAG_PREFIX}${version} .
}
function process() {
sbt_make
gulp_make
docker_make
if [ ${flag_build} -eq 1 ]; then
docker_build
fi
echo "${green}done.${reset}"
}
parse_command_line $@
echo "${green}
██╗ ██╗ █████╗ ███╗ ███╗██████╗ ██████╗ ██╗ ██╗███╗ ██╗███╗ ██╗███████╗██████╗
██║ ██║██╔══██╗████╗ ████║██╔══██╗ ██╔══██╗██║ ██║████╗ ██║████╗ ██║██╔════╝██╔══██╗
██║ ██║███████║██╔████╔██║██████╔╝ ██████╔╝██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝
╚██╗ ██╔╝██╔══██║██║╚██╔╝██║██╔═══╝ ██╔══██╗██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗
╚████╔╝ ██║ ██║██║ ╚═╝ ██║██║ ██║ ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║ ██║
╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝
by magnetic.io
${reset}"
if [ ${flag_help} -eq 1 ] || [[ $# -eq 0 ]]; then
print_help
fi
if [ ${flag_make} -eq 1 ] || [ ${flag_build} -eq 1 ]; then
rm -Rf ${target} 2> /dev/null
process
fi