PHPackages                             service-to/prune-releases - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. service-to/prune-releases

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

service-to/prune-releases
=========================

A Laravel package for automatically pruning old deployment releases while preserving the current symlinked release

00PHP

Since Dec 2Pushed 5mo agoCompare

[ Source](https://github.com/ServiceTo/PruneReleases)[ Packagist](https://packagist.org/packages/service-to/prune-releases)[ RSS](/packages/service-to-prune-releases/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PruneReleases
=============

[](#prunereleases)

A Laravel package for automatically pruning old deployment releases while preserving the current symlinked release.

Overview
--------

[](#overview)

When using deployment tools like Laravel Envoy with a releases directory structure, old releases can accumulate over time and consume disk space. This package automatically cleans up old releases while ensuring:

- The currently active release (symlinked via `current`) is **never** deleted
- A configurable number of recent releases are retained
- Scheduled automatic cleanup runs daily (or on your custom schedule)
- Safe operation with dry-run mode and logging

Installation
------------

[](#installation)

### Via Packagist

[](#via-packagist)

```
composer require service-to/prune-releases
```

### Laravel Auto-Discovery

[](#laravel-auto-discovery)

The package will automatically register its service provider in Laravel 5.5+.

### Publish Configuration

[](#publish-configuration)

Publish the configuration file to customize settings:

```
php artisan vendor:publish --tag=prune-releases-config
```

This will create `config/prune-releases.php` in your application.

Configuration
-------------

[](#configuration)

Edit `config/prune-releases.php` to customize the package behavior:

```
return [
    // Path to your releases directory
    'releases_directory' => env('PRUNE_RELEASES_DIR', base_path('../releases')),

    // Number of recent releases to keep
    'keep' => env('PRUNE_RELEASES_KEEP', 5),

    // Path to the current symlink
    'current_symlink' => env('PRUNE_RELEASES_CURRENT', base_path('../current')),

    // When to run: 'daily', 'hourly', 'weekly', or a cron expression
    'schedule' => env('PRUNE_RELEASES_SCHEDULE', 'daily'),

    // Enable dry-run mode (won't actually delete anything)
    'dry_run' => env('PRUNE_RELEASES_DRY_RUN', false),

    // Enable detailed logging
    'logging' => env('PRUNE_RELEASES_LOGGING', true),
];
```

### Environment Variables

[](#environment-variables)

You can also configure the package using environment variables in your `.env` file:

```
PRUNE_RELEASES_DIR=/var/www/your-app/releases
PRUNE_RELEASES_KEEP=5
PRUNE_RELEASES_CURRENT=/var/www/your-app/current
PRUNE_RELEASES_SCHEDULE=daily
PRUNE_RELEASES_DRY_RUN=false
PRUNE_RELEASES_LOGGING=true
```

Usage
-----

[](#usage)

### Automatic Scheduled Pruning

[](#automatic-scheduled-pruning)

The package automatically schedules the prune command to run based on your `schedule` configuration. Make sure your Laravel scheduler is running:

```
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
```

### Manual Pruning

[](#manual-pruning)

You can manually prune releases at any time:

```
php artisan releases:prune
```

### Dry Run Mode

[](#dry-run-mode)

Test the pruning logic without actually deleting anything:

```
php artisan releases:prune --dry-run
```

Or set it in configuration:

```
PRUNE_RELEASES_DRY_RUN=true
```

### Override Keep Count

[](#override-keep-count)

Override the number of releases to keep for a single run:

```
php artisan releases:prune --keep=10
```

How It Works
------------

[](#how-it-works)

1. **Scans** the releases directory for all release folders
2. **Identifies** the current active release by following the `current` symlink
3. **Sorts** releases by modification time (newest first)
4. **Keeps** the configured number of recent releases
5. **Protects** the current release from deletion (even if it's older than the keep threshold)
6. **Deletes** old releases that exceed the keep threshold
7. **Logs** all operations for auditing

Example Deployment Structure
----------------------------

[](#example-deployment-structure)

```
/var/www/your-app/
├── current -> /var/www/your-app/releases/20241202120000
├── .env
├── storage/
└── releases/
    ├── 20241201120000/
