This commit is contained in:
2025-05-23 09:33:05 +04:00
parent a16ac8f627
commit 79d66e4b6b
34 changed files with 603 additions and 608 deletions

View File

@@ -0,0 +1,25 @@
#!/bin/bash
set -e
# Change to the script's directory to ensure relative paths work
cd "$(dirname "$0")"
echo "Building PostgreSQL Builder for Linux on AMD64..."
# Create build directory if it doesn't exist
mkdir -p build
# Build the PostgreSQL builder
echo "Building PostgreSQL builder..."
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-s -w" \
-trimpath \
-o build/postgresql_builder \
../cmd/main.go
# Set executable permissions
chmod +x build/postgresql_builder
# Output binary info
echo "Build complete!"
ls -lh build/

View File

@@ -0,0 +1,27 @@
package main
import (
"fmt"
"os"
"github.com/freeflowuniverse/heroagent/pkg/system/builders/postgresql"
)
func main() {
// Create a new PostgreSQL builder with default settings
builder := postgresql.NewBuilder()
// Build PostgreSQL
if err := builder.Build(); err != nil {
fmt.Fprintf(os.Stderr, "Error building PostgreSQL: %v\n", err)
os.Exit(1) // Ensure we exit with non-zero status on error
}
// Run PostgreSQL in screen
if err := builder.PostgresBuilder.RunPostgresInScreen(); err != nil {
fmt.Fprintf(os.Stderr, "Error running PostgreSQL in screen: %v\n", err)
os.Exit(1) // Ensure we exit with non-zero status on error
}
fmt.Println("PostgreSQL build completed successfully!")
}

View File

@@ -0,0 +1,93 @@
#!/bin/bash
set -e
export SERVER="65.109.18.183"
LOG_FILE="postgresql_deployment_$(date +%Y%m%d_%H%M%S).log"
cd "$(dirname "$0")"
# Configure logging
log() {
local timestamp=$(date +"%Y-%m-%d %H:%M:%S")
echo "[$timestamp] $1" | tee -a "$LOG_FILE"
}
log "=== Starting PostgreSQL Builder Deployment ==="
log "Log file: $LOG_FILE"
# Check if SERVER environment variable is set
if [ -z "$SERVER" ]; then
log "Error: SERVER environment variable is not set."
log "Please set it to the IPv4 or IPv6 address of the target server."
log "Example: export SERVER=192.168.1.100"
exit 1
fi
# Validate if SERVER is a valid IP address (IPv4 or IPv6)
if ! [[ "$SERVER" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] && \
! [[ "$SERVER" =~ ^[0-9a-fA-F:]+$ ]]; then
log "Error: SERVER must be a valid IPv4 or IPv6 address."
exit 1
fi
log "Using server: $SERVER"
# Build the PostgreSQL builder binary
log "Building PostgreSQL builder binary..."
./build.sh | tee -a "$LOG_FILE"
# Check if binary exists
if [ ! -f "build/postgresql_builder" ]; then
log "Error: PostgreSQL builder binary not found after build."
exit 1
fi
log "Binary size:"
ls -lh build/ | tee -a "$LOG_FILE"
# Create deployment directory on server
log "Creating deployment directory on server..."
ssh "root@$SERVER" "mkdir -p ~/postgresql_builder" 2>&1 | tee -a "$LOG_FILE"
# Transfer the binary to the server
log "Transferring PostgreSQL builder binary to server..."
rsync -avz --progress build/postgresql_builder "root@$SERVER:~/postgresql_builder/" 2>&1 | tee -a "$LOG_FILE"
# Run the PostgreSQL builder on the server
log "Running PostgreSQL builder on server..."
ssh -t "root@$SERVER" "cd ~/postgresql_builder && ./postgresql_builder" 2>&1 | tee -a "$LOG_FILE"
BUILD_EXIT_CODE=${PIPESTATUS[0]}
# If there was an error, make it very clear
if [ $BUILD_EXIT_CODE -ne 0 ]; then
log "⚠️ PostgreSQL builder failed with exit code: $BUILD_EXIT_CODE"
fi
# Check for errors in exit code
if [ $BUILD_EXIT_CODE -eq 0 ]; then
log "✅ SUCCESS: PostgreSQL builder completed successfully!"
log "----------------------------------------------------------------"
# Note: Verification is now handled by the builder itself
# Check for build logs or error messages
log "Checking for build logs on server..."
BUILD_LOGS=$(ssh "root@$SERVER" "cd ~/postgresql_builder && ls -la *.log 2>/dev/null || echo 'No log files found'" 2>&1)
log "Build log files:"
echo "$BUILD_LOGS" | tee -a "$LOG_FILE"
log "----------------------------------------------------------------"
log "🎉 PostgreSQL Builder deployment COMPLETED"
log "================================================================"
else
log "❌ ERROR: PostgreSQL builder failed to run properly on the server."
# Get more detailed error information
# log "Checking for error logs on server..."
# ssh "root@$SERVER" "cd ~/postgresql_builder && ls -la" 2>&1 | tee -a "$LOG_FILE"
exit 1
fi
log "=== Deployment Completed ==="