#!/bin/bash ############################################################################# # CF Deployer - Chunked Upload Deployment Script # # This script deploys a Java application to Cloud Foundry using chunked # uploads to bypass nginx size restrictions and async deployment to avoid # timeout issues. # # Usage: # ./deploy-chunked.sh # # Configuration: # Edit the variables below to match your environment ############################################################################# set -e # Exit on error ############################################################################# # CONFIGURATION - Update these values for your deployment ############################################################################# # API endpoint API_BASE="http://localhost:8080/api/cf" # Files to deploy JAR_FILE="./app.jar" MANIFEST_FILE="./manifest.yml" # Chunk size (bytes) # Recommended: 1MB (1048576) for Tanzu with memory constraints # Options: 512KB (524288), 1MB (1048576), 2MB (2097152), 5MB (5242880) CHUNK_SIZE=1048576 # 1MB # Cloud Foundry configuration CF_API_ENDPOINT="https://api.cf.example.com" CF_USERNAME="your-username" CF_PASSWORD="your-password" CF_ORGANIZATION="your-org" CF_SPACE="your-space" CF_APP_NAME="your-app" CF_SKIP_SSL="false" # Use "true" for self-signed certificates # Polling configuration POLL_INTERVAL=5 # seconds between status checks MAX_WAIT=600 # maximum wait time in seconds (10 minutes) ############################################################################# # SCRIPT - Do not modify below this line ############################################################################# # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Helper functions log_info() { echo -e "${BLUE}[INFO]${NC} $1" } log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } # Check if files exist if [ ! -f "$JAR_FILE" ]; then log_error "JAR file not found: $JAR_FILE" exit 1 fi if [ ! -f "$MANIFEST_FILE" ]; then log_error "Manifest file not found: $MANIFEST_FILE" exit 1 fi # Check if curl is available if ! command -v curl &> /dev/null; then log_error "curl is not installed. Please install curl to use this script." exit 1 fi # Build CF configuration JSON CF_CONFIG=$(cat </dev/null) if [ $? -ne 0 ]; then log_warning "Failed to fetch status, retrying..." continue fi CURRENT_STATUS=$(echo "$STATUS_RESPONSE" | grep -o '"status":"[^"]*' | cut -d'"' -f4) MESSAGE=$(echo "$STATUS_RESPONSE" | grep -o '"message":"[^"]*' | cut -d'"' -f4) PROGRESS=$(echo "$STATUS_RESPONSE" | grep -o '"progress":[0-9]*' | cut -d':' -f2) # Only print if message changed to reduce clutter if [ "$MESSAGE" != "$last_message" ]; then printf " [%3ds] Status: %-15s Progress: %3s%% - %s\n" \ "$elapsed" "$CURRENT_STATUS" "${PROGRESS:-0}" "$MESSAGE" last_message="$MESSAGE" fi # Check if deployment completed if [ "$CURRENT_STATUS" = "COMPLETED" ]; then echo "" log_success "Deployment completed successfully!" echo "" log_info "Deployment details:" echo "$STATUS_RESPONSE" | python -m json.tool 2>/dev/null || echo "$STATUS_RESPONSE" exit 0 fi # Check if deployment failed if [ "$CURRENT_STATUS" = "FAILED" ]; then echo "" log_error "Deployment failed!" echo "" log_info "Error details:" echo "$STATUS_RESPONSE" | python -m json.tool 2>/dev/null || echo "$STATUS_RESPONSE" exit 1 fi done # Timeout reached echo "" log_warning "Deployment timeout reached after ${MAX_WAIT}s" log_info "The deployment may still be running. Check status manually:" echo " curl $API_BASE/deployment/status/$SESSION_ID" exit 1