#!/bin/bash # # Creates a clean deployment bundle of the project in a specified local directory. # # This script is designed to be run from the root of the project directory. # It uses rsync with a "whitelist" of files and directories to ensure only # artifacts required for deployment are included in the bundle. # # Usage: # ./tools/create-deployment-bundle.sh [DESTINATION_PATH] # # If DESTINATION_PATH is not provided, it defaults to /opt/yt-ops-deploys/yt-ops-services. set -e # Exit immediately if a command exits with a non-zero status. set -u # Treat unset variables as an error. # --- Configuration --- # The root directory of the project on the local machine. SOURCE_DIR="." # Default destination for the deployment bundle. Can be overridden by the first argument. DEFAULT_DEST_DIR="/opt/yt-ops-deploys/yt-ops-services" DEST_DIR="${1:-$DEFAULT_DEST_DIR}" # --- rsync command --- echo ">>> Creating deployment bundle from '$SOURCE_DIR' to '$DEST_DIR'..." # Ensure the parent directory of the destination exists. # This requires sudo if the user doesn't have permissions for the parent path. if [ ! -d "$(dirname "$DEST_DIR")" ]; then echo "Parent directory of destination does not exist. Attempting to create with sudo..." sudo mkdir -p "$(dirname "$DEST_DIR")" sudo chown "$USER" "$(dirname "$DEST_DIR")" fi # Create a temporary file to list the files to be included. # This is a "whitelist" approach, ensuring only necessary files are bundled. # This list is generated by analyzing the Ansible playbooks to determine # exactly which files and directories are required for deployment. INCLUDE_FILE=$(mktemp) EXCLUDE_FILE=$(mktemp) trap 'rm -f -- "$INCLUDE_FILE" "$EXCLUDE_FILE"' EXIT # Define files and directories to exclude from the bundle. cat > "$EXCLUDE_FILE" < "$INCLUDE_FILE" <>> Deployment bundle created successfully at '$DEST_DIR'."