mirror of
https://github.com/rustfs/rustfs.git
synced 2026-01-17 01:30:33 +00:00
* feat: implement Docker improvements and binary build scripts This commit transforms the RustFS Docker build system to follow MinIO's best practices: ## 🏗️ Binary Build Script (build-rustfs.sh) - Create independent binary compilation script for multi-platform builds - Support x86_64 and aarch64 Linux musl targets - Include checksum generation and optional binary signing - Support cross-compilation and upload functionality - Automated target installation and environment setup ## 🐳 Docker Improvements - Rewrite Dockerfiles to download precompiled binaries instead of building from source - Follow MinIO's approach for security and binary verification - Add comprehensive LABEL metadata (version, build-date, vcs-ref) - Implement proper environment variable management - Add signature verification with minisign (commented for future use) - Include static curl download for minimal runtime dependencies ## 🚀 Enhanced Build Script (docker-buildx.sh) - Inspired by MinIO's docker-buildx.sh for consistency and reliability - Support multiple platforms with proper build arguments - Auto-detect git versions and pass metadata to containers - Improved error messages with helpful troubleshooting hints - Cleanup and cache management between builds ## 🛠️ Supporting Scripts - scripts/download-static-curl.sh: Download statically compiled curl - scripts/setup-test-binaries.sh: Create test binaries for local development ## 📋 Key Benefits - Faster Docker builds (download vs compile) - Better security with signature verification - Consistent with industry standards (MinIO approach) - Proper multi-platform support - Enhanced metadata and traceability - Independent binary distribution capability * feat: update Docker files to use Aliyun OSS for binary downloads * feat: merge stash with OSS binary download improvements - Remove old build_rustfs.sh script - Keep Aliyun OSS download URLs for binary retrieval - Maintain Docker build improvements from stash - Resolve merge conflicts between stash and OSS updates * feat: improve build-rustfs.sh with auto platform detection - Auto-detect current platform using uname (like old build_rustfs.sh) - Default to building for current platform only - Add --all-platforms flag for cross-compilation to Linux musl targets - Support macOS (darwin) and Linux platforms - Auto-enable cross compilation when needed - Provide better usage examples and platform detection info This makes the script much more user-friendly by default while maintaining flexibility for cross-compilation scenarios. * refactor: simplify build-rustfs.sh for CI/CD pipeline usage - Remove cross-compilation complexity (each CI runner builds natively) - Focus on single platform builds per runner - Remove --all-platforms and --cross options - Simplify to match CI/CD workflow where: * Linux x86_64 runner builds Linux x86_64 binary * Linux ARM64 runner builds Linux ARM64 binary * macOS x86_64 runner builds macOS x86_64 binary * macOS ARM64 runner builds macOS ARM64 binary - Keep signing and upload functionality for release CI - Make the script's purpose and usage clearer This aligns with the user's understanding that build scripts should focus on native compilation for the current platform only. * feat: update download server domain to dl.rustfs.com - Update Dockerfile to use dl.rustfs.com/dev/ for development binaries - Update Dockerfile.release to use dl.rustfs.com/release/ for release binaries - Update docker-buildx.sh error messages with new URLs - Update build-rustfs.sh upload target to dl.rustfs.com - Update test scripts to reference new domain - Clean up remaining git conflict markers This centralizes all binary downloads through the official dl.rustfs.com domain instead of direct OSS access. * fix: correct dl.rustfs.com path structure to include /artifacts/rustfs/ - Update all download URLs to use correct path structure: * Dev: https://dl.rustfs.com/artifacts/rustfs/dev/ * Release: https://dl.rustfs.com/artifacts/rustfs/release/ - Test confirmed both paths return HTTP 200 with application/zip content-type - Update Dockerfile, Dockerfile.release, docker-buildx.sh, and build-rustfs.sh - Update test scripts with correct base path The dl.rustfs.com domain requires the /artifacts/rustfs/ prefix to access the binary files correctly. * feat: refactor Dockerfile to download binaries from GitHub Releases - Changed binary download source from dl.rustfs.com to GitHub Releases - Added support for latest release auto-detection via GitHub API - Enhanced error handling with detailed messages and helpful links - Added optional checksum verification using SHA256SUMS - Improved architecture support for amd64 and arm64 - Removed unnecessary minisign installation - Added jq dependency for JSON parsing * feat: consolidate Docker build to use single Dockerfile - Removed Dockerfile.release and use unified Dockerfile instead - Updated docker-buildx.sh to use single Dockerfile with build args - Both latest and release variants now use GitHub Releases - Simplified build process and reduced maintenance overhead - Updated error messages to point to GitHub releases * chore: remove unused Dockerfile.obs - Removed Dockerfile.obs as it's no longer needed - Simplified Docker build configuration * feat: unify Docker prebuild variants to use GitHub Releases - Updated .docker/alpine/Dockerfile.prebuild to download from GitHub Releases - Updated .docker/ubuntu/Dockerfile.prebuild to download from GitHub Releases - All prebuild variants now consistently use GitHub Releases as binary source - Added checksum verification for all prebuild variants - Updated .docker/README.md to reflect unified GitHub Releases approach - Improved error handling and user guidance in all prebuild Dockerfiles * feat: major Docker structure simplification and consolidation ## 🎯 Simplified Docker Structure Moved from complex multi-directory structure to clean root-level organization: ### Before: - Dockerfile (production) - .docker/alpine/Dockerfile.prebuild (duplicate) - .docker/alpine/Dockerfile.source - .docker/ubuntu/Dockerfile.prebuild (duplicate) - .docker/ubuntu/Dockerfile.source - .docker/ubuntu/Dockerfile.dev ### After: - Dockerfile (production - Alpine + GitHub Releases) - Dockerfile.source (source build - Ubuntu + cross-compilation) - Dockerfile.dev (development - Ubuntu + full toolchain) ## 🔧 Key Changes - **Eliminated Duplicates**: Removed redundant prebuild variants - **Moved Core Files**: Dockerfile.{source,dev} now in root directory - **Unified Configuration**: cargo.config.toml moved to root - **Updated References**: Fixed all GitHub Actions and docker-compose paths - **Simplified CI Matrix**: Reduced from 5 to 3 Docker variants ## 📦 Preserved Valuable Diversity - **Production**: Alpine-based for minimal size - **Source**: Ubuntu-based with cross-compilation support - **Development**: Ubuntu-based with full development tools ## 🚀 Benefits - ✅ Cleaner project structure - ✅ Easier maintenance and navigation - ✅ Reduced CI/CD complexity - ✅ Faster build matrix execution - ✅ Maintained functionality and flexibility * chore: remove duplicate cargo.config.toml from .docker directory The file is now in the root directory and no longer needed in .docker/ * fix: update all references to removed Dockerfile files - Updated .docker/compose/README.md to reference Dockerfile.source instead of Dockerfile.obs - Updated docker-compose.yml to use Dockerfile.source instead of Dockerfile.dev - Updated scripts/build-docker-multiarch.sh to use Dockerfile.source for devenv builds - Updated .github/workflows/docker.yml to use Dockerfile.source for dev builds - Updated Makefile to use Dockerfile.source for init-devenv target - Updated .docker/README.md to remove references to non-existent Dockerfile.dev - Ensured all Docker configurations consistently use the unified Dockerfile structure * chore: remove unnecessary console static assets download - Remove obsolete download steps from build.yml and performance.yml - Console static assets are already embedded via rust-embed in rustfs/static/ - The download from dl.rustfs.com is no longer needed as project contains complete console assets - This improves build reliability and reduces external dependencies - Replaced with verification steps that confirm embedded assets are present * feat: update Makefile and README.md for new Docker build system - Updated Makefile to use unified Docker build system: - Replace references to non-existent Dockerfile.ubuntu22.04 and Dockerfile.rockylinux9.3 - Add new docker-buildx targets using docker-buildx.sh script - Deprecate old docker-build-multiarch targets with warnings - Add docker-build-production and docker-build-source targets - Update help-docker with new command structure - Updated README.md with docker-buildx.sh usage: - Add comprehensive Docker build from source section - Document multi-architecture build capabilities - Include both script and Make target examples - Show registry flexibility and build optimization features - Update step numbers in quickstart guide - Improve developer experience with clear documentation and updated tooling - Maintain backward compatibility with deprecation warnings * feat: integrate console assets download into build-rustfs.sh - Added console download functionality to build-rustfs.sh: - New flags: --download-console, --force-console-update, --console-version - Intelligent detection of existing console assets - Retry logic with fallback error handling - Consistent with Docker build asset management - Updated scripts to use unified build process: - scripts/static.sh: Now uses build-rustfs.sh for console downloads - scripts/run.sh: Uses build-rustfs.sh instead of direct curl - scripts/run.ps1: Updated with guidance for Windows users - Benefits: - Unified asset management across all build processes - Consistent version handling and retry logic - Eliminates duplicate download logic - Better error handling and user feedback - Preparation for CI/CD integration - Removed unused download-static-curl.sh script This change centralizes console asset management and prepares for streamlined CI/CD processes where build-rustfs.sh becomes the single point of truth for binary and asset builds. * fix: update PowerShell script to use unified console asset management - Updated scripts/run.ps1 to use build-rustfs.sh for console asset downloads - Added guidance for Windows users to use the unified build script - Maintains consistency across all platform-specific scripts * feat: add binary verification to build script - Add verify_binary function to test built binaries - Test --help and --version commands - Verify binary structure with readelf/otool - Add --skip-verification option for cross-compilation - Include verification status in build output - Automatic error handling if verification fails * feat: add platform selection support to build script - Add --platform parameter to build-rustfs.sh for target platform selection - Implement cross-compilation support with automatic 'cross' tool detection - Auto-enable --skip-verification for cross-compilation scenarios - Update all Makefile build targets to use unified build-rustfs.sh script - Add helpful error messages and suggestions for cross-compilation failures - Update help documentation with platform selection examples - Improve build consistency across different architectures * feat: modernize CI/CD build process with build-rustfs.sh - Replace manual cargo build commands with unified build-rustfs.sh script - Simplify matrix configuration by removing cross-compilation flags - Ensure consistency between local and CI/CD builds - Automatic cross-compilation tool detection and installation - Built-in binary verification for quality assurance - Unified console asset management - Better error handling and suggestions Benefits: - Consistent build process across all environments - Automatic detection and handling of cross-compilation scenarios - Built-in quality checks with binary verification - Reduced CI/CD configuration complexity - Better maintainability with single source of truth for build logic * feat: optimize CI/CD workspace path management - Add WORKSPACE_DIR environment variable to cache github.workspace - Set default working-directory at job level for consistency - Use explicit workspace paths in critical operations - Improve reliability and maintainability of CI/CD paths - Ensure consistent behavior across different GitHub Actions environments Benefits: - More explicit and reliable path handling - Better maintainability with centralized workspace reference - Reduced risk of path-related issues in CI/CD - Consistent working directory across all job steps * refactor: simplify CI/CD path management - remove redundant workspace references - Remove unnecessary WORKSPACE_DIR environment variable - Remove redundant defaults.run.working-directory setting - Use relative paths since GITHUB_WORKSPACE is the default working directory - Follow GitHub Actions best practices by leveraging default behavior As per GitHub Actions documentation, GITHUB_WORKSPACE is already the default working directory, so explicit specification is unnecessary in most cases. * docs: update Docker README to reflect current project state - Fix directory structure: remove non-existent nginx/ directory - Correct base OS: Dockerfile.source uses Debian Bookworm, not Ubuntu 22.04 - Add docker-buildx.sh script documentation - Update Docker tag examples to match actual CI/CD workflows - Add CI/CD integration section explaining automated builds - Document build variants and manual build options - Reflect current project architecture and tooling These updates ensure the documentation accurately represents the current Docker build system and CI/CD workflows. * fix: update Docker command in rustfs README - Replace quay.io registry with Docker Hub (rustfs/rustfs:latest) - Remove separate console port 9001, console now runs on main port 9000 - Add both Docker and Podman examples for user choice - Fix console access URL to use unified port This aligns with the recent console port consolidation changes and the project's move to Docker Hub as the primary registry. * wip * fix: remove unnecessary entrypoint.sh and fix Docker paths * Update Dockerfile Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * cleanup: remove unused DOCKERFILE_PATH variable from Makefile * feat: update Docker build to use dl.rustfs.com for binary downloads - Replace GitHub releases download with dl.rustfs.com - Add CHANNEL parameter support (release/dev) - Update docker-buildx.sh to support channel-specific builds - Improve error messages with new download URLs - Support both latest and specific version downloads - Add channel validation in build script --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
489 lines
16 KiB
Bash
Executable File
489 lines
16 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# RustFS Binary Build Script
|
|
# This script compiles RustFS binaries for different platforms and architectures
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Auto-detect current platform
|
|
detect_platform() {
|
|
local arch=$(uname -m)
|
|
local os=$(uname -s | tr '[:upper:]' '[:lower:]')
|
|
|
|
case "$os" in
|
|
"linux")
|
|
case "$arch" in
|
|
"x86_64")
|
|
echo "x86_64-unknown-linux-musl"
|
|
;;
|
|
"aarch64"|"arm64")
|
|
echo "aarch64-unknown-linux-musl"
|
|
;;
|
|
"armv7l")
|
|
echo "armv7-unknown-linux-musleabihf"
|
|
;;
|
|
*)
|
|
echo "unknown-platform"
|
|
;;
|
|
esac
|
|
;;
|
|
"darwin")
|
|
case "$arch" in
|
|
"x86_64")
|
|
echo "x86_64-apple-darwin"
|
|
;;
|
|
"arm64"|"aarch64")
|
|
echo "aarch64-apple-darwin"
|
|
;;
|
|
*)
|
|
echo "unknown-platform"
|
|
;;
|
|
esac
|
|
;;
|
|
*)
|
|
echo "unknown-platform"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Default values
|
|
OUTPUT_DIR="target/release"
|
|
PLATFORM=$(detect_platform) # Auto-detect current platform
|
|
BINARY_NAME="rustfs"
|
|
BUILD_TYPE="release"
|
|
SIGN=false
|
|
WITH_CONSOLE=true
|
|
FORCE_CONSOLE_UPDATE=false
|
|
CONSOLE_VERSION="latest"
|
|
SKIP_VERIFICATION=false
|
|
CUSTOM_PLATFORM=""
|
|
|
|
# Print usage
|
|
usage() {
|
|
echo "Usage: $0 [OPTIONS]"
|
|
echo ""
|
|
echo "Description:"
|
|
echo " Build RustFS binary for the current platform. Designed for CI/CD pipelines"
|
|
echo " where different runners build platform-specific binaries natively."
|
|
echo " Includes automatic verification to ensure the built binary is functional."
|
|
echo ""
|
|
echo "Options:"
|
|
echo " -o, --output-dir DIR Output directory (default: target/release)"
|
|
echo " -b, --binary-name NAME Binary name (default: rustfs)"
|
|
echo " -p, --platform TARGET Target platform (default: auto-detect)"
|
|
echo " --dev Build in dev mode"
|
|
echo " --sign Sign binaries after build"
|
|
echo " --with-console Download console static assets (default)"
|
|
echo " --no-console Skip console static assets"
|
|
echo " --force-console-update Force update console assets even if they exist"
|
|
echo " --console-version VERSION Console version to download (default: latest)"
|
|
echo " --skip-verification Skip binary verification after build"
|
|
echo " -h, --help Show this help message"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " $0 # Build for current platform (includes console assets)"
|
|
echo " $0 --dev # Development build"
|
|
echo " $0 --sign # Build and sign binary (release CI)"
|
|
echo " $0 --no-console # Build without console static assets"
|
|
echo " $0 --force-console-update # Force update console assets"
|
|
echo " $0 --platform x86_64-unknown-linux-musl # Build for specific platform"
|
|
echo " $0 --skip-verification # Skip binary verification (for cross-compilation)"
|
|
echo ""
|
|
echo "Detected platform: $(detect_platform)"
|
|
echo "CI Usage: Run this script on each platform's runner to build native binaries"
|
|
}
|
|
|
|
# Print colored message
|
|
print_message() {
|
|
local color=$1
|
|
local message=$2
|
|
echo -e "${color}${message}${NC}"
|
|
}
|
|
|
|
# Get version from git
|
|
get_version() {
|
|
if git describe --abbrev=0 --tags >/dev/null 2>&1; then
|
|
git describe --abbrev=0 --tags
|
|
else
|
|
git rev-parse --short HEAD
|
|
fi
|
|
}
|
|
|
|
# Setup rust environment
|
|
setup_rust_environment() {
|
|
print_message $BLUE "🔧 Setting up Rust environment..."
|
|
|
|
# Install required target for current platform
|
|
print_message $YELLOW "Installing target: $PLATFORM"
|
|
rustup target add "$PLATFORM"
|
|
|
|
# Install required tools
|
|
if [ "$SIGN" = true ]; then
|
|
if ! command -v minisign &> /dev/null; then
|
|
print_message $YELLOW "Installing minisign for binary signing..."
|
|
cargo install minisign
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Download console static assets
|
|
download_console_assets() {
|
|
local static_dir="rustfs/static"
|
|
local console_exists=false
|
|
|
|
# Check if console assets already exist
|
|
if [ -d "$static_dir" ] && [ -f "$static_dir/index.html" ]; then
|
|
console_exists=true
|
|
local static_size=$(du -sh "$static_dir" 2>/dev/null | cut -f1 || echo "unknown")
|
|
print_message $YELLOW "Console static assets already exist ($static_size)"
|
|
fi
|
|
|
|
# Determine if we need to download
|
|
local should_download=false
|
|
if [ "$WITH_CONSOLE" = true ]; then
|
|
if [ "$console_exists" = false ]; then
|
|
print_message $BLUE "🎨 Console assets not found, downloading..."
|
|
should_download=true
|
|
elif [ "$FORCE_CONSOLE_UPDATE" = true ]; then
|
|
print_message $BLUE "🎨 Force updating console assets..."
|
|
should_download=true
|
|
else
|
|
print_message $GREEN "✅ Console assets already available, skipping download"
|
|
fi
|
|
else
|
|
if [ "$console_exists" = true ]; then
|
|
print_message $GREEN "✅ Using existing console assets"
|
|
else
|
|
print_message $YELLOW "⚠️ Console assets not found. Use --download-console to download them."
|
|
fi
|
|
fi
|
|
|
|
if [ "$should_download" = true ]; then
|
|
print_message $BLUE "📥 Downloading console static assets..."
|
|
|
|
# Create static directory
|
|
mkdir -p "$static_dir"
|
|
|
|
# Download from GitHub Releases (consistent with Docker build)
|
|
local download_url
|
|
if [ "$CONSOLE_VERSION" = "latest" ]; then
|
|
print_message $YELLOW "Getting latest console release info..."
|
|
# For now, use dl.rustfs.com as fallback until GitHub Releases includes console assets
|
|
download_url="https://dl.rustfs.com/artifacts/console/rustfs-console-latest.zip"
|
|
else
|
|
download_url="https://dl.rustfs.com/artifacts/console/rustfs-console-${CONSOLE_VERSION}.zip"
|
|
fi
|
|
|
|
print_message $YELLOW "Downloading from: $download_url"
|
|
|
|
# Download with retries
|
|
local temp_file="console-assets-temp.zip"
|
|
local download_success=false
|
|
|
|
for i in {1..3}; do
|
|
if curl -L "$download_url" -o "$temp_file" --retry 3 --retry-delay 5 --max-time 300; then
|
|
download_success=true
|
|
break
|
|
else
|
|
print_message $YELLOW "Download attempt $i failed, retrying..."
|
|
sleep 2
|
|
fi
|
|
done
|
|
|
|
if [ "$download_success" = true ]; then
|
|
# Verify the downloaded file
|
|
if [ -f "$temp_file" ] && [ -s "$temp_file" ]; then
|
|
print_message $BLUE "📦 Extracting console assets..."
|
|
|
|
# Extract to static directory
|
|
if unzip -o "$temp_file" -d "$static_dir"; then
|
|
rm "$temp_file"
|
|
local final_size=$(du -sh "$static_dir" 2>/dev/null | cut -f1 || echo "unknown")
|
|
print_message $GREEN "✅ Console assets downloaded successfully ($final_size)"
|
|
else
|
|
print_message $RED "❌ Failed to extract console assets"
|
|
rm -f "$temp_file"
|
|
return 1
|
|
fi
|
|
else
|
|
print_message $RED "❌ Downloaded file is empty or invalid"
|
|
rm -f "$temp_file"
|
|
return 1
|
|
fi
|
|
else
|
|
print_message $RED "❌ Failed to download console assets after 3 attempts"
|
|
print_message $YELLOW "💡 Console assets are optional. Build will continue without them."
|
|
rm -f "$temp_file"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Verify binary functionality
|
|
verify_binary() {
|
|
local binary_path="$1"
|
|
|
|
# Check if binary exists
|
|
if [ ! -f "$binary_path" ]; then
|
|
print_message $RED "❌ Binary file not found: $binary_path"
|
|
return 1
|
|
fi
|
|
|
|
# Check if binary is executable
|
|
if [ ! -x "$binary_path" ]; then
|
|
print_message $RED "❌ Binary is not executable: $binary_path"
|
|
return 1
|
|
fi
|
|
|
|
# Check basic functionality - try to run help command
|
|
print_message $YELLOW " Testing --help command..."
|
|
if ! "$binary_path" --help >/dev/null 2>&1; then
|
|
print_message $RED "❌ Binary failed to run --help command"
|
|
return 1
|
|
fi
|
|
|
|
# Check version command
|
|
print_message $YELLOW " Testing --version command..."
|
|
if ! "$binary_path" --version >/dev/null 2>&1; then
|
|
print_message $YELLOW "⚠️ Binary does not support --version command (this is optional)"
|
|
fi
|
|
|
|
# Try to get some basic info about the binary
|
|
local file_info=$(file "$binary_path" 2>/dev/null || echo "unknown")
|
|
print_message $YELLOW " Binary info: $file_info"
|
|
|
|
# Check if it's a valid ELF/Mach-O binary
|
|
if command -v readelf >/dev/null 2>&1; then
|
|
if readelf -h "$binary_path" >/dev/null 2>&1; then
|
|
print_message $YELLOW " ELF binary structure: valid"
|
|
fi
|
|
elif command -v otool >/dev/null 2>&1; then
|
|
if otool -h "$binary_path" >/dev/null 2>&1; then
|
|
print_message $YELLOW " Mach-O binary structure: valid"
|
|
fi
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
# Build binary for current platform
|
|
build_binary() {
|
|
local version=$(get_version)
|
|
local output_file="${OUTPUT_DIR}/${PLATFORM}/${BINARY_NAME}"
|
|
|
|
print_message $BLUE "🏗️ Building for platform: $PLATFORM"
|
|
print_message $YELLOW " Version: $version"
|
|
print_message $YELLOW " Output: $output_file"
|
|
|
|
# Create output directory
|
|
mkdir -p "${OUTPUT_DIR}/${PLATFORM}"
|
|
|
|
# Build command - use cross for cross-compilation if needed
|
|
local build_cmd="cargo build"
|
|
local current_platform=$(detect_platform)
|
|
|
|
# Check if we need cross-compilation
|
|
if [ "$PLATFORM" != "$current_platform" ]; then
|
|
# Check if cross is available
|
|
if command -v cross &> /dev/null; then
|
|
build_cmd="cross build"
|
|
print_message $YELLOW "🔄 Cross-compilation detected, using 'cross' tool"
|
|
else
|
|
print_message $YELLOW "⚠️ Cross-compilation detected but 'cross' tool not found"
|
|
print_message $YELLOW "📦 Installing cross tool..."
|
|
cargo install cross --git https://github.com/cross-rs/cross
|
|
build_cmd="cross build"
|
|
fi
|
|
fi
|
|
|
|
if [ "$BUILD_TYPE" = "release" ]; then
|
|
build_cmd+=" --release"
|
|
fi
|
|
|
|
build_cmd+=" --target $PLATFORM"
|
|
build_cmd+=" --bin $BINARY_NAME"
|
|
|
|
print_message $BLUE "📦 Executing: $build_cmd"
|
|
|
|
# Execute build
|
|
if eval $build_cmd; then
|
|
print_message $GREEN "✅ Successfully built for $PLATFORM"
|
|
|
|
# Copy binary to output directory
|
|
cp "target/${PLATFORM}/${BUILD_TYPE}/${BINARY_NAME}" "$output_file"
|
|
|
|
# Generate checksums
|
|
print_message $BLUE "🔐 Generating checksums..."
|
|
(cd "${OUTPUT_DIR}/${PLATFORM}" && sha256sum "${BINARY_NAME}" > "${BINARY_NAME}.sha256sum")
|
|
|
|
# Verify binary functionality (if not skipped)
|
|
if [ "$SKIP_VERIFICATION" = false ]; then
|
|
print_message $BLUE "🔍 Verifying binary functionality..."
|
|
if verify_binary "$output_file"; then
|
|
print_message $GREEN "✅ Binary verification passed"
|
|
else
|
|
print_message $RED "❌ Binary verification failed"
|
|
return 1
|
|
fi
|
|
else
|
|
print_message $YELLOW "⚠️ Binary verification skipped by user request"
|
|
fi
|
|
|
|
# Sign binary if requested
|
|
if [ "$SIGN" = true ]; then
|
|
print_message $BLUE "✍️ Signing binary..."
|
|
(cd "${OUTPUT_DIR}/${PLATFORM}" && minisign -S -m "${BINARY_NAME}" -s ~/.minisign/minisign.key)
|
|
fi
|
|
|
|
print_message $GREEN "✅ Build completed successfully"
|
|
else
|
|
print_message $RED "❌ Failed to build for $PLATFORM"
|
|
|
|
# Provide helpful suggestions for cross-compilation failures
|
|
if [ "$PLATFORM" != "$(detect_platform)" ]; then
|
|
print_message $YELLOW "💡 Cross-compilation suggestions:"
|
|
print_message $YELLOW " 1. Use Docker build: make build-docker"
|
|
print_message $YELLOW " 2. Use GitHub Actions for multi-platform builds"
|
|
print_message $YELLOW " 3. Build natively on the target platform"
|
|
print_message $YELLOW " 4. Use 'make docker-buildx' for multi-arch Docker images"
|
|
fi
|
|
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
|
|
|
|
# Main build function
|
|
build_rustfs() {
|
|
local version=$(get_version)
|
|
|
|
print_message $BLUE "🚀 Starting RustFS binary build process..."
|
|
print_message $YELLOW " Version: $version"
|
|
print_message $YELLOW " Platform: $PLATFORM"
|
|
print_message $YELLOW " Output Directory: $OUTPUT_DIR"
|
|
print_message $YELLOW " Build Type: $BUILD_TYPE"
|
|
print_message $YELLOW " Sign: $SIGN"
|
|
print_message $YELLOW " With Console: $WITH_CONSOLE"
|
|
if [ "$WITH_CONSOLE" = true ]; then
|
|
print_message $YELLOW " Console Version: $CONSOLE_VERSION"
|
|
print_message $YELLOW " Force Console Update: $FORCE_CONSOLE_UPDATE"
|
|
fi
|
|
print_message $YELLOW " Skip Verification: $SKIP_VERIFICATION"
|
|
echo ""
|
|
|
|
# Setup environment
|
|
setup_rust_environment
|
|
echo ""
|
|
|
|
# Download console assets if requested
|
|
download_console_assets
|
|
echo ""
|
|
|
|
# Build binary
|
|
build_binary
|
|
echo ""
|
|
|
|
print_message $GREEN "🎉 Build process completed successfully!"
|
|
|
|
# Show built binary
|
|
local binary_file="${OUTPUT_DIR}/${PLATFORM}/${BINARY_NAME}"
|
|
if [ -f "$binary_file" ]; then
|
|
local size=$(ls -lh "$binary_file" | awk '{print $5}')
|
|
print_message $BLUE "📋 Built binary: $binary_file ($size)"
|
|
fi
|
|
}
|
|
|
|
# Parse command line arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-o|--output-dir)
|
|
OUTPUT_DIR="$2"
|
|
shift 2
|
|
;;
|
|
-b|--binary-name)
|
|
BINARY_NAME="$2"
|
|
shift 2
|
|
;;
|
|
-p|--platform)
|
|
CUSTOM_PLATFORM="$2"
|
|
shift 2
|
|
;;
|
|
--dev)
|
|
BUILD_TYPE="debug"
|
|
shift
|
|
;;
|
|
--sign)
|
|
SIGN=true
|
|
shift
|
|
;;
|
|
--with-console)
|
|
WITH_CONSOLE=true
|
|
shift
|
|
;;
|
|
--no-console)
|
|
WITH_CONSOLE=false
|
|
shift
|
|
;;
|
|
--force-console-update)
|
|
FORCE_CONSOLE_UPDATE=true
|
|
WITH_CONSOLE=true # Auto-enable download when forcing update
|
|
shift
|
|
;;
|
|
--console-version)
|
|
CONSOLE_VERSION="$2"
|
|
shift 2
|
|
;;
|
|
--skip-verification)
|
|
SKIP_VERIFICATION=true
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
print_message $RED "❌ Unknown option: $1"
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Main execution
|
|
main() {
|
|
print_message $BLUE "🦀 RustFS Binary Build Script"
|
|
echo ""
|
|
|
|
# Check if we're in a Rust project
|
|
if [ ! -f "Cargo.toml" ]; then
|
|
print_message $RED "❌ No Cargo.toml found. Are you in a Rust project directory?"
|
|
exit 1
|
|
fi
|
|
|
|
# Override platform if specified
|
|
if [ -n "$CUSTOM_PLATFORM" ]; then
|
|
PLATFORM="$CUSTOM_PLATFORM"
|
|
print_message $YELLOW "🎯 Using specified platform: $PLATFORM"
|
|
|
|
# Auto-enable skip verification for cross-compilation
|
|
if [ "$PLATFORM" != "$(detect_platform)" ]; then
|
|
SKIP_VERIFICATION=true
|
|
print_message $YELLOW "⚠️ Cross-compilation detected, enabling --skip-verification"
|
|
fi
|
|
fi
|
|
|
|
# Start build process
|
|
build_rustfs
|
|
}
|
|
|
|
# Run main function
|
|
main
|
|
|