forked from open-edge-platform/edge-ai-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·274 lines (229 loc) · 8.82 KB
/
build.sh
File metadata and controls
executable file
·274 lines (229 loc) · 8.82 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/bin/bash
# Build script for microservice dependencies and sample application backend/UI
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
export REGISTRY_URL=${REGISTRY_URL:-}
export PROJECT_NAME=${PROJECT_NAME:-}
export TAG=${TAG:-latest}
[[ -n "$REGISTRY_URL" ]] && REGISTRY_URL="${REGISTRY_URL%/}/"
[[ -n "$PROJECT_NAME" ]] && PROJECT_NAME="${PROJECT_NAME%/}/"
REGISTRY="${REGISTRY_URL}${PROJECT_NAME}"
export REGISTRY="${REGISTRY:-}"
# Display info about the registry being used
if [ -z "$REGISTRY" ]; then
echo -e "${YELLOW}Warning: No registry prefix set. Images will be tagged without a registry prefix.${NC}"
echo "Using local image names with tag: ${TAG}"
else
echo "Using registry prefix: ${REGISTRY}"
fi
# Usage information
show_usage() {
echo -e "Usage: $0 [OPTION]"
echo -e " --dependencies\t Build sample application dependencies (vdms-dataprep, multimodal-embedding, vlm-openvino-serving, audio-analyzer)"
echo -e " --help, -h\t\t Show this help message"
echo -e " --push\t Push all built Docker images to the registry"
echo -e " <no option>\t Build sample application services (video-ingestion, pipeline-manager, search-ms, and UI)"
echo -e ""
}
# Logging functions
log_info() {
local message="$1"
echo -e "$(date '+%Y-%m-%d %H:%M:%S') - $message" | tee -a "${LOG_FILE:-/dev/null}"
}
# Function to build docker image with proxy support
docker_build() {
local build_args=""
# Add proxy settings if they exist in the environment
if [ -n "$http_proxy" ]; then
build_args="$build_args --build-arg http_proxy=$http_proxy"
fi
if [ -n "$https_proxy" ]; then
build_args="$build_args --build-arg https_proxy=$https_proxy"
fi
if [ -n "$no_proxy" ]; then
build_args="$build_args --build-arg no_proxy=$no_proxy"
fi
# Add copyleft sources build arg if environment variable is set
if [ "$ADD_COPYLEFT_SOURCES" = "true" ]; then
build_args="$build_args --build-arg COPYLEFT_SOURCES=true"
fi
# Execute docker build with all arguments
docker build $build_args "$@"
}
# ================================================================================
# Build microservice dependencies
# ================================================================================
build_dependencies() {
log_info "Building microservice dependencies..."
# Save current directory
local current_dir=$(pwd)
local uservices_dir="${current_dir}/../../microservices"
local build_success=true
# Build DATAPREP (generates required multimodal embedding wheel internally)
local vdms_dir="${uservices_dir}/visual-data-preparation-for-retrieval/vdms"
if [ -x "${vdms_dir}/build.sh" ]; then
log_info "Running vdms build.sh to build vdms-dataprep image..."
if ! (cd "${vdms_dir}" && ./build.sh); then
log_info "${RED}Failed to build vdms-dataprep via build.sh${NC}"
build_success=false
fi
else
log_info "${YELLOW}vdms build.sh not found or not executable${NC}"
build_success=false
fi
# Check if the directory exists first
cd "${uservices_dir}/multimodal-embedding-serving/docker" || return
if [ -f "compose.yaml" ]; then
cd .. && docker_build -t ${REGISTRY}multimodal-embedding-serving:${TAG} -f docker/Dockerfile . || {
log_info "${RED}Failed to build multimodal embedding serving${NC}";
build_success=false;
}
else
log_info "${YELLOW}compose.yml not found for multimodal embedding serving${NC}";
fi
# Build vlm-openvino-serving
cd "${uservices_dir}/vlm-openvino-serving/docker" || return 0
if [ -f "compose.yaml" ]; then
cd .. && docker_build -t ${REGISTRY}vlm-openvino-serving:${TAG} -f docker/Dockerfile . || {
log_info "${RED}Failed to build vlm-openvino-serving${NC}";
build_success=false;
}
else
log_info "${YELLOW}compose.yaml not found for vlm-openvino-serving ${NC}";
fi
# Build audio analyzer microservice
cd "${uservices_dir}/audio-analyzer/docker" || return 1
if [ -f "compose.yaml" ]; then
cd .. && docker_build -t ${REGISTRY}audio-analyzer:${TAG} -f docker/Dockerfile . || {
log_info "${RED}Failed to build audio-analyzer microservice${NC}";
build_success=false;
}
fi
# Return to original directory
cd "$current_dir"
if [ "$build_success" = true ]; then
log_info "${GREEN}All dependencies built successfully${NC}"
# Print built images
log_info "${GREEN}Built images:${NC}"
echo "Retrieving Docker images related to microservice dependencies..."
docker images | grep -E "${REGISTRY}.*(vdms|multimodal|vlm|audio).*${TAG}"
return 0
else
log_info "${YELLOW}Some dependencies failed to build. Check logs for details.${NC}"
return 1
fi
}
# ================================================================================
# Build sample application Backend and UI
# ================================================================================
build_sample_app() {
log_info "Building sample application services..."
# Save current directory
local current_dir=$(pwd)
local build_success=true
# Build video ingestion microservice
cd "${current_dir}/video-ingestion/docker" || return 0
if [ -f "compose.yaml" ]; then
cd .. && docker_build -t ${REGISTRY}video-ingestion:${TAG} -f docker/Dockerfile . || {
log_info "${RED}Failed to build video-ingestion microservice${NC}";
build_success=false;
}
fi
# Build pipeline-manager backend service
cd "${current_dir}/pipeline-manager" || return 0
if [ -f "Dockerfile" ]; then
log_info "Building pipeline-manager service..."
docker_build -t "${REGISTRY}pipeline-manager:${TAG}" . || {
log_info "${RED}Failed to build pipeline-manager service${NC}";
build_success=false;
}
else
log_info "${YELLOW}Dockerfile not found for pipeline-manager service${NC}";
fi
# Build video search backend service
cd "${current_dir}/search-ms" || return 0
if [ -f "docker/Dockerfile" ]; then
log_info "Building search-ms service..."
docker_build -t "${REGISTRY}video-search:${TAG}" -f docker/Dockerfile . || {
log_info "${RED}Failed to build search-ms service${NC}";
build_success=false;
}
else
log_info "${YELLOW}Dockerfile not found for search-ms service${NC}";
fi
# Build UI service
cd "${current_dir}/ui/react" || return 0
if [ -f "Dockerfile" ]; then
log_info "Building UI service..."
docker_build -t "${REGISTRY}vss-ui:${TAG}" . || {
log_info "${RED}Failed to build UI service${NC}";
build_success=false;
}
else
log_info "${YELLOW}Dockerfile not found for UI service${NC}";
fi
# Return to original directory
cd "$current_dir"
if [ "$build_success" = true ]; then
log_info "${GREEN}All sample application services built successfully${NC}"
# Print built images
log_info "${GREEN}Built sample application images:${NC}"
echo "Retrieving Docker images related to sample applications..."
docker images | grep -E "${REGISTRY}.*(vss-ui|video-search|pipeline-manager|video-ingestion).*$TAG"
return 0
else
log_info "${YELLOW}Some sample application services failed to build. Check logs for details.${NC}"
return 1
fi
}
# ================================================================================
# Push all built Docker images to the registry
# ================================================================================
push_images() {
log_info "Pushing Docker images to registry..."
# Save current directory
local current_dir=$(pwd)
local push_success=true
# Get list of dependency images to push
log_info "Pushing dependency images..."
dependency_images=$(docker images | grep -E "${REGISTRY}.*(vdms|multimodal|vlm|audio).*${TAG}" | awk '{print $1":"$2}')
# Push dependency images
for image in $dependency_images; do
log_info "Pushing $image..."
docker push $image || {
log_info "${RED}Failed to push $image${NC}";
push_success=false;
}
done
# Push sample application images
log_info "Pushing sample application images..."
app_images=$(docker images | grep -E "${REGISTRY}.*(pipeline-manager|video-search|video-ingestion|vss-ui).*${TAG}" | awk '{print $1":"$2}')
for image in $app_images; do
log_info "Pushing $image..."
docker push $image || {
log_info "${RED}Failed to push $image${NC}";
push_success=false;
}
done
if [ "$push_success" = true ]; then
log_info "${GREEN}All images pushed successfully${NC}"
return 0
else
log_info "${YELLOW}Some images failed to push. Check logs for details.${NC}"
return 1
fi
}
# ================================================================================
# Parse command line arguments
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
show_usage
elif [ "$1" == "--dependencies" ]; then
build_dependencies
elif [ "$1" == "--push" ]; then
push_images
else
build_sample_app
fi