-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcommon.bash
More file actions
236 lines (206 loc) · 4.54 KB
/
Copy pathcommon.bash
File metadata and controls
236 lines (206 loc) · 4.54 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
parse_opts() {
installcheck_mode=orca
run_mode=icg
stale_orca=false
existential_angst=false
build_mode=opt
local opt
for opt in "$@"; do
case "${opt}" in
--planner | --no-optimizer)
installcheck_mode=planner
;;
--interactive)
run_mode=interactive
;;
--interactive-after-icg)
run_mode=interactive_after_icg
;;
--use-stale-orca)
stale_orca=true
;;
--existential-angst)
existential_angst=true
;;
--enable-debug)
build_mode=debug
;;
esac
done
if [[ "${run_mode}" = interactive && "${installcheck_mode}" = planner ]]; then
printf >&2 -- '--interactive and --no-optimizer are mutually exclusive\n'
return 1
fi
}
container_name() {
local container_id
readonly container_id=$1
docker ps --format '{{.Names}}' --filter id="${container_id}"
}
is_anxious() {
[[ "${DEBUG+x}" = "x" && "${existential_angst:-}" = "true" ]]
}
build_orca() {
if [[ "${stale_orca:-}" = true ]]; then
return 0
fi
local workspace
workspace=$(workspace)
local orca_container_id
orca_container_id=$(
docker run --detach \
--volume gpdbccache:/ccache \
--volume orca:/orca \
--volume "${workspace}":/workspace:ro \
--env CCACHE_DIR=/ccache \
--env CCACHE_UMASK=0000 \
yolo/orcadev:centos5 \
/workspace/bug-free-fortnight/streamline-master/build_orca.bash
)
if is_anxious; then
(
trap "cleanup_container \"${orca_container_id}\"" EXIT
docker attach --sig-proxy=false "${orca_container_id}"
)
else
local orca_build_status
orca_build_status=$(
trap "cleanup_container \"${orca_container_id}\"" INT
docker wait "${orca_container_id}"
)
if [[ "${orca_build_status}" -ne 0 ]]; then
docker logs "${orca_container_id}"
fi
docker rm "${orca_container_id}"
return "${orca_build_status}"
fi
}
build_image() {
local dir
dir=$(dirname "$0")
if is_anxious; then
docker build "${dir}" >&2
fi
docker build -q "${dir}"
}
run_in_container() {
local container_id
local -a path_and_args
readonly container_id=$1
shift
path_and_args=("$@")
docker exec "${container_id}" "${path_and_args[@]}"
}
workspace() {
local -r whereami=$(absdir)
dirname "$(dirname "${whereami}")"
}
absdir() {
(
cd "$(dirname "$0")"
pwd
)
}
set_ccache_max_size() {
local -r cache_size=8G
docker run --rm \
--volume gpdbccache:/ccache \
yolo/gpdbdev:centos6 \
chmod a+rw /ccache
docker run --rm \
--volume gpdbccache:/ccache \
--env CCACHE_DIR=/ccache \
--env CCACHE_UMASK=0000 \
yolo/gpdbdev:centos6 \
ccache -M ${cache_size}
}
relpath_from_workspace() {
local whereami this_dir parent_abspath parent_dir
whereami=$(absdir)
this_dir=$(basename "${whereami}")
parent_abspath=$(dirname "${whereami}")
parent_dir=$(basename "${parent_abspath}")
echo "${parent_dir}"/"${this_dir}"
}
build_gpdb() {
local container_id
readonly container_id=$1
local relpath
readonly relpath=$2
local build_mode
readonly build_mode=$3
local -a build_args=()
if [[ "${build_mode}" == debug ]]; then
build_args+=(
-d
)
fi
local -r path=/workspace/${relpath}/build_gpdb.bash
run_in_container "${container_id}" "${path}" "${build_args[@]+${build_args[@]}}"
}
cleanup_container() {
local container_id
readonly container_id=$1
docker rm --force --volumes "${container_id}"
}
cleanup() {
local container_id
readonly container_id=$1
local repo
readonly repo=$2
local workspace
workspace=$(workspace)
docker cp "${container_id}":/build/gpdb/src/test/regress/regression.diffs "${workspace}"/"${repo}"/src/test/regress || :
cleanup_container "${container_id}"
}
run() {
local container_id
readonly container_id=$1
local relpath
readonly relpath=$2
local run_mode
readonly run_mode=$3
local installcheck_mode
readonly installcheck_mode=$4
case "${run_mode}" in
interactive)
docker exec -ti "${container_id}" /workspace/"${relpath}"/db_shell.bash
return 0
;;
icg)
icg "${container_id}" "${relpath}" "${installcheck_mode}"
;;
interactive_after_icg)
if icg "${container_id}" "${relpath}" "${installcheck_mode}"; then
echo "ICG passed."
true
else
echo "ICG failed: returned status $?"
fi
docker exec -ti "${container_id}" /workspace/"${relpath}"/db_shell.bash
return 0
;;
*)
return 1
;;
esac
}
icg() {
local container_id
readonly container_id=$1
local relpath
readonly relpath=$2
local installcheck_mode
readonly installcheck_mode=$3
case "${installcheck_mode}" in
orca)
run_in_container "${container_id}" /workspace/"${relpath}"/icg.bash
;;
planner)
run_in_container "${container_id}" /workspace/"${relpath}"/icg.bash -m planner
;;
*)
return 1
;;
esac
}