Improve caching, performance and add dry-run

This commit is contained in:
René Preuß
2021-07-22 16:42:01 +02:00
parent 53cff7d805
commit 820287dd2c
13 changed files with 342 additions and 40 deletions

View File

@@ -2,7 +2,9 @@
namespace App\Commands;
use App\Bunny\Filesystem\CompareOptions;
use App\Bunny\Filesystem\EdgeStorage;
use App\Bunny\Filesystem\Exceptions\FilesystemException;
use App\Bunny\Filesystem\FileCompare;
use App\Bunny\Filesystem\LocalStorage;
use Illuminate\Console\Scheduling\Schedule;
@@ -16,7 +18,11 @@ class DeployCommand extends Command
* @var string
*/
protected $signature = 'deploy
{--dir=dist : Root directory to upload}';
{--dir=dist : Root directory to upload}
{--no-sha256-cache : Skips .well-known/bunny.sha256 and queries the storage endpoints recursively instead}
{--no-sha256-generation : Skips .well-known/bunny.sha256 generation}
{--sha256-name=.well-known/bunny.sha256 : Change filename of .well-known/bunny.sha256}
{--dry-run : Outputs the operations but will not execute anything}';
/**
* The description of the command.
@@ -34,9 +40,11 @@ class DeployCommand extends Command
{
$start = microtime(true);
$edgeStorage = new EdgeStorage();
$localStorage = new LocalStorage();
$fileCompare = new FileCompare($localStorage, $edgeStorage, $this);
$fileCompare = new FileCompare(
app(LocalStorage::class),
app(EdgeStorage::class),
$this
);
$localPath = realpath($path = $this->option('dir') ?? 'dist');
@@ -47,7 +55,23 @@ class DeployCommand extends Command
$edgePath = sprintf('/%s', config('bunny.storage.username'));
$fileCompare->compare($localPath, $edgePath, $start);
if ($this->option('dry-run')) {
$this->warn('⚠ Dry run is activated. The operations are displayed but not executed.');
}
try {
$fileCompare->compare($localPath, $edgePath, [
CompareOptions::START => $start,
CompareOptions::NO_SHA256_CACHE => $this->option('no-sha256-cache'),
CompareOptions::NO_SHA256_GENERATION => $this->option('no-sha256-generation'),
CompareOptions::SHA256_NAME => $this->option('sha256-name'),
CompareOptions::DRY_RUN => $this->option('dry-run'),
]);
} catch (FilesystemException $exception) {
$this->error($exception->getMessage());
return 2;
}
return 0;
}