Skip to content

Instantly share code, notes, and snippets.

@rwunsch
Created March 31, 2025 18:07
Show Gist options
  • Select an option

  • Save rwunsch/bb9943536f5e79099b87fdc92c17813a to your computer and use it in GitHub Desktop.

Select an option

Save rwunsch/bb9943536f5e79099b87fdc92c17813a to your computer and use it in GitHub Desktop.
Deeploy to Adobe AEM Cloud Services (AEMaaCS) Rapid Development Environments (RDEs) - Shelly Script
#!/bin/bash
# ============================================================================
# AEM RDE Deployment Script
# ============================================================================
# This script automates the deployment of AEM packages to a Rapid Development
# Environment (RDE) using the Adobe I/O CLI.
#
# Usage:
# ./deploy-to-rde.sh [options]
#
# Options:
# -o, --org-id ID Adobe Organization ID (required if not configured)
# -p, --program-id ID Cloud Manager Program ID (default: 127553)
# -e, --env-id ID Environment ID (default: 1584902)
# -a, --all-package PATH Path to the 'all' package (default: all/target/*.zip)
# -d, --disp-package PATH Path to the dispatcher package (default: dispatcher/target/*.zip)
# -s, --skip-disp Skip dispatcher package deployment
# -r, --reset Reset RDE before deployment
# -v, --verbose Show verbose output
# -D, --debug Enable debug mode with maximum information
# -h, --help Show this help message
#
# Examples:
# ./deploy-to-rde.sh --program-id 127553 --env-id 1584902
# ./deploy-to-rde.sh --all-package path/to/custom/package.zip --skip-disp
# ./deploy-to-rde.sh --reset
# ./deploy-to-rde.sh --debug
# ============================================================================
# Default values
PROGRAM_ID=127553
ENVIRONMENT_ID=1584902
ALL_PACKAGE_PATH="all/target/*.zip"
DISP_PACKAGE_PATH="dispatcher/target/*.zip"
SKIP_DISPATCHER=false
RESET_RDE=false
VERBOSE=false
DEBUG=false
# Text formatting
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NORMAL='\033[0m'
# Function to display help
show_help() {
echo -e "${BOLD}AEM RDE Deployment Script${NORMAL}"
echo
echo "This script automates the deployment of AEM packages to a Rapid Development Environment (RDE)."
echo
echo -e "${BOLD}Usage:${NORMAL}"
echo " ./deploy-to-rde.sh [options]"
echo
echo -e "${BOLD}Options:${NORMAL}"
echo " -o, --org-id ID Adobe Organization ID (required if not configured)"
echo " -p, --program-id ID Cloud Manager Program ID (default: $PROGRAM_ID)"
echo " -e, --env-id ID Environment ID (default: $ENVIRONMENT_ID)"
echo " -a, --all-package PATH Path to the 'all' package (default: $ALL_PACKAGE_PATH)"
echo " -d, --disp-package PATH Path to the dispatcher package (default: $DISP_PACKAGE_PATH)"
echo " -s, --skip-disp Skip dispatcher package deployment"
echo " -r, --reset Reset RDE before deployment"
echo " -v, --verbose Show verbose output"
echo " -D, --debug Enable debug mode with maximum information"
echo " -h, --help Show this help message"
echo
echo -e "${BOLD}Examples:${NORMAL}"
echo " ./deploy-to-rde.sh --program-id $PROGRAM_ID --env-id $ENVIRONMENT_ID"
echo " ./deploy-to-rde.sh --all-package path/to/custom/package.zip --skip-disp"
echo " ./deploy-to-rde.sh --reset"
echo " ./deploy-to-rde.sh --debug"
echo
}
# Function to log messages
log() {
local level=$1
local message=$2
case $level in
info)
echo -e "${BLUE}[INFO]${NORMAL} $message"
;;
success)
echo -e "${GREEN}[SUCCESS]${NORMAL} $message"
;;
warning)
echo -e "${YELLOW}[WARNING]${NORMAL} $message"
;;
error)
echo -e "${RED}[ERROR]${NORMAL} $message"
;;
debug)
if [ "$DEBUG" = true ]; then
echo -e "${CYAN}[DEBUG]${NORMAL} $message"
fi
;;
*)
echo -e "$message"
;;
esac
}
# Function to execute command with debug output
execute_cmd() {
local cmd="$1"
local description="$2"
local output_file=$(mktemp)
log debug "Executing: $cmd"
if [ "$DEBUG" = true ] || [ "$VERBOSE" = true ]; then
echo -e "${YELLOW}>> $description${NORMAL}"
echo -e "${YELLOW}>> Command: $cmd${NORMAL}"
eval "$cmd" | tee "$output_file"
exit_code=${PIPESTATUS[0]}
else
eval "$cmd" > "$output_file" 2>&1
exit_code=$?
fi
if [ $exit_code -ne 0 ]; then
log error "$description failed (exit code: $exit_code)"
echo -e "${RED}>> Command output:${NORMAL}"
cat "$output_file"
rm "$output_file"
return $exit_code
fi
log debug "$description completed successfully"
if [ "$DEBUG" = true ] && [ "$VERBOSE" = false ]; then
echo -e "${CYAN}>> Command output:${NORMAL}"
cat "$output_file"
fi
rm "$output_file"
return 0
}
# Function to check if Adobe I/O CLI is installed
check_aio_cli() {
if ! command -v aio &> /dev/null; then
log error "Adobe I/O CLI is not installed. Please install it with: npm install -g @adobe/aio-cli"
exit 1
fi
log debug "Adobe I/O CLI version:"
if [ "$DEBUG" = true ]; then
aio --version
fi
# Check if AEM RDE plugin is installed
log debug "Checking for AEM RDE plugin..."
if ! aio plugins 2>/dev/null | grep -q "@adobe/aio-cli-plugin-aem-rde"; then
log warning "AEM RDE plugin is not installed. Installing now..."
execute_cmd "aio plugins:install @adobe/aio-cli-plugin-aem-rde" "Installing AEM RDE plugin"
else
log info "AEM RDE plugin is already installed."
if [ "$DEBUG" = true ]; then
log debug "Installed plugins:"
aio plugins
fi
fi
}
# Function to check AIO CLI login status
check_login() {
log debug "Checking Adobe I/O CLI login status..."
local context_output=$(aio context 2>&1)
if ! echo "$context_output" | grep -q "Logged in"; then
log info "You are not logged in to Adobe I/O CLI. Let's log in now..."
execute_cmd "aio login" "Logging in to Adobe I/O CLI"
else
log info "Already logged in to Adobe I/O CLI."
if [ "$DEBUG" = true ]; then
log debug "Current context:"
aio context
fi
fi
}
# Function to configure the environment
configure_environment() {
if [ -n "$ORG_ID" ]; then
log info "Setting organization ID: $ORG_ID"
execute_cmd "aio config:set cloudmanager_orgid \"$ORG_ID\"" "Setting organization ID"
fi
log info "Setting program ID: $PROGRAM_ID"
execute_cmd "aio config:set cloudmanager_programid \"$PROGRAM_ID\"" "Setting program ID"
log info "Setting environment ID: $ENVIRONMENT_ID"
execute_cmd "aio config:set cloudmanager_environmentid \"$ENVIRONMENT_ID\"" "Setting environment ID"
if [ "$DEBUG" = true ]; then
log debug "Current AIO configuration:"
aio config
fi
}
# Function to check RDE status
check_rde_status() {
log info "Checking RDE status..."
execute_cmd "aio aem:rde:status" "Checking RDE status"
}
# Function to reset RDE
reset_rde() {
log warning "Resetting RDE environment..."
read -p "Are you sure you want to reset the RDE? This will remove all custom code and content. (y/n): " confirm
if [[ "$confirm" == [yY] || "$confirm" == [yY][eE][sS] ]]; then
execute_cmd "aio aem:rde:reset" "Resetting RDE"
log success "RDE reset completed."
else
log info "RDE reset cancelled."
fi
}
# Function to check if AEM RDE commands are available
check_rde_commands() {
log info "Verifying AEM RDE commands are available..."
# Check if the plugin is installed correctly
log debug "Testing RDE plugin..."
if [ "$DEBUG" = true ]; then
aio aem:rde 2>&1 || echo "Command returned non-zero exit code: $?"
fi
# Check if aem:rde:status command works
log debug "Testing RDE status command..."
if ! aio aem:rde:status 2>/dev/null; then
local exit_code=$?
log warning "AEM RDE commands not working properly (exit code: $exit_code)."
if [ "$DEBUG" = true ]; then
log debug "RDE status command output:"
aio aem:rde:status || echo "Command failed with exit code: $?"
log debug "Plugin details:"
aio plugins || echo "Command failed with exit code: $?"
log debug "Attempting to reinstall plugin..."
aio plugins:uninstall @adobe/aio-cli-plugin-aem-rde || echo "Uninstall failed with exit code: $?"
aio plugins:install @adobe/aio-cli-plugin-aem-rde || echo "Install failed with exit code: $?"
fi
log info "Checking if you need to log in again..."
execute_cmd "aio login" "Logging in to Adobe I/O CLI again"
# Try the command again after login
if ! aio aem:rde:status &>/dev/null; then
log error "AEM RDE plugin is not working properly. Please try the following steps:"
log error "1. Run: npm install -g @adobe/aio-cli@latest"
log error "2. Run: aio plugins:install @adobe/aio-cli-plugin-aem-rde"
log error "3. Run: aio login"
log error "4. Run this script again with --debug flag for more information"
exit 1
fi
fi
log success "AEM RDE commands are available."
}
# Function to deploy packages
deploy_packages() {
# Resolve package paths using glob patterns
ALL_PACKAGE=$(ls $ALL_PACKAGE_PATH 2>/dev/null | head -n 1)
DISP_PACKAGE=$(ls $DISP_PACKAGE_PATH 2>/dev/null | head -n 1)
log debug "Resolved all package path: $ALL_PACKAGE"
log debug "Resolved dispatcher package path: $DISP_PACKAGE"
# Check if all package exists
if [ -z "$ALL_PACKAGE" ] || [ ! -f "$ALL_PACKAGE" ]; then
log error "All package not found at path: $ALL_PACKAGE_PATH"
log warning "Make sure you've built the project with 'mvn clean package'"
exit 1
fi
# Deploy all package
log info "Deploying all package: $ALL_PACKAGE"
execute_cmd "aio aem:rde:install \"$ALL_PACKAGE\"" "Deploying all package"
log success "All package deployment initiated."
# Deploy dispatcher package if not skipped
if [ "$SKIP_DISPATCHER" = false ]; then
if [ -z "$DISP_PACKAGE" ] || [ ! -f "$DISP_PACKAGE" ]; then
log warning "Dispatcher package not found at path: $DISP_PACKAGE_PATH"
log warning "Skipping dispatcher package deployment."
else
log info "Deploying dispatcher package: $DISP_PACKAGE"
execute_cmd "aio aem:rde:install \"$DISP_PACKAGE\"" "Deploying dispatcher package"
log success "Dispatcher package deployment initiated."
fi
else
log info "Skipping dispatcher package deployment as requested."
fi
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-o|--org-id)
ORG_ID="$2"
shift 2
;;
-p|--program-id)
PROGRAM_ID="$2"
shift 2
;;
-e|--env-id)
ENVIRONMENT_ID="$2"
shift 2
;;
-a|--all-package)
ALL_PACKAGE_PATH="$2"
shift 2
;;
-d|--disp-package)
DISP_PACKAGE_PATH="$2"
shift 2
;;
-s|--skip-disp)
SKIP_DISPATCHER=true
shift
;;
-r|--reset)
RESET_RDE=true
shift
;;
-v|--verbose)
VERBOSE=true
shift
;;
-D|--debug)
DEBUG=true
VERBOSE=true # Debug implies verbose
shift
;;
-h|--help)
show_help
exit 0
;;
*)
log error "Unknown option: $1"
show_help
exit 1
;;
esac
done
# Main execution
echo -e "${BOLD}====================================================================${NORMAL}"
echo -e "${BOLD} AEM RDE Deployment Script ${NORMAL}"
echo -e "${BOLD}====================================================================${NORMAL}"
echo
if [ "$DEBUG" = true ]; then
log debug "Debug mode enabled - showing detailed information"
log debug "Running on: $(uname -a)"
log debug "Working directory: $(pwd)"
log debug "Script parameters:"
log debug " PROGRAM_ID=$PROGRAM_ID"
log debug " ENVIRONMENT_ID=$ENVIRONMENT_ID"
log debug " ALL_PACKAGE_PATH=$ALL_PACKAGE_PATH"
log debug " DISP_PACKAGE_PATH=$DISP_PACKAGE_PATH"
log debug " SKIP_DISPATCHER=$SKIP_DISPATCHER"
log debug " RESET_RDE=$RESET_RDE"
log debug " VERBOSE=$VERBOSE"
log debug " DEBUG=$DEBUG"
if [ -n "$ORG_ID" ]; then
log debug " ORG_ID=$ORG_ID"
else
log debug " ORG_ID=<not provided>"
fi
fi
# Check prerequisites
check_aio_cli
check_login
configure_environment
check_rde_commands
check_rde_status
# Reset RDE if requested
if [ "$RESET_RDE" = true ]; then
reset_rde
fi
# Deploy packages
deploy_packages
echo
log success "Deployment process completed."
log info "You can check your deployment status with: aio aem:rde:history"
log info "Access your AEM environment at: https://author-$PROGRAM_ID-$ENVIRONMENT_ID.adobeaemcloud.com"
echo -e "${BOLD}====================================================================${NORMAL}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment