forked from vmware-archive/ModSecurity-envoy
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sh
executable file
·150 lines (124 loc) · 3.62 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
#!/bin/bash
function check_modsecurity() {
if [ -d /usr/local/modsecurity/lib/pkgconfig ]; then
export PKG_CONFIG_PATH="/usr/local/modsecurity/lib/pkgconfig:$PKG_CONFIG_PATH"
export LD_LIBRARY_PATH="/usr/local/modsecurity/lib:$LD_LIBRARY_PATH"
fi
if ! pkg-config modsecurity --exists; then
echo "Not found ModSecurity"
exit 1
fi
}
function gen_workspace() {
cat <<EOL > WORKSPACE
workspace(name = "envoy_filter_modsecurity")
local_repository(
name = "envoy",
path = "envoy",
)
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "bazel_pkg_config",
strip_prefix = "bazel_pkg_config-master",
urls = ["https://github.com/cherrry/bazel_pkg_config/archive/master.zip"],
)
load("@bazel_pkg_config//:pkg_config.bzl", "pkg_config")
pkg_config(
name = "modsecurity",
ignore_opts = [
"-lmodsecurity"
],
min_version = "3.0.4"
)
EOL
# patch envoy workspace
cat envoy/WORKSPACE | sed -e '1d' | sed -e 's|//bazel|@envoy//bazel|g' >> WORKSPACE
}
if [ ! -f envoy/VERSION ]; then
if [ -d .git ]; then
echo "Downloading submodule"
git submodule update --init
echo "Done"
else
echo "Please download envoy source"
exit 1
fi
fi
case $1 in
list-versions )
cd envoy
if [ -f .git ] || [ -d .git ]; then
git ls-remote --tags 2> /dev/null | grep -o "refs/tags/.*" | sort -rV | grep -o '[^\/]*$'
else
echo "Not clone from git"
exit 1
fi
;;
version )
echo "v$(cat envoy/VERSION)"
;;
set-version )
cd envoy
if [ -f .git ] || [ -d .git ]; then
git checkout master && git pull
git checkout $2
else
echo "Not clone from git"
exit 1
fi
;;
set-clang )
gen_workspace
./envoy/bazel/setup_clang.sh $2
;;
test )
check_modsecurity
# show version to build
echo "Test with envoy $($0 version)"
gen_workspace
bazel test //:envoy_binary_test ${@:2} || exit 1
bazel test //http-filter-modsecurity:modsecurity_filter_integration_test ${@:2} || exit 1
echo "Done!"
;;
build )
check_modsecurity
# show version to build
echo "Build with envoy $($0 version)"
gen_workspace
echo "Start build"
bazel build //:envoy ${@:2} || exit 1
echo "Done!"
;;
release )
check_modsecurity
# show version to build
echo "Build with envoy $($0 version)"
gen_workspace
echo "Start build"
bazel build //:envoy.stripped -c opt ${@:2} || exit 1
echo "Done!"
;;
install )
if [ ! -f bazel-bin/envoy ]; then
$0 build || exit 1
fi
(
install -m 755 -s bazel-bin/envoy.stripped /usr/local/bin/envoy ||
install -m 755 -s bazel-bin/envoy /usr/local/bin/envoy
)
echo "Done!"
;;
help|*)
echo "$0 <command [args...]>"
echo
echo "Commands:"
echo " list-versions List online envoy versions (git)"
echo " version Get current envoy version"
echo " set-version <ver> Set envoy version (git)"
echo " build Start build"
echo " release Start build release"
echo " test Start test"
echo " install Install envoy to system path"
echo " help This message"
;;
esac