diff --git a/app/Actions/RemoteProcess/DispatchRemoteProcess.php b/app/Actions/RemoteProcess/DispatchRemoteProcess.php index 0f9d60192..21e40d3a0 100644 --- a/app/Actions/RemoteProcess/DispatchRemoteProcess.php +++ b/app/Actions/RemoteProcess/DispatchRemoteProcess.php @@ -19,12 +19,10 @@ class DispatchRemoteProcess $this->activity = activity() ->withProperties($properties) ->performedOn($remoteProcessArgs->model) - ->event('deployment') ->log(""); } else { $this->activity = activity() ->withProperties($remoteProcessArgs->toArray()) - ->event('remote_process') ->log(""); } } diff --git a/app/Actions/RemoteProcess/RunRemoteProcess.php b/app/Actions/RemoteProcess/RunRemoteProcess.php index 14b9190e1..3104cc36f 100644 --- a/app/Actions/RemoteProcess/RunRemoteProcess.php +++ b/app/Actions/RemoteProcess/RunRemoteProcess.php @@ -31,7 +31,8 @@ class RunRemoteProcess */ public function __construct(Activity $activity) { - if ($activity->getExtraProperty('type') !== ActivityTypes::REMOTE_PROCESS->value) { + + if ($activity->getExtraProperty('type') !== ActivityTypes::REMOTE_PROCESS->value && $activity->getExtraProperty('type') !== ActivityTypes::DEPLOYMENT->value) { throw new \RuntimeException('Incompatible Activity to run a remote command.'); } diff --git a/app/Enums/ActivityTypes.php b/app/Enums/ActivityTypes.php index ad1c10c7a..5bcab7cd7 100644 --- a/app/Enums/ActivityTypes.php +++ b/app/Enums/ActivityTypes.php @@ -5,4 +5,5 @@ namespace App\Enums; enum ActivityTypes: string { case REMOTE_PROCESS = 'remote_process'; + case DEPLOYMENT = 'deployment'; } diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 43b17430c..a31681a4b 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -42,7 +42,7 @@ class ProjectController extends Controller if (!$application) { return redirect()->route('home'); } - return view('project.application', ['project' => $project, 'application' => $application]); + return view('project.application', ['project' => $project, 'application' => $application, 'deployments' => $application->deployments()]); } public function database() { diff --git a/app/Http/Livewire/DeployApplication.php b/app/Http/Livewire/DeployApplication.php index e6889f1e4..95cc1b30b 100644 --- a/app/Http/Livewire/DeployApplication.php +++ b/app/Http/Livewire/DeployApplication.php @@ -36,7 +36,7 @@ class DeployApplication extends Component $wildcard_domain = $project_wildcard_domain ?? $global_wildcard_domain ?? null; // Create Deployment ID - $this->deployment_uuid = new Cuid2(12); + $this->deployment_uuid = new Cuid2(7); $workdir = "/artifacts/{$this->deployment_uuid}"; // Start build process @@ -48,20 +48,9 @@ class DeployApplication extends Component $this->command[] = "docker stop -t 0 {$this->deployment_uuid} >/dev/null"; $this->activity = remoteProcess($this->command, $destination->server, $this->deployment_uuid, $application); - // Create Deployment - Deployment::create([ - 'uuid' => $this->deployment_uuid, - 'type_id' => $application->id, - 'type_type' => Application::class, - 'activity_log_id' => $this->activity->id, - ]); - // Redirect to deployment page - return redirect()->route('project.deployment', [ - "deployment_uuid" => $this->deployment_uuid, - "project_uuid" => $application->environment->project->uuid, - "environment_name" => $application->environment->name, - "application_uuid" => $application->uuid - ]); + $currentUrl = url()->previous(); + $deploymentUrl = "$currentUrl/deployment/$this->deployment_uuid"; + return redirect($deploymentUrl); } public function render() { diff --git a/app/Models/Application.php b/app/Models/Application.php index afd52ae90..c6bacd941 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -22,7 +22,10 @@ class Application extends BaseModel { return $this->morphTo(); } - + public function deployments() + { + return Activity::where('subject_id', $this->id)->where('properties->deployment_uuid', '!=', null)->orderBy('created_at', 'desc')->get(); + } public function get_deployment(string $deployment_uuid) { return Activity::where('subject_id', $this->id)->where('properties->deployment_uuid', '=', $deployment_uuid)->first(); diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 32bf22f89..1d9564ee2 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -12,7 +12,7 @@ abstract class BaseModel extends Model parent::boot(); static::creating(function (Model $model) { - $model->uuid = (string) new Cuid2(); + $model->uuid = (string) new Cuid2(7); }); } } diff --git a/app/Models/User.php b/app/Models/User.php index 576415ec1..5ba3a299d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -48,7 +48,7 @@ class User extends Authenticatable parent::boot(); static::creating(function (Model $model) { - $model->uuid = (string) new Cuid2(); + $model->uuid = (string) new Cuid2(7); }); } public function teams() diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 0b9498831..86bc7a6e0 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -2,6 +2,7 @@ use App\Actions\RemoteProcess\DispatchRemoteProcess; use App\Data\RemoteProcessArgs; +use App\Enums\ActivityTypes; use App\Models\Server; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Storage; @@ -29,6 +30,7 @@ if (!function_exists('remoteProcess')) { return resolve(DispatchRemoteProcess::class, [ 'remoteProcessArgs' => new RemoteProcessArgs( + type: $deployment_uuid ? ActivityTypes::DEPLOYMENT->value : ActivityTypes::REMOTE_PROCESS->value, model: $model, server_ip: $server->ip, deployment_uuid: $deployment_uuid, diff --git a/resources/views/project/application.blade.php b/resources/views/project/application.blade.php index 36ab57146..db9ba59ee 100644 --- a/resources/views/project/application.blade.php +++ b/resources/views/project/application.blade.php @@ -3,4 +3,13 @@

Name: {{ $project->name }}

UUID: {{ $project->uuid }}

+
+

Deployments

+ @foreach ($deployments as $deployment) +

+ + {{ data_get($deployment->properties, 'deployment_uuid') }} +

+ @endforeach +
diff --git a/routes/web.php b/routes/web.php index 875a117c8..067b0536f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -20,9 +20,12 @@ use Illuminate\Support\Facades\Route; Route::middleware(['auth'])->group(function () { Route::get('/', [HomeController::class, 'show'])->name('home'); Route::get('/project/{project_uuid}', [ProjectController::class, 'environments'])->name('project.environments'); + Route::get('/project/{project_uuid}/{environment_name}', [ProjectController::class, 'resources'])->name('project.resources'); + Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}', [ProjectController::class, 'application'])->name('project.application'); Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}/deployment/{deployment_uuid}', [ProjectController::class, 'deployment'])->name('project.deployment'); + Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}', [ProjectController::class, 'database'])->name('project.database'); Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}', [ProjectController::class, 'service'])->name('project.service');