Skip to content

Commit 6c88a3c

Browse files
committed
chore: add a button to trigger a deploy from app instance
1 parent 970e5da commit 6c88a3c

2 files changed

Lines changed: 64 additions & 2 deletions

File tree

app/Console/Commands/TriggerLagoonDeployOnAppInstances.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Models\PolydockStoreApp;
77
use Illuminate\Console\Command;
88
use Illuminate\Support\Facades\Process;
9+
910
use function Laravel\Prompts\multiselect;
1011

1112
class TriggerLagoonDeployOnAppInstances extends Command
@@ -91,7 +92,7 @@ public function handle()
9192
$options = [];
9293
foreach ($instanceData as $id => $data) {
9394
$label = sprintf(
94-
"%s %s %s %s",
95+
'%s %s %s %s',
9596
str_pad($data['id'], $maxWidths['id']),
9697
str_pad($data['name'], $maxWidths['name']),
9798
str_pad($data['project'], $maxWidths['project']),
@@ -102,7 +103,7 @@ public function handle()
102103

103104
// Create a header for the prompt label
104105
$header = sprintf(
105-
"%s %s %s %s",
106+
'%s %s %s %s',
106107
str_pad('ID', $maxWidths['id']),
107108
str_pad('Name', $maxWidths['name']),
108109
str_pad('Lagoon Project', $maxWidths['project']),

app/Filament/Admin/Resources/PolydockAppInstanceResource/Pages/ViewPolydockAppInstance.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
use Filament\Actions;
88
use Filament\Actions\Action;
99
use Filament\Forms\Components\DatePicker;
10+
use Filament\Forms\Components\Placeholder;
11+
use Filament\Forms\Components\TextInput;
1012
use Filament\Notifications\Notification;
1113
use Filament\Resources\Pages\ViewRecord;
14+
use FreedomtechHosting\PolydockApp\Enums\PolydockAppInstanceStatus;
15+
use Illuminate\Support\Facades\Process;
1216

1317
class ViewPolydockAppInstance extends ViewRecord
1418
{
@@ -19,6 +23,63 @@ protected function getHeaderActions(): array
1923
{
2024
return [
2125
Actions\EditAction::make(),
26+
Action::make('trigger_deploy')
27+
->label('Trigger Deploy')
28+
->icon('heroicon-o-rocket-launch')
29+
->color('warning')
30+
->requiresConfirmation()
31+
->form([
32+
TextInput::make('branch')
33+
->label('Branch / Environment')
34+
->required()
35+
->disabled()
36+
->default(fn ($record) => $record->getKeyValue('lagoon-deploy-branch')),
37+
Placeholder::make('last_deployment_date')
38+
->label('Last Deployment Date')
39+
->content(function ($record) {
40+
$lastDeployLog = $record->logs()
41+
->whereJsonContains('data->new_status', PolydockAppInstanceStatus::DEPLOY_COMPLETED->value)
42+
->latest()
43+
->first();
44+
45+
return $lastDeployLog ? $lastDeployLog->created_at->toDateTimeString() : 'Never';
46+
}),
47+
])
48+
->action(function (array $data, $record): void {
49+
$projectName = $record->getKeyValue('lagoon-project-name');
50+
$branch = $data['branch'];
51+
52+
if (empty($projectName) || empty($branch)) {
53+
Notification::make()
54+
->title('Deployment Failed')
55+
->danger()
56+
->body('Missing project name or branch configuration.')
57+
->send();
58+
59+
return;
60+
}
61+
62+
$fullCommand = sprintf('lagoon deploy -p %s -e %s',
63+
escapeshellarg($projectName),
64+
escapeshellarg($branch)
65+
);
66+
67+
$result = Process::run($fullCommand);
68+
69+
if ($result->successful()) {
70+
Notification::make()
71+
->title('Deployment Triggered')
72+
->success()
73+
->body('Output: '.trim($result->output()))
74+
->send();
75+
} else {
76+
Notification::make()
77+
->title('Deployment Failed')
78+
->danger()
79+
->body('Error: '.trim($result->errorOutput()))
80+
->send();
81+
}
82+
}),
2283
Action::make('extend_trial')
2384
->label('Extend Trial')
2485
->icon('heroicon-o-calendar')

0 commit comments

Comments
 (0)