-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·108 lines (92 loc) · 2.54 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
#!/usr/bin/env bash
DOT=$(cd -P "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)
IMAGE="${IMAGE:-registry.k8s.io/ingress-nginx/controller:v1.10.1}"
DOCKER="${DOCKER:-docker}"
IN_DOCKER="${IN_DOCKER:-0}"
LUA_SHARE="/usr/local/share/lua/5.1"
LUA_LIB="/usr/local/lib/lua/5.1"
check_deps() {
_deps=(
"openssl"
"${DOCKER}"
"dpkg-deb"
)
for _dep in "${_deps[@]}"; do
if ! command -v "$_dep" >/dev/null; then
echo -e "couldn't find $_dep; aborting"
exit 1
fi
done
}
main() {
check_deps
docker_exodus
copy_extras
make_deb
${DOCKER} rm -f $c_name
}
detach() {
sleep infinity
}
docker_exodus() {
c_name="ingress-$(openssl rand -hex 12)"
${DOCKER} run -d --rm --name $c_name --entrypoint="/bin/bash" \
-v ${DOT}/build.sh:/build.sh -v ${DOT}/exodus:/exodus \
--user root \
${IMAGE} /build.sh detach
${DOCKER} exec -it $c_name /build.sh do_exodus
}
do_exodus() {
set -ex
# install exodus
apk update
apk add --no-cache python3
rm /usr/lib/python3.11/EXTERNALLY-MANAGED
python3 -m ensurepip
pip3 install exodus-bundler
# port the nginx-ingress-controller + nginx binaries
exodus -o /exodus/controller-setup /nginx-ingress-controller
exodus -o /exodus/nginx-setup nginx
# lua things
mkdir -p "${LUA_SHARE}"
mv /usr/local/lib/lua/ngx "${LUA_SHARE}"/
mv /usr/local/lib/lua/resty "${LUA_SHARE}"/
mv /usr/local/lib/lua/librestychash.so "${LUA_LIB}"/
}
make_deb() {
_opt="${DOT}/pkgroot/opt/ingress-metal"
${DOT}/exodus/controller-setup "$_opt"
${DOT}/exodus/nginx-setup "$_opt"
cp -f ${DOT}/bin/run.sh "$_opt/bin/"
cp -f ${DOT}/bin/is-up.sh "$_opt/bin/"
dpkg-deb --build --root-owner-group pkgroot ingress-metal.deb
}
copy_extras() {
_extras=(
"/etc/nginx"
"${LUA_SHARE}"
"${LUA_LIB}/cjson.so"
"${LUA_LIB}/librestychash.so"
"/usr/lib/libbrotlicommon.so.1"
"/usr/lib/libbrotlidec.so.1"
"/usr/lib/libbrotlienc.so.1"
)
for _extra in "${_extras[@]}"; do
_to="${DOT}/pkgroot$(dirname $_extra)/"
mkdir -p $_to
if [[ "${IN_DOCKER}" == "0" ]]; then
${DOCKER} cp -L $c_name:$_extra $_to
else
cp -r -L $_extra $_to
fi
done
}
cleanup() {
${DOCKER} ps -a | grep "ingress-" | cut -d" " -f1 | xargs ${DOCKER} rm -f
rm -rf ${DOT}/pkgroot/{usr/{local/{lib,share},lib},etc/nginx,opt} ${DOT}/*.deb
}
if test -z "$1"; then
main
else
"$1"
fi