forked from infrawatch/sg-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·102 lines (86 loc) · 2.02 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
#!/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)
PLUGIN_DIR=${PLUGIN_DIR:-"/tmp/plugins/"}
CONTAINER_BUILD=${CONTAINER_BUILD:-false}
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=(
"amqp1"
"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"
go build -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"
go build -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"
go build -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"
go build -o /tmp/sg-core cmd/*.go
else
go build -o sg-core cmd/*.go
fi
}
build_plugins
build_core