161 lines
4.4 KiB
Bash
Executable file
161 lines
4.4 KiB
Bash
Executable file
#!/bin/bash
|
|
# Build native binaries for Incus deployment (without Docker)
|
|
# Usage: ./build-native.sh [service-name]
|
|
# If no service specified, builds all services
|
|
|
|
set -e
|
|
|
|
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
BUILD_DIR="${PROJECT_ROOT}/.build/incus"
|
|
SERVICE="${1:-all}"
|
|
|
|
# Colors
|
|
GREEN='\033[0;32m'
|
|
BLUE='\033[0;34m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m'
|
|
|
|
echo -e "${BLUE}🔨 Building native binaries for Incus deployment...${NC}"
|
|
|
|
mkdir -p "${BUILD_DIR}"
|
|
|
|
build_backend_api() {
|
|
echo -e "${BLUE}Building backend-api (Go)...${NC}"
|
|
cd "${PROJECT_ROOT}/veza-backend-api"
|
|
|
|
# Check if Go modules are downloaded
|
|
if [ ! -f "go.sum" ]; then
|
|
echo -e "${YELLOW}Downloading Go modules...${NC}"
|
|
go mod download
|
|
fi
|
|
|
|
# Build Go binary
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
|
-ldflags="-w -s" \
|
|
-o "${BUILD_DIR}/veza-backend-api" \
|
|
./cmd/modern-server/main.go
|
|
|
|
if [ ! -f "${BUILD_DIR}/veza-backend-api" ]; then
|
|
echo -e "${RED}❌ Failed to build backend-api${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✅ backend-api built${NC}"
|
|
}
|
|
|
|
build_chat_server() {
|
|
echo -e "${BLUE}Building chat-server (Rust)...${NC}"
|
|
cd "${PROJECT_ROOT}/veza-chat-server"
|
|
|
|
# Build Rust binary (release mode)
|
|
if cargo build --release --target x86_64-unknown-linux-gnu 2>/dev/null; then
|
|
BINARY_PATH="target/x86_64-unknown-linux-gnu/release/chat-server"
|
|
else
|
|
echo -e "${YELLOW}Cross-compilation not available, using native build...${NC}"
|
|
cargo build --release
|
|
BINARY_PATH="target/release/chat-server"
|
|
fi
|
|
|
|
# Copy binary
|
|
if [ -f "${BINARY_PATH}" ]; then
|
|
cp "${BINARY_PATH}" "${BUILD_DIR}/veza-chat-server"
|
|
else
|
|
echo -e "${RED}❌ Failed to build chat-server: binary not found${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f "${BUILD_DIR}/veza-chat-server" ]; then
|
|
echo -e "${RED}❌ Failed to copy chat-server binary${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✅ chat-server built${NC}"
|
|
}
|
|
|
|
build_stream_server() {
|
|
echo -e "${BLUE}Building stream-server (Rust)...${NC}"
|
|
cd "${PROJECT_ROOT}/veza-stream-server"
|
|
|
|
# Build Rust binary (release mode)
|
|
if cargo build --release --target x86_64-unknown-linux-gnu 2>/dev/null; then
|
|
BINARY_PATH="target/x86_64-unknown-linux-gnu/release/stream_server"
|
|
else
|
|
echo -e "${YELLOW}Cross-compilation not available, using native build...${NC}"
|
|
cargo build --release
|
|
BINARY_PATH="target/release/stream_server"
|
|
fi
|
|
|
|
# Copy binary
|
|
if [ -f "${BINARY_PATH}" ]; then
|
|
cp "${BINARY_PATH}" "${BUILD_DIR}/veza-stream-server"
|
|
else
|
|
echo -e "${RED}❌ Failed to build stream-server: binary not found${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f "${BUILD_DIR}/veza-stream-server" ]; then
|
|
echo -e "${RED}❌ Failed to copy stream-server binary${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✅ stream-server built${NC}"
|
|
}
|
|
|
|
build_web() {
|
|
echo -e "${BLUE}Building web frontend (Node.js)...${NC}"
|
|
cd "${PROJECT_ROOT}/apps/web"
|
|
|
|
# Install dependencies if needed
|
|
if [ ! -d "node_modules" ]; then
|
|
echo -e "${YELLOW}Installing npm dependencies...${NC}"
|
|
npm install --silent
|
|
fi
|
|
|
|
# Build frontend
|
|
npm run build
|
|
|
|
# Check if build succeeded
|
|
if [ ! -d "dist" ]; then
|
|
echo -e "${RED}❌ Failed to build web frontend: dist directory not found${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Copy build output
|
|
mkdir -p "${BUILD_DIR}/web"
|
|
cp -r dist/* "${BUILD_DIR}/web/"
|
|
|
|
if [ ! -f "${BUILD_DIR}/web/index.html" ]; then
|
|
echo -e "${RED}❌ Failed to copy web frontend files${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✅ web frontend built${NC}"
|
|
}
|
|
|
|
case "${SERVICE}" in
|
|
backend-api)
|
|
build_backend_api
|
|
;;
|
|
chat-server)
|
|
build_chat_server
|
|
;;
|
|
stream-server)
|
|
build_stream_server
|
|
;;
|
|
web)
|
|
build_web
|
|
;;
|
|
all)
|
|
build_backend_api
|
|
build_chat_server
|
|
build_stream_server
|
|
build_web
|
|
echo -e "${GREEN}✅ All services built successfully!${NC}"
|
|
echo -e "${BLUE}Build artifacts are in: ${BUILD_DIR}${NC}"
|
|
;;
|
|
*)
|
|
echo -e "${YELLOW}Unknown service: ${SERVICE}${NC}"
|
|
echo "Available services: backend-api, chat-server, stream-server, web, all"
|
|
exit 1
|
|
;;
|
|
esac
|