-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathbuild-images.sh
More file actions
226 lines (188 loc) · 5.93 KB
/
Copy pathbuild-images.sh
File metadata and controls
226 lines (188 loc) · 5.93 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
#!/bin/bash
# Docker Build Script for Context-Engine
# Builds all service images with custom registry tagging
set -euo pipefail
# Configuration
REGISTRY="192.168.96.61:30009/library"
PROJECT_NAME="context-engine"
TAG="${TAG:-latest}"
# Service mapping (service_name:dockerfile:final_image_name)
declare -A SERVICES=(
["memory"]="Dockerfile.mcp:${PROJECT_NAME}-memory"
["indexer"]="Dockerfile.mcp-indexer:${PROJECT_NAME}-indexer"
["indexer-service"]="Dockerfile.indexer:${PROJECT_NAME}-indexer-service"
["llamacpp"]="Dockerfile.llamacpp:${PROJECT_NAME}-llamacpp"
)
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Logging functions
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# Build function
build_image() {
local service=$1
local dockerfile=$2
local image_name=$3
local full_image="${REGISTRY}/${image_name}:${TAG}"
log_info "Building ${service} service..."
log_info "Dockerfile: ${dockerfile}"
log_info "Image: ${full_image}"
if ! docker build \
-f "${dockerfile}" \
-t "${full_image}" \
--build-arg BUILDKIT_INLINE_CACHE=1 \
.; then
log_error "Failed to build ${service} image"
return 1
fi
log_info "Successfully built ${service} image: ${full_image}"
# Push if registry is accessible
if [[ "${PUSH_IMAGES:-false}" == "true" ]]; then
log_info "Pushing ${service} image..."
if ! docker push "${full_image}"; then
log_warn "Failed to push ${service} image (registry may be inaccessible)"
return 1
fi
log_info "Successfully pushed ${service} image"
fi
echo "${full_image}"
}
# Main build process
main() {
log_info "Starting Context-Engine Docker build process..."
log_info "Registry: ${REGISTRY}"
log_info "Tag: ${TAG}"
log_info "Push enabled: ${PUSH_IMAGES:-false}"
echo
# Check if Docker is running
if ! docker info >/dev/null 2>&1; then
log_error "Docker is not running or not accessible"
exit 1
fi
# Check if Dockerfiles exist
for service in "${!SERVICES[@]}"; do
IFS=':' read -r dockerfile image_name <<< "${SERVICES[$service]}"
if [[ ! -f "${dockerfile}" ]]; then
log_error "Dockerfile not found: ${dockerfile}"
exit 1
fi
done
local built_images=()
local failed_services=()
# Build each service
for service in "${!SERVICES[@]}"; do
IFS=':' read -r dockerfile image_name <<< "${SERVICES[$service]}"
if built_image=$(build_image "$service" "$dockerfile" "$image_name"); then
built_images+=("$built_image")
else
failed_services+=("$service")
fi
echo
done
# Summary
log_info "Build Summary:"
log_info "Successfully built: ${#built_images[@]} images"
for img in "${built_images[@]}"; do
log_info " ✓ ${img}"
done
if [[ ${#failed_services[@]} -gt 0 ]]; then
log_error "Failed to build: ${#failed_services[@]} services"
for service in "${failed_services[@]}"; do
log_error " ✗ ${service}"
done
exit 1
fi
log_info "All images built successfully!"
# Generate updated kustomization.yaml
cat > "deploy/kubernetes/kustomization-images.yaml" << 'EOF'
# Image overrides for Context-Engine Kubernetes deployment
# Use this with: kustomize build . --load-restrictor=LoadRestrictionsNone | kubectl apply -f -
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- namespace.yaml
- configmap.yaml
- qdrant.yaml
- mcp-memory.yaml
- mcp-indexer.yaml
- mcp-http.yaml
- indexer-services.yaml
- llamacpp.yaml
- ingress.yaml
images:
EOF
# Add images to kustomization
for service in "${!SERVICES[@]}"; do
IFS=':' read -r dockerfile image_name <<< "${SERVICES[$service]}"
full_image="${REGISTRY}/${image_name}:${TAG}"
cat >> "deploy/kubernetes/kustomization-images.yaml" << EOF
- name: ${image_name}
newName: ${full_image%:*} # Remove tag
newTag: ${TAG}
EOF
done
cat >> "deploy/kubernetes/kustomization-images.yaml" << 'EOF'
# Common labels
commonLabels:
app.kubernetes.io/name: context-engine
app.kubernetes.io/component: kubernetes-deployment
app.kubernetes.io/managed-by: kustomize
# Namespace override
namespace: context-engine
EOF
log_info "Generated deploy/kubernetes/kustomization-images.yaml"
log_info "To deploy: kustomize build deploy/kubernetes/ | kubectl apply -f -"
}
# Help function
show_help() {
cat << EOF
Context-Engine Docker Build Script
Usage: $0 [OPTIONS]
Options:
-t, --tag TAG Set image tag (default: latest)
-p, --push Push images to registry after build
-h, --help Show this help message
Examples:
$0 # Build with default tag
$0 -t v1.0.0 # Build with custom tag
$0 --push # Build and push to registry
TAG=dev-branch $0 # Build using environment variable
Environment Variables:
TAG Image tag to use
PUSH_IMAGES Set to 'true' to push after build
Registry Configuration:
Current registry: ${REGISTRY}
To change: modify REGISTRY variable in script
Generated Files:
- deploy/kubernetes/kustomization-images.yaml
Contains image references for Kubernetes deployment
EOF
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-t|--tag)
TAG="$2"
shift 2
;;
-p|--push)
export PUSH_IMAGES=true
shift
;;
-h|--help)
show_help
exit 0
;;
*)
log_error "Unknown option: $1"
show_help
exit 1
;;
esac
done
# Run main function
main "$@"