forked from isard-vdi/isard
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·170 lines (157 loc) · 3.17 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
#!/bin/sh
set -e
git submodule init
git submodule update --recursive --remote
cp isardvdi.cfg .env
## BUILD_ROOT_PATH env
# This is a workarround for
# https://github.com/docker/compose/issues/7873
# See also BUILD_ROOT_PATH sed section at the end of file
echo "BUILD_ROOT_PATH=$(pwd)" >> .env
. ./.env
PARTS_PATH=docker-compose-parts
parts_files(){
for part in $@
do
local file="$PARTS_PATH/$part.yml"
if [ -f "$file" ]
then
echo -n "-f $file "
fi
done
}
merge(){
local flavour="$1"
shift || return 0
local args="$(parts_files $@)"
if [ -n "$*" -a -n "$args" ]
then
if [ -z "$flavour" ]
then
local delimiter=""
else
local delimiter="."
fi
docker-compose $args config > "docker-compose$delimiter$flavour.yml"
fi
}
parts_variant(){
local variant="$1"
shift || return 0
for part in $@
do
echo -n "$part.$variant "
done
}
variants(){
local flavour="$1"
shift || return 0
if [ -z "$flavour" ]
then
local delimiter=""
else
local delimiter="."
fi
merge "$flavour" $@
merge "$flavour${delimiter}build" $@ $(parts_variant build $@)
merge "$flavour${delimiter}devel" $@ $(parts_variant build $@) $(parts_variant devel $@)
}
flavour(){
local flavour="$1"
shift || return 0
local no_stats_parts=""
local parts=""
for part in $@
do
parts="$parts $part"
if [ "$part" = "hypervisor" -a -n "$HYPERVISOR_HOST_TRUNK_INTERFACE" ]
then
parts="$parts hypervisor-vlans"
no_stats_parts="$no_stats_parts hypervisor-vlans"
fi
if [ "$part" != "stats" ]
then
no_stats_parts="$no_stats_parts $part"
fi
done
if [ -n "$no_stats_parts" -a "$no_stats_parts" != " network" ]
then
if [ -z "$flavour" ]
then
local delimiter=""
else
local delimiter="."
fi
variants "$flavour${delimiter}no-stats" $no_stats_parts
fi
variants "$flavour" $parts
}
## Usage of flavour function
#
# flavour <flavour-name> <part-1> <part-2> ...
# - <flavour-name> is used for the filename: docker-compose.<flavour-name>.yml
# - <part-1> and <part-2> ... shoud be files like docker-compose-parts/<part-1>.yml
# - variants build and devel sould be like docker-compose-parts/<part-1>.build.yml
# and docker-compose-parts/<part-1>.devel.yml
#
flavour "" \
network \
db \
engine \
static \
portal \
hypervisor \
websockify \
squid \
webapp \
grafana \
stats \
api \
backend \
vpn \
flavour hypervisor \
network \
video \
hypervisor \
websockify \
squid \
stats \
vpnc \
flavour toolbox \
network \
toolbox \
flavour hypervisor-standalone \
network \
hypervisor \
hypervisor-standalone \
stats \
vpnc \
flavour video-standalone \
network \
video \
websockify \
squid \
stats \
flavour web \
network \
db \
engine \
static \
portal \
webapp \
grafana \
stats \
api \
backend \
flavour stats \
network \
stats \
## BUILD_ROOT_PATH sed section
# Fix the context parameter in the docker-compose file
# See also BUILD_ROOT_PATH env section above
sed -i "s|$(pwd)|.|g" docker-compose*.yml
echo "You have the docker-compose files. Have fun!"
echo "You can download the prebuild images and bring it up:"
echo " docker-compose pull && docker-compose up -d"
echo "Or build it yourself:"
echo " docker-compose build && docker-compose up -d"