Skip to content

Commit

Permalink
Add command to invalidate asset cache (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon authored Jul 15, 2022
1 parent 04271d8 commit 9bbf55b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
40 changes: 40 additions & 0 deletions src/Commands/InvalidateAssetCacheCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Laravel\VaporCli\Commands;

use Laravel\VaporCli\Helpers;
use Laravel\VaporCli\Manifest;
use Symfony\Component\Console\Input\InputArgument;

class InvalidateAssetCacheCommand extends Command
{
/**
* Configure the command options.
*
* @return void
*/
protected function configure()
{
$this
->setName('asset:invalidate-cache')
->addArgument('environment', InputArgument::OPTIONAL, 'The environment name')
->setDescription('Invalidate the asset cache for the given environment');
}

/**
* Execute the command.
*
* @return void
*/
public function handle()
{
Helpers::ensure_api_token_is_available();

$this->vapor->invalidateAssetCache(
Manifest::id(),
$this->argument('environment')
);

Helpers::info("Asset cache for {$this->argument('environment')} is being invalidated.");
}
}
11 changes: 11 additions & 0 deletions src/ConsoleVaporClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,17 @@ public function recordArtifactAssets($artifactId, array $files)
]);
}

/**
* Invalidate the asset cache for the given environment.
*
* @param string $environment
* @return array
*/
public function invalidateAssetCache($projectId, $environment)
{
return $this->requestWithErrorHandling('post', '/api/projects/'.$projectId.'/environments/'.$environment.'/invalidate-assets');
}

/**
* Get all of the deployments for the given project.
*
Expand Down
6 changes: 4 additions & 2 deletions vapor
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ if (file_exists(__DIR__.'/../../autoload.php')) {
*/
(function () {
if (class_exists(RepositoryBuilder::class)) {

$adapters = [
V4orV5EnvConstAdapter::class,
V4orV5ServerConstAdapter::class,
Expand Down Expand Up @@ -56,7 +55,7 @@ if (file_exists(__DIR__.'/../../autoload.php')) {
)->safeLoad();
} else { // V3
Dotenv::create(__DIR__, null, new DotenvFactory([
new V3EnvConstAdapter, new V3ServerConstAdapter
new V3EnvConstAdapter, new V3ServerConstAdapter,
]))->safeLoad();
}
})();
Expand Down Expand Up @@ -206,4 +205,7 @@ $app->add(new Commands\MetricsCommand);
$app->add(new Commands\LocalCommand);
$app->add(new Commands\TestCommand);

// Assets...
$app->add(new Commands\InvalidateAssetCacheCommand);

$app->run();

0 comments on commit 9bbf55b

Please sign in to comment.