refactor(db): update cursor rules and enhance deployment rollback script
- Standardized string formatting in cursor rules for consistency. - Added a new rollback deployment script to facilitate blue-green deployment strategy. - Removed outdated seed data files and introduced new rarity mappings for better data management. - Improved model relationships and query optimizations in various views and admin configurations. - Enhanced caching strategies across templates to improve performance and reduce load times, including jitter in cache settings for better performance. - Refactored card-related views and templates to utilize new model fields and relationships.
This commit is contained in:
parent
39a002e394
commit
af2f48a491
37 changed files with 2444 additions and 13565 deletions
98
scripts/rollback-deployment.sh
Executable file
98
scripts/rollback-deployment.sh
Executable file
|
|
@ -0,0 +1,98 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# Rollback deployment by swapping colors
|
||||
# Usage: ./rollback-deployment.sh
|
||||
|
||||
# Source common functions
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "${SCRIPT_DIR}/common-lib.sh"
|
||||
|
||||
validate_deployment_env
|
||||
|
||||
# Get current state
|
||||
STATE=$(get_deployment_state)
|
||||
|
||||
echo "🔍 Current deployment state: $STATE"
|
||||
|
||||
if [ "$STATE" = "none" ]; then
|
||||
echo "❌ No active deployment found to rollback"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$STATE" != "both" ]; then
|
||||
echo "❌ Rollback requires both colors to be running"
|
||||
echo " Current state: only $STATE is running"
|
||||
echo ""
|
||||
echo " To perform a manual rollback:"
|
||||
echo " 1. Find the previous release in ${RELEASES_PATH}/"
|
||||
echo " 2. Update the symlink: ln -sfn <previous-release> ${CURRENT_LINK_PATH}"
|
||||
echo " 3. Redeploy using: ./deploy-blue-green.sh"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Both colors running - determine which is newer
|
||||
CURRENT_COLOR=$(get_current_color)
|
||||
ROLLBACK_COLOR=$(switch_color "$CURRENT_COLOR")
|
||||
|
||||
# Get image tags for both deployments
|
||||
CURRENT_IMAGE=$(get_deployment_image_tag "$CURRENT_COLOR")
|
||||
ROLLBACK_IMAGE=$(get_deployment_image_tag "$ROLLBACK_COLOR")
|
||||
|
||||
echo "🔄 Rolling back from $CURRENT_COLOR (newer) to $ROLLBACK_COLOR (older)"
|
||||
echo " Current image: ${CURRENT_IMAGE}"
|
||||
echo " Rollback image: ${ROLLBACK_IMAGE}"
|
||||
|
||||
# Verify the rollback image exists
|
||||
if ! run_on_target "docker images -q 'badbl0cks/pkmntrade-club:${ROLLBACK_IMAGE}' | grep -q ."; then
|
||||
echo "❌ Rollback image not found: badbl0cks/pkmntrade-club:${ROLLBACK_IMAGE}"
|
||||
echo " The image may have been pruned. Cannot perform rollback."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verify rollback color is healthy
|
||||
ROLLBACK_PROJECT=$(get_project_name "$ROLLBACK_COLOR")
|
||||
HEALTHY_COUNT=$(count_containers "label=com.docker.compose.project=${ROLLBACK_PROJECT} --filter status=running")
|
||||
|
||||
if [ "$HEALTHY_COUNT" -eq 0 ]; then
|
||||
echo "❌ No healthy $ROLLBACK_COLOR containers found, cannot perform rollback"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ Found $HEALTHY_COUNT healthy $ROLLBACK_COLOR containers"
|
||||
|
||||
# Store the release path of the current color before we change the symlink
|
||||
CURRENT_RELEASE_PATH=$(readlink -f "${CURRENT_LINK_PATH}")
|
||||
|
||||
echo "🔄 Performing rollback..."
|
||||
|
||||
echo "🔎 Finding release for rollback color ($ROLLBACK_COLOR)..."
|
||||
# Find the second newest release directory. This is assumed to be the rollback target.
|
||||
ROLLBACK_RELEASE_PATH=$(ls -dt "${RELEASES_PATH}"/*/ | sed -n '2p' | tr -d '\n')
|
||||
|
||||
if [ -z "$ROLLBACK_RELEASE_PATH" ]; then
|
||||
echo "❌ Could not find a previous release to rollback to in ${RELEASES_PATH}"
|
||||
exit 1
|
||||
fi
|
||||
echo " Found rollback release: ${ROLLBACK_RELEASE_PATH}"
|
||||
|
||||
echo "🔗 Switching 'current' symlink to point to rollback release..."
|
||||
ln -sfn "${ROLLBACK_RELEASE_PATH}" "${CURRENT_LINK_PATH}"
|
||||
|
||||
# Refresh gatekeepers to switch traffic to the rollback color
|
||||
refresh_gatekeepers
|
||||
|
||||
wait_with_countdown 10 "⏳ Waiting for traffic to stabilize on $ROLLBACK_COLOR..."
|
||||
|
||||
# Stop and clean up current color containers, using the correct release path
|
||||
export CLEANUP_RELEASE_PATH="${CURRENT_RELEASE_PATH}"
|
||||
cleanup_color_containers "$CURRENT_COLOR"
|
||||
unset CLEANUP_RELEASE_PATH
|
||||
|
||||
# Refresh gatekeepers again to remove routes to the old color
|
||||
refresh_gatekeepers
|
||||
|
||||
echo "✅ Rollback completed!"
|
||||
echo " Active deployment: $ROLLBACK_COLOR"
|
||||
echo ""
|
||||
echo "📌 Note: The next deployment will now deploy as $CURRENT_COLOR"
|
||||
Loading…
Add table
Add a link
Reference in a new issue