-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.sh
executable file
·103 lines (87 loc) · 2.12 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
#!/bin/bash
# Build locally:
# ./build.sh
#
# Build for container:
# CONTAINER_BUILD=true ./build.sh
#
# Production build (omits test plugin binaries to minimize image size and builds for container)
# PRODUCTION_BUILD=true ./build.sh
base=$(pwd)
GOCMD=${GOCMD:-"go"}
PLUGIN_DIR=${PLUGIN_DIR:-"/tmp/plugins/"}
CONTAINER_BUILD=${CONTAINER_BUILD:-false}
BUILD_ARGS=${BUILD_ARGS:-''}
PRODUCTION_BUILD=${PRODUCTION_BUILD:-false}
if $PRODUCTION_BUILD; then
CONTAINER_BUILD=true
fi
# add plugins here that should be omitted in production build
# to keep the image size as small as possible
if $PRODUCTION_BUILD; then
OMIT_TRANSPORTS=(
"dummy-alertmanager"
"dummy-events"
"dummy-metrics"
"dummy-logs"
)
OMIT_HANDLERS=(
)
OMIT_APPLICATIONS=(
)
fi
search_list() {
#arges: search_string, list_to_search
arrName=$2[@]
arr=("${!arrName}")
for entry in "${arr[@]}"; do
if [ $entry == $1 ]; then
return 1
fi
done
return 0
}
build_plugins() {
# build transports
cd "$base"
for i in plugins/transport/*; do
cd "$base/$i"
search_list "$(basename $i)" OMIT_TRANSPORTS
if [ $? -ne 1 ]; then
echo "building $(basename $i).so"
$GOCMD build $BUILD_ARGS -o "$PLUGIN_DIR$(basename $i).so" -buildmode=plugin
fi
done
# build handlers
cd "$base"
for i in plugins/handler/*; do
cd "$base/$i"
search_list "$(basename $i)" OMIT_HANDLERS
if [ $? -ne 1 ]; then
echo "building $(basename $i).so"
$GOCMD build $BUILD_ARGS -o "$PLUGIN_DIR$(basename $i).so" -buildmode=plugin
fi
done
# build applications
cd "$base"
for i in plugins/application/*; do
cd "$base/$i"
search_list "$(basename $i)" OMIT_APPLICATIONS
if [ $? -ne 1 ]; then
echo "building $(basename $i).so"
$GOCMD build $BUILD_ARGS -o "$PLUGIN_DIR$(basename $i).so" -buildmode=plugin
fi
done
}
build_core() {
# build sg-core
cd "$base"
if $CONTAINER_BUILD; then
echo "building sg-core for container"
$GOCMD build $BUILD_ARGS -o /tmp/sg-core cmd/*.go
else
$GOCMD build $BUILD_ARGS -o sg-core cmd/*.go
fi
}
build_plugins
build_core