-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-docker.sh
More file actions
executable file
·190 lines (154 loc) · 4.67 KB
/
build-docker.sh
File metadata and controls
executable file
·190 lines (154 loc) · 4.67 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
#!/bin/bash
# Docker-based cross-platform build script for SUSE Observability Integrations Finder
# This script uses Docker containers to build executables for different platforms
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$SCRIPT_DIR"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if Docker is available
check_docker() {
if ! command -v docker &> /dev/null; then
print_error "Docker is not installed or not in PATH"
exit 1
fi
if ! docker info &> /dev/null; then
print_error "Docker is not running or you don't have permissions"
exit 1
fi
}
# Build Docker image for a specific platform
build_docker_image() {
local platform=$1
local arch=$2
print_status "Building Docker image for $platform-$arch..."
cat > "$PROJECT_ROOT/Dockerfile.$platform-$arch" << EOF
FROM python:3.11-slim
# Install system dependencies
RUN apt-get update && apt-get install -y \\
gcc \\
g++ \\
make \\
zip \\
tar \\
gzip \\
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy requirements and install Python dependencies
COPY build_requirements.txt .
RUN pip install --no-cache-dir -r build_requirements.txt
# Copy source code
COPY . .
# Build the executable
RUN python build.py $platform-$arch
# Create output directory
RUN mkdir -p /output
# Copy built executable to output
RUN cp -r dist/* /output/ 2>/dev/null || true
RUN cp -r packages/* /output/ 2>/dev/null || true
# Set output as volume
VOLUME /output
EOF
docker build -f "Dockerfile.$platform-$arch" -t "suse-integrations-finder:$platform-$arch" .
}
# Build executable using Docker
build_executable() {
local platform=$1
local arch=$2
print_status "Building executable for $platform-$arch..."
# Create output directory
mkdir -p "$PROJECT_ROOT/packages"
# Run Docker container
docker run --rm \
-v "$PROJECT_ROOT/packages:/output" \
"suse-integrations-finder:$platform-$arch" \
sh -c "cp -r /output/* . 2>/dev/null || true"
print_status "Build completed for $platform-$arch"
}
# Clean up Docker images
cleanup_docker() {
print_status "Cleaning up Docker images..."
docker rmi $(docker images -q "suse-integrations-finder:*") 2>/dev/null || true
rm -f "$PROJECT_ROOT"/Dockerfile.*
}
# Main build function
main() {
local target=${1:-all}
print_status "Starting Docker-based build for target: $target"
# Check Docker availability
check_docker
# Define targets
declare -A targets=(
["linux-x86_64"]="linux x86_64"
["linux-aarch64"]="linux aarch64"
["macos-x86_64"]="macos x86_64"
["macos-aarch64"]="macos aarch64"
["win-x86_64"]="win x86_64"
)
# Build targets
if [[ "$target" == "all" ]]; then
for target_name in "${!targets[@]}"; do
IFS=' ' read -r platform arch <<< "${targets[$target_name]}"
build_docker_image "$platform" "$arch"
build_executable "$platform" "$arch"
done
elif [[ -n "${targets[$target]}" ]]; then
IFS=' ' read -r platform arch <<< "${targets[$target]}"
build_docker_image "$platform" "$arch"
build_executable "$platform" "$arch"
else
print_error "Unknown target: $target"
echo "Available targets:"
for target_name in "${!targets[@]}"; do
echo " $target_name"
done
echo " all"
exit 1
fi
# Cleanup
cleanup_docker
print_status "All builds completed successfully!"
print_status "Packages are available in: $PROJECT_ROOT/packages/"
}
# Show help
show_help() {
echo "Docker-based build script for SUSE Observability Integrations Finder"
echo ""
echo "Usage: $0 [TARGET]"
echo ""
echo "Targets:"
echo " linux-x86_64 - Build Linux x86_64 executable"
echo " linux-aarch64 - Build Linux aarch64 executable"
echo " macos-x86_64 - Build macOS x86_64 executable"
echo " macos-aarch64 - Build macOS aarch64 executable"
echo " win-x86_64 - Build Windows x86_64 executable"
echo " all - Build for all platforms (default)"
echo ""
echo "Examples:"
echo " $0 linux-x86_64"
echo " $0 all"
}
# Parse command line arguments
case "${1:-}" in
-h|--help)
show_help
exit 0
;;
*)
main "$@"
;;
esac