This commit is contained in:
Andras Bacsai 2023-03-30 17:29:01 +02:00
parent da2f657342
commit 8019dc1267
6 changed files with 19 additions and 81 deletions

View File

@ -2,6 +2,8 @@
namespace App\Http\Controllers;
use App\Models\Application;
use App\Models\Environment;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@ -9,8 +11,7 @@ class ProjectController extends Controller
{
public function environments()
{
$project_uuid = request()->route('project_uuid');
$project = session('currentTeam')->projects->where('uuid', $project_uuid)->first();
$project = session('currentTeam')->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
return redirect()->route('home');
}
@ -18,94 +19,33 @@ public function environments()
}
public function resources()
{
$project_uuid = request()->route('project_uuid');
$project = session('currentTeam')->projects->where('uuid', $project_uuid)->first();
$project = session('currentTeam')->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
return redirect()->route('home');
}
$environment = $project->environments->where('name', request()->route('environment_name'))->first();
$environment = Environment::where('name', request()->route('environment_name'))->where('project_id', $project->id)->first();
// $environment = $project->environments->where('name', request()->route('environment_name'))->first();
return view('project.resources', ['project' => $project, 'environment' => $environment]);
}
public function application()
{
$project_uuid = request()->route('project_uuid');
$environment_name = request()->route('environment_name');
$application_uuid = request()->route('application_uuid');
$project = session('currentTeam')->projects->where('uuid', $project_uuid)->first();
if (!$project) {
return redirect()->route('home');
}
$environment = $project->environments->where('name', $environment_name)->first();
if (!$environment) {
return redirect()->route('home');
}
$application = $environment->applications->where('uuid', $application_uuid)->first();
$application = Application::where('uuid', request()->route('application_uuid'))->first();
if (!$application) {
return redirect()->route('home');
}
return view('project.application', ['project' => $project, 'application' => $application, 'deployments' => $application->deployments()]);
return view('project.application', ['application' => $application, 'deployments' => $application->deployments()]);
}
public function database()
{
$project_uuid = request()->route('project_uuid');
$environment_name = request()->route('environment_name');
$database_uuid = request()->route('database_uuid');
$project = session('currentTeam')->projects->where('uuid', $project_uuid)->first();
if (!$project) {
return redirect()->route('home');
}
$environment = $project->environments->where('name', $environment_name)->first();
if (!$environment) {
return redirect()->route('home');
}
$database = $environment->databases->where('uuid', $database_uuid)->first();
if (!$database) {
return redirect()->route('home');
}
return view('project.database', ['project' => $project, 'database' => $database]);
}
public function service()
{
$project_uuid = request()->route('project_uuid');
$environment_name = request()->route('environment_name');
$service_uuid = request()->route('service_uuid');
$project = session('currentTeam')->projects->where('uuid', $project_uuid)->first();
if (!$project) {
return redirect()->route('home');
}
$environment = $project->environments->where('name', $environment_name)->first();
if (!$environment) {
return redirect()->route('home');
}
$service = $environment->services->where('uuid', $service_uuid)->first();
if (!$service) {
return redirect()->route('home');
}
return view('project.service', ['project' => $project, 'service' => $service]);
}
public function deployment()
{
$project_uuid = request()->route('project_uuid');
$environment_name = request()->route('environment_name');
$application_uuid = request()->route('application_uuid');
$deployment_uuid = request()->route('deployment_uuid');
$project = session('currentTeam')->projects->where('uuid', $project_uuid)->first();
if (!$project) {
return redirect()->route('home');
}
$environment = $project->environments->where('name', $environment_name)->first();
if (!$environment) {
return redirect()->route('home');
}
$application = $environment->applications->where('uuid', $application_uuid)->first();
$application = Application::where('uuid', request()->route('application_uuid'))->first();
if (!$application) {
return redirect()->route('home');
}
$activity = $application->get_deployment($deployment_uuid);
return view('project.deployment', ['project' => $project, 'activity' => $activity]);
return view('project.deployment', ['activity' => $activity]);
}
}

View File

@ -221,7 +221,7 @@ public function deploy()
$this->execute_in_builder("docker build -f {$workdir}/Dockerfile --build-arg SOURCE_COMMIT=$(cat {$workdir}/.git-commit) --progress plain -t {$this->application->uuid}:$(cat {$workdir}/.git-commit) {$workdir}");
$this->command[] = "echo 'Done.'";
// $this->execute_in_builder("test ! -z \"$(docker ps --format '{{.State}}' --filter 'name={$this->application->uuid}')\" && docker rm -f {$this->application->uuid} >/dev/null 2>&1");
$this->execute_in_builder("docker rm -f {$this->application->uuid} >/dev/null 2>&1");
$this->command[] = "echo -n 'Deploying... '";

View File

@ -4,6 +4,7 @@
class Project extends BaseModel
{
protected $with = ['settings', 'environments'];
protected static function booted()
{
static::created(function ($project) {

View File

@ -1,7 +1,4 @@
<x-layout>
<h1>Deployment</h1>
<p>Name: {{ $project->name }}</p>
<p>UUID: {{ $project->uuid }}</p>
<livewire:poll-activity :activity="$activity" />
</x-layout>

View File

@ -3,12 +3,12 @@
<div>
@foreach ($environment->applications as $application)
<p>
<a href="{{ route('project.application', [$project->uuid, $environment->name, $application->uuid]) }}">
<a href="{{ route('project.application', [$application->uuid]) }}">
{{ $application->name }}
</a>
</p>
@endforeach
@foreach ($environment->databases as $database)
{{-- @foreach ($environment->databases as $database)
<p>
<a href="{{ route('project.database', [$project->uuid, $environment->name, $database->uuid]) }}">
{{ $database->name }}
@ -21,6 +21,6 @@
{{ $service->name }}
</a>
</p>
@endforeach
@endforeach --}}
</div>
</x-layout>

View File

@ -23,11 +23,11 @@
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('/application/{application_uuid}', [ProjectController::class, 'application'])->name('project.application');
Route::get('/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');
// Route::get('/database/{database_uuid}', [ProjectController::class, 'database'])->name('project.database');
// Route::get('//service/{service_uuid}', [ProjectController::class, 'service'])->name('project.service');
Route::get('/profile', function () {
return view('profile');