forked from smarunich/inference-in-a-box
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-multiarch-images.sh
More file actions
executable file
·157 lines (127 loc) · 4.17 KB
/
Copy pathbuild-multiarch-images.sh
File metadata and controls
executable file
·157 lines (127 loc) · 4.17 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
#!/bin/bash
# Build multi-architecture Docker images for Management API and UI
# This script builds both containers for AMD64 and ARM64 and pushes them to Google Artifact Registry
set -e
# Configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
REGISTRY="us-east1-docker.pkg.dev/dogfood-cx/registryrepository"
TAG="${TAG:-latest}"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Helper functions
print_step() {
echo -e "${BLUE}==== $1 ====${NC}"
}
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_error() {
echo -e "${RED}✗ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠ $1${NC}"
}
# Check if Docker is available
check_docker() {
if ! command -v docker &> /dev/null; then
print_error "Docker is required but not installed"
exit 1
fi
if ! docker info &> /dev/null; then
print_error "Docker daemon is not running"
exit 1
fi
# Check if buildx is available
if ! docker buildx version &> /dev/null; then
print_error "Docker buildx is required for multi-arch builds"
exit 1
fi
# Create/use buildx builder for multi-arch
if ! docker buildx ls | grep -q "multi-arch-builder"; then
print_step "Creating multi-arch builder"
docker buildx create --name multi-arch-builder --driver docker-container --use
docker buildx inspect --bootstrap
else
print_step "Using existing multi-arch builder"
docker buildx use multi-arch-builder
fi
}
# Configure Docker for Google Artifact Registry
configure_docker() {
print_step "Configuring Docker for Google Artifact Registry"
# Check if gcloud is available
if ! command -v gcloud &> /dev/null; then
print_error "gcloud CLI is required but not installed"
exit 1
fi
# Configure Docker auth
gcloud auth configure-docker us-east1-docker.pkg.dev
print_success "Docker configured for Artifact Registry"
}
# Build Management Service Docker image (consolidated)
build_management_service() {
print_step "Building Management Service Docker image (multi-arch)"
# Build multi-architecture image
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t "$REGISTRY/management-service:$TAG" \
--push \
"$PROJECT_ROOT/management/"
print_success "Management Service multi-arch image built and pushed"
}
# Show image information
show_image_info() {
print_step "Image Information"
echo "Built multi-arch images:"
echo " Management Service: $REGISTRY/management-service:$TAG"
echo -e "\nArchitectures: linux/amd64, linux/arm64"
echo -e "\nTo deploy using these images:"
echo "kubectl apply -f $PROJECT_ROOT/configs/management/management-registry.yaml"
echo -e "\nTo inspect multi-arch manifest:"
echo "docker buildx imagetools inspect $REGISTRY/management-service:$TAG"
}
# Main execution
main() {
echo -e "${BLUE}Build Multi-Architecture Docker Images${NC}"
echo -e "${BLUE}=====================================${NC}"
check_docker
configure_docker
build_management_service
show_image_info
print_success "Multi-arch Docker images built and pushed successfully!"
}
# Handle script interruption
trap 'echo -e "\n${YELLOW}Build interrupted${NC}"; exit 1' INT
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--tag)
TAG="$2"
shift 2
;;
--registry)
REGISTRY="$2"
shift 2
;;
--help)
echo "Usage: $0 [options]"
echo "Options:"
echo " --tag TAG Docker image tag (default: latest)"
echo " --registry REG Docker registry (default: us-east1-docker.pkg.dev/dogfood-cx/registryrepository)"
echo " --help Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Run the build and push
main