Skip to content

Add Blitz cache cleanup task for Craft CMS deployments#24

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-19
Draft

Add Blitz cache cleanup task for Craft CMS deployments#24
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-19

Conversation

Copilot AI commented Aug 5, 2025

Copy link
Copy Markdown
Contributor

This PR adds automated cleanup of Blitz cache files from old releases during Craft CMS deployments to prevent storage bloat and maintain optimal server performance.

What's Changed

New Task: lameco:cleanup_blitz_cache

Added a new deployment task that:

  • Targets Craft CMS projects only - Automatically detects project type and runs only when lameco_project_type === 'craftcms'
  • Runs after successful deployment - Executes after deploy:success to ensure the deployment completed before cleanup
  • Preserves current release - Removes web/cache/blitz from all old releases while keeping the current active release untouched
  • Includes safety checks - Verifies directories exist before removal and provides detailed logging
  • Works automatically - No configuration required; runs automatically for all Craft CMS projects

Why This Is Needed

Blitz is a popular static cache plugin for Craft CMS that stores cached files in web/cache/blitz. During deployments using Deployer's release system, these cache files accumulate across multiple releases:

releases/
├── release-20240110-111111/web/cache/blitz/  ← Old cache (should be removed)
├── release-20240112-222222/web/cache/blitz/  ← Old cache (should be removed)  
├── release-20240114-333333/web/cache/blitz/  ← Old cache (should be removed)
└── release-20240115-123456/web/cache/blitz/  ← Current cache (preserved)

Since the cache is environment-specific and tied to the current release, old cache files serve no purpose and consume unnecessary disk space. This cleanup ensures only the current release's cache is maintained.

Implementation Details

  • Uses Deployer's built-in get('release_name') and get('releases_list') functions for robust release management
  • Filters out the current release and processes only old releases
  • Safely removes cache directories with existence checks
  • Provides informative logging about cleanup progress
  • Handles edge cases like missing directories gracefully

Documentation

Updated README.md with comprehensive documentation including:

  • Task description and behavior
  • Explanation of why this is needed for Craft CMS
  • Task dependency information

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: kevinsleegerslameco <217211989+kevinsleegerslameco@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove web/cache/blitz folder from old releases after successful deployment (Craft CMS) Add Blitz cache cleanup task for Craft CMS deployments Aug 5, 2025
Comment thread src/config.php Outdated
set('lameco_php_config', 'php-fpm-{{http_user}}.service');

// Blitz cache cleanup configuration
set('lameco_cleanup_blitz_cache', true);

@kevinsleegerslameco kevinsleegerslameco Jan 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I don't think that this has to be configurable. I would just assume for it to work automatically if the project type is craft cms.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the configuration parameter. The task now runs automatically for all Craft CMS projects. (16043f3)

Comment thread src/tasks.php Outdated

// Get the current release name and all releases
$currentRelease = basename(run('readlink {{deploy_path}}/current'));
$releases = explode("\n", run('ls -1 {{deploy_path}}/releases'));

@kevinsleegerslameco kevinsleegerslameco Jan 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot If this works fine. But can you check if there's a built-in way in deployer to get the current release and other releases?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use Deployer's built-in functions: get('release_name') for the current release and get('releases_list') for all releases. This replaces the manual readlink and ls commands. (16043f3)

@kevinsleegerslameco

Copy link
Copy Markdown
Contributor

@copilot can you take a look at the reviews?

Co-authored-by: kevinsleegerslameco <217211989+kevinsleegerslameco@users.noreply.github.com>

Copilot AI commented Jan 9, 2026

Copy link
Copy Markdown
Contributor Author

@copilot can you take a look at the reviews?

Addressed both review comments in commit 16043f3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants