-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathPushConfigCommand.php
More file actions
60 lines (48 loc) · 1.75 KB
/
PushConfigCommand.php
File metadata and controls
60 lines (48 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace App\Commands;
use App\Support\Configuration;
use App\Sync\BaseSync;
use App\Sync\DaemonSync;
use App\Sync\DeploymentScriptSync;
use App\Sync\WebhookSync;
use App\Sync\WorkerSync;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Forge\Forge;
use Laravel\Forge\Resources\Server;
use Laravel\Forge\Resources\Site;
use Laravel\Forge\Resources\Webhook;
use LaravelZero\Framework\Commands\Command;
class PushConfigCommand extends ForgeCommand
{
const SYNC_CLASSES = [
WebhookSync::class,
DeploymentScriptSync::class,
DaemonSync::class,
WorkerSync::class,
];
protected $signature = 'config:push {environment=production} {--force}';
protected $description = 'Push the configuration from your forge.yml file to Laravel Forge';
/**
* @param Forge $forge
* @param Configuration $configuration
* @return int
*/
public function handle(Forge $forge, Configuration $configuration)
{
$environment = $this->argument('environment');
$server = $forge->server($configuration->get($environment, 'server'));
$site = $forge->site($server->id, $configuration->get($environment, 'id'));
$this->synchronize($environment, $server, $site);
$this->info('Done');
}
protected function synchronize(string $environment, Server $server, Site $site)
{
foreach (static::SYNC_CLASSES as $syncClass) {
$this->info('Synchronizing ' . $syncClass);
$output = fn (string $contents, string $level = 'info') => $this->{$level}($contents);
/** @var BaseSync $synchronizer */
$syncer = app($syncClass);
$syncer->sync($environment, $server, $site, $output, $this->option('force'));
}
}
}