fetch_ml/scripts/build/build-go.sh
Jeremie Fraeys cb142213fa
chore(build): update build system, Dockerfiles, and dependencies
Build and deployment improvements:

Makefile:
- Native library build targets with ASan support
- Cross-platform compilation helpers
- Performance benchmark targets
- Security scan integration

Docker:
- secure-prod.Dockerfile: Hardened production image (non-root, minimal surface)
- simple.Dockerfile: Lightweight development image

Scripts:
- build/: Go and native library build scripts, cross-platform builds
- ci/: checks.sh, test.sh, verify-paths.sh for validation
- benchmarks/: Local performance testing and regression tracking
- dev/: Monitoring setup

Dependencies: Update to latest stable with security patches

Commands:
- api-server/main.go: Server initialization updates
- data_manager/data_sync.go: Data sync with visibility
- errors/main.go: Error handling improvements
- tui/: TUI improvements for group management
2026-03-08 13:03:48 -04:00

44 lines
1,011 B
Bash
Executable file

#!/bin/bash
# Builds Go binaries with configurable CGO/native options
# Usage: build-go.sh <build_type> <os> <arch> <source_path>
set -euo pipefail
BUILD_TYPE=${1:-native}
OS=${2:-linux}
ARCH=${3:-amd64}
SOURCE_PATH=${4:-cmd/api-server/main.go}
LDFLAGS="-s -w -X main.BuildHash=$(git rev-parse --short HEAD) -X main.BuildTime=$(date -u +%Y%m%d.%H%M%S)"
case $BUILD_TYPE in
pure)
export CGO_ENABLED=0
TAGS=""
SUFFIX="_${OS}_${ARCH}_pure"
;;
cgo)
export CGO_ENABLED=1
TAGS=""
SUFFIX="_${OS}_${ARCH}_cgo"
;;
native)
export CGO_ENABLED=1
TAGS="native_libs"
SUFFIX="_${OS}_${ARCH}_native"
;;
*)
echo "Unknown build type: $BUILD_TYPE"
echo "Usage: $0 <pure|cgo|native> <os> <arch> <source_path>"
exit 1
;;
esac
BINARY_NAME=$(basename "$SOURCE_PATH" .go)
OUTPUT="dist/fetch_ml_${BINARY_NAME}_${OS}_${ARCH}${SUFFIX}"
mkdir -p dist
echo "Building ${BINARY_NAME} (${BUILD_TYPE}) for ${OS}/${ARCH}..."
go build -tags="$TAGS" -ldflags="$LDFLAGS" -o "$OUTPUT" "$SOURCE_PATH"
echo "✓ Built: $OUTPUT"