#!/bin/bash # Parallel Cloudron Application Processor set -e # Configuration WORKSPACE_DIR="/home/localuser/TSYSDevStack/Cloudron/CloudronPackages-Workspace" ARTIFACTS_DIR="/home/localuser/TSYSDevStack/Cloudron/CloudronPackages-Artifacts" MAX_PARALLEL=5 # Process 5 apps at once # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # Logging log_info() { echo -e "${BLUE}[INFO]${NC} $1"; } log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; } log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; } log_error() { echo -e "${RED}[ERROR]${NC} $1"; } # Process single application process_app() { local app_dir="$1" local app_name=$(basename "$app_dir") log_info "Processing $app_name" # Skip if already processed if [ -d "$app_dir/app" ] && [ -f "$app_dir/app/manifest.json" ]; then log_warning "$app_name already has Cloudron package, skipping" return 0 fi # Detect application type local app_type="unknown" if [ -f "$app_dir/package.json" ]; then app_type="nodejs" elif [ -f "$app_dir/go.mod" ]; then app_type="golang" elif [ -f "$app_dir/requirements.txt" ] || [ -f "$app_dir/setup.py" ] || [ -f "$app_dir/pyproject.toml" ]; then app_type="python" elif [ -f "$app_dir/Cargo.toml" ]; then app_type="rust" elif [ -f "$app_dir/pom.xml" ] || [ -f "$app_dir/build.gradle" ]; then app_type="java" elif [ -f "$app_dir/Gemfile" ] || [ -f "$app_dir/Gemfile.lock" ]; then app_type="ruby" elif [ -f "$app_dir/composer.json" ]; then app_type="php" fi log_info "Detected $app_name as $app_type" # Create Cloudron package structure mkdir -p "$app_dir/app" # Create manifest cat > "$app_dir/app/manifest.json" << EOF { "id": "com.$app_name.cloudron", "title": "$app_name", "version": "1.0.0", "description": "Auto-generated Cloudron package for $app_name", "developer": { "name": "TSYSDevStack Team", "email": "support@tsysdevstack.com" }, "tags": ["productivity", "web-app"], "httpPort": 8080, "manifestVersion": 2, "healthCheck": { "path": "/", "port": 8080 } } EOF # Create Dockerfile based on type case "$app_type" in "nodejs") cat > "$app_dir/app/Dockerfile" << 'EOF' FROM node:18-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --only=production && npm cache clean --force COPY . . EXPOSE 8080 CMD ["npm", "start"] EOF ;; "golang") cat > "$app_dir/app/Dockerfile" << 'EOF' FROM golang:1.21-alpine AS builder WORKDIR /app COPY go.mod go.sum ./ RUN go mod download && go mod verify COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o main . FROM alpine:latest RUN apk --no-cache add ca-certificates tzdata WORKDIR /root/ COPY --from=builder /app/main . RUN chmod +x main EXPOSE 8080 CMD ["./main"] EOF ;; "python") cat > "$app_dir/app/Dockerfile" << 'EOF' FROM python:3.11-alpine WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . EXPOSE 8080 CMD ["python", "app.py"] EOF ;; *) cat > "$app_dir/app/Dockerfile" << 'EOF' FROM alpine:latest RUN apk --no-cache add ca-certificates WORKDIR /app COPY . . EXPOSE 8080 CMD ["./start.sh"] EOF ;; esac # Create start script for unknown types if [ "$app_type" = "unknown" ]; then cat > "$app_dir/app/start.sh" << 'EOF' #!/bin/sh echo "Starting application..." # Add your startup command here exec "$@" EOF chmod +x "$app_dir/app/start.sh" fi # Commit changes cd "$app_dir" git add app/ 2>/dev/null || true if ! git diff --staged --quiet; then git config user.email "support@tsysdevstack.com" git config user.name "TSYSDevStack Team" git commit -m "Add Cloudron package for $app_name Type: $app_type Generated: $(date) " log_success "Committed Cloudron package for $app_name" else log_warning "No changes to commit for $app_name" fi # Update status echo "$(date '+%Y-%m-%d %H:%M:%S')|$app_name|completed|$app_type" >> "$ARTIFACTS_DIR/processing_status.log" log_success "Completed $app_name ($app_type)" } # Export function for parallel execution export -f process_app export -f log_info export -f log_success export -f log_warning export -f log_error # Main processing main() { log_info "Starting parallel processing of applications" # Create artifacts directory mkdir -p "$ARTIFACTS_DIR" # Initialize status log echo "timestamp|app_name|status|app_type" > "$ARTIFACTS_DIR/processing_status.log" # Find all application directories local apps=() for dir in "$WORKSPACE_DIR"/*; do if [ -d "$dir" ] && [ "$(basename "$dir")" != "goalert" ]; then # Skip goalert as it's already done apps+=("$dir") fi done log_info "Found ${#apps[@]} applications to process" # Process apps in parallel batches local batch_size=$MAX_PARALLEL local total=${#apps[@]} local processed=0 for (( i=0; i