Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to invalidate asset cache #190

Merged
merged 1 commit into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();