Skip to content

Commit

Permalink
Merge branch 'next' into fix-docker-cleanup-notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
peaklabs-dev authored Dec 17, 2024
2 parents ed2ccaf + 905f849 commit f92ddd7
Show file tree
Hide file tree
Showing 73 changed files with 640 additions and 699 deletions.
114 changes: 66 additions & 48 deletions app/Http/Controllers/Api/ApplicationsController.php

Large diffs are not rendered by default.

73 changes: 45 additions & 28 deletions app/Http/Controllers/Api/DatabasesController.php

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions app/Http/Controllers/Api/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ public function project_by_uuid(Request $request)

#[OA\Get(
summary: 'Environment',
description: 'Get environment by name.',
path: '/projects/{uuid}/{environment_name}',
operationId: 'get-environment-by-name',
description: 'Get environment by name or UUID.',
path: '/projects/{uuid}/{environment_name_or_uuid}',
operationId: 'get-environment-by-name-or-uuid',
security: [
['bearerAuth' => []],
],
tags: ['Projects'],
parameters: [
new OA\Parameter(name: 'uuid', in: 'path', required: true, description: 'Project UUID', schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'environment_name', in: 'path', required: true, description: 'Environment name', schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'environment_name_or_uuid', in: 'path', required: true, description: 'Environment name or UUID', schema: new OA\Schema(type: 'string')),
],
responses: [
new OA\Response(
Expand Down Expand Up @@ -141,14 +141,17 @@ public function environment_details(Request $request)
if (! $request->uuid) {
return response()->json(['message' => 'UUID is required.'], 422);
}
if (! $request->environment_name) {
return response()->json(['message' => 'Environment name is required.'], 422);
if (! $request->environment_name_or_uuid) {
return response()->json(['message' => 'Environment name or UUID is required.'], 422);
}
$project = Project::whereTeamId($teamId)->whereUuid($request->uuid)->first();
if (! $project) {
return response()->json(['message' => 'Project not found.'], 404);
}
$environment = $project->environments()->whereName($request->environment_name)->first();
$environment = $project->environments()->whereName($request->environment_name_or_uuid)->first();
if (! $environment) {
$environment = $project->environments()->whereUuid($request->environment_name_or_uuid)->first();
}
if (! $environment) {
return response()->json(['message' => 'Environment not found.'], 404);
}
Expand Down
26 changes: 20 additions & 6 deletions app/Http/Controllers/Api/ServicesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function services(Request $request)
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
required: ['server_uuid', 'project_uuid', 'environment_name', 'type'],
required: ['server_uuid', 'project_uuid', 'environment_name', 'environment_uuid', 'type'],
properties: [
'type' => [
'description' => 'The one-click service type',
Expand Down Expand Up @@ -199,7 +199,8 @@ public function services(Request $request)
'name' => ['type' => 'string', 'maxLength' => 255, 'description' => 'Name of the service.'],
'description' => ['type' => 'string', 'nullable' => true, 'description' => 'Description of the service.'],
'project_uuid' => ['type' => 'string', 'description' => 'Project UUID.'],
'environment_name' => ['type' => 'string', 'description' => 'Environment name.'],
'environment_name' => ['type' => 'string', 'description' => 'Environment name. You need to provide at least one of environment_name or environment_uuid.'],
'environment_uuid' => ['type' => 'string', 'description' => 'Environment UUID. You need to provide at least one of environment_name or environment_uuid.'],
'server_uuid' => ['type' => 'string', 'description' => 'Server UUID.'],
'destination_uuid' => ['type' => 'string', 'description' => 'Destination UUID. Required if server has multiple destinations.'],
'instant_deploy' => ['type' => 'boolean', 'default' => false, 'description' => 'Start the service immediately after creation.'],
Expand Down Expand Up @@ -236,7 +237,7 @@ public function services(Request $request)
)]
public function create_service(Request $request)
{
$allowedFields = ['type', 'name', 'description', 'project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'instant_deploy'];
$allowedFields = ['type', 'name', 'description', 'project_uuid', 'environment_name', 'environment_uuid', 'server_uuid', 'destination_uuid', 'instant_deploy'];

$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
Expand All @@ -250,7 +251,8 @@ public function create_service(Request $request)
$validator = customApiValidator($request->all(), [
'type' => 'string|required',
'project_uuid' => 'string|required',
'environment_name' => 'string|required',
'environment_name' => 'string|nullable',
'environment_uuid' => 'string|nullable',
'server_uuid' => 'string|required',
'destination_uuid' => 'string',
'name' => 'string|max:255',
Expand All @@ -272,6 +274,11 @@ public function create_service(Request $request)
'errors' => $errors,
], 422);
}
$environmentUuid = $request->environment_uuid;
$environmentName = $request->environment_name;
if (blank($environmentUuid) && blank($environmentName)) {
return response()->json(['message' => 'You need to provide at least one of environment_name or environment_uuid.'], 422);
}
$serverUuid = $request->server_uuid;
$instantDeploy = $request->instant_deploy ?? false;
if ($request->is_public && ! $request->public_port) {
Expand All @@ -281,7 +288,10 @@ public function create_service(Request $request)
if (! $project) {
return response()->json(['message' => 'Project not found.'], 404);
}
$environment = $project->environments()->where('name', $request->environment_name)->first();
$environment = $project->environments()->where('name', $environmentName)->first();
if (! $environment) {
$environment = $project->environments()->where('uuid', $environmentUuid)->first();
}
if (! $environment) {
return response()->json(['message' => 'Environment not found.'], 404);
}
Expand Down Expand Up @@ -349,7 +359,11 @@ public function create_service(Request $request)
}
$domains = $service->applications()->get()->pluck('fqdn')->sort();
$domains = $domains->map(function ($domain) {
return str($domain)->beforeLast(':')->value();
if (count(explode(':', $domain)) > 2) {
return str($domain)->beforeLast(':')->value();
}

return $domain;
});

return response()->json([
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/ApplicationDeploymentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ private function deploy_to_additional_destinations()
'project_uuid' => data_get($this->application, 'environment.project.uuid'),
'application_uuid' => data_get($this->application, 'uuid'),
'deployment_uuid' => $deployment_uuid,
'environment_name' => data_get($this->application, 'environment.name'),
'environment_uuid' => data_get($this->application, 'environment.uuid'),
]));
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/Livewire/Boarding/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Models\Team;
use Illuminate\Support\Collection;
use Livewire\Component;
use Visus\Cuid2\Cuid2;

class Index extends Component
{
Expand Down Expand Up @@ -334,6 +335,7 @@ public function createNewProject()
$this->createdProject = Project::create([
'name' => 'My first project',
'team_id' => currentTeam()->id,
'uuid' => (string) new Cuid2,
]);
$this->currentState = 'create-resource';
}
Expand All @@ -346,7 +348,7 @@ public function showNewResource()
'project.resource.create',
[
'project_uuid' => $this->createdProject->uuid,
'environment_name' => 'production',
'environment_uuid' => $this->createdProject->environments->first()->uuid,
'server' => $this->createdServer->id,
]
);
Expand Down
15 changes: 15 additions & 0 deletions app/Livewire/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Server;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Redirect;
use Livewire\Component;

class Dashboard extends Component
Expand Down Expand Up @@ -49,6 +50,20 @@ public function loadDeployments()
])->sortBy('id')->groupBy('server_name')->toArray();
}

public function navigateToProject($projectUuid)
{
$project = Project::where('uuid', $projectUuid)->first();

if ($project && $project->environments->count() === 1) {
return Redirect::route('project.resource.index', [
'project_uuid' => $projectUuid,
'environment_uuid' => $project->environments->first()->uuid,
]);
}

return Redirect::route('project.show', ['project_uuid' => $projectUuid]);
}

public function render()
{
return view('livewire.dashboard');
Expand Down
2 changes: 2 additions & 0 deletions app/Livewire/Project/AddEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\Project;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Visus\Cuid2\Cuid2;

class AddEmpty extends Component
{
Expand All @@ -22,6 +23,7 @@ public function submit()
'name' => $this->name,
'description' => $this->description,
'team_id' => currentTeam()->id,
'uuid' => (string) new Cuid2,
]);

return redirect()->route('project.show', $project->uuid);
Expand Down
5 changes: 2 additions & 3 deletions app/Livewire/Project/Application/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function mount()
->where('uuid', request()->route('project_uuid'))
->firstOrFail();
$environment = $project->environments()
->select('id', 'name', 'project_id')
->where('name', request()->route('environment_name'))
->select('id', 'uuid', 'name', 'project_id')
->where('uuid', request()->route('environment_uuid'))
->firstOrFail();
$application = $environment->applications()
->with(['destination'])
Expand All @@ -39,7 +39,6 @@ public function mount()
$this->project = $project;
$this->environment = $environment;
$this->application = $application;

}

public function render()
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Project/Application/Deployment/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function mount()
if (! $project) {
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
$environment = $project->load(['environments'])->environments->where('uuid', request()->route('environment_uuid'))->first()->load(['applications']);
if (! $environment) {
return redirect()->route('dashboard');
}
Expand Down
12 changes: 2 additions & 10 deletions app/Livewire/Project/Application/Deployment/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,19 @@ public function mount()
if (! $project) {
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
$environment = $project->load(['environments'])->environments->where('uuid', request()->route('environment_uuid'))->first()->load(['applications']);
if (! $environment) {
return redirect()->route('dashboard');
}
$application = $environment->applications->where('uuid', request()->route('application_uuid'))->first();
if (! $application) {
return redirect()->route('dashboard');
}
// $activity = Activity::where('properties->type_uuid', '=', $deploymentUuid)->first();
// if (!$activity) {
// return redirect()->route('project.application.deployment.index', [
// 'project_uuid' => $project->uuid,
// 'environment_name' => $environment->name,
// 'application_uuid' => $application->uuid,
// ]);
// }
$application_deployment_queue = ApplicationDeploymentQueue::where('deployment_uuid', $deploymentUuid)->first();
if (! $application_deployment_queue) {
return redirect()->route('project.application.deployment.index', [
'project_uuid' => $project->uuid,
'environment_name' => $environment->name,
'environment_uuid' => $environment->uuid,
'application_uuid' => $application->uuid,
]);
}
Expand Down
6 changes: 3 additions & 3 deletions app/Livewire/Project/Application/Heading.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function mount()
{
$this->parameters = [
'project_uuid' => $this->application->project()->uuid,
'environment_name' => $this->application->environment->name,
'environment_uuid' => $this->application->environment->uuid,
'application_uuid' => $this->application->uuid,
];
$lastDeployment = $this->application->get_last_successful_deployment();
Expand Down Expand Up @@ -94,7 +94,7 @@ public function deploy(bool $force_rebuild = false)
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
'deployment_uuid' => $this->deploymentUuid,
'environment_name' => $this->parameters['environment_name'],
'environment_uuid' => $this->parameters['environment_uuid'],
]);
}

Expand Down Expand Up @@ -136,7 +136,7 @@ public function restart()
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
'deployment_uuid' => $this->deploymentUuid,
'environment_name' => $this->parameters['environment_name'],
'environment_uuid' => $this->parameters['environment_uuid'],
]);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Project/Application/Previews.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function deploy(int $pull_request_id, ?string $pull_request_html_url = nu
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
'deployment_uuid' => $this->deployment_uuid,
'environment_name' => $this->parameters['environment_name'],
'environment_uuid' => $this->parameters['environment_uuid'],
]);
} catch (\Throwable $e) {
return handleError($e, $this);
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Project/Application/Rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function rollbackImage($commit)
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
'deployment_uuid' => $deployment_uuid,
'environment_name' => $this->parameters['environment_name'],
'environment_uuid' => $this->parameters['environment_uuid'],
]);
}

Expand Down
8 changes: 5 additions & 3 deletions app/Livewire/Project/CloneMe.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CloneMe extends Component
{
public string $project_uuid;

public string $environment_name;
public string $environment_uuid;

public int $project_id;

Expand Down Expand Up @@ -44,7 +44,7 @@ public function mount($project_uuid)
{
$this->project_uuid = $project_uuid;
$this->project = Project::where('uuid', $project_uuid)->firstOrFail();
$this->environment = $this->project->environments->where('name', $this->environment_name)->first();
$this->environment = $this->project->environments->where('uuid', $this->environment_uuid)->first();
$this->project_id = $this->project->id;
$this->servers = currentTeam()->servers;
$this->newName = str($this->project->name.'-clone-'.(string) new Cuid2)->slug();
Expand Down Expand Up @@ -89,6 +89,7 @@ public function clone(string $type)
if ($this->environment->name !== 'production') {
$project->environments()->create([
'name' => $this->environment->name,
'uuid' => (string) new Cuid2,
]);
}
$environment = $project->environments->where('name', $this->environment->name)->first();
Expand All @@ -100,6 +101,7 @@ public function clone(string $type)
$project = $this->project;
$environment = $this->project->environments()->create([
'name' => $this->newName,
'uuid' => (string) new Cuid2,
]);
}
$applications = $this->environment->applications;
Expand Down Expand Up @@ -174,7 +176,7 @@ public function clone(string $type)

return redirect()->route('project.resource.index', [
'project_uuid' => $project->uuid,
'environment_name' => $environment->name,
'environment_uuid' => $environment->uuid,
]);
} catch (\Exception $e) {
return handleError($e, $this);
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Project/Database/Backup/Execution.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function mount()
if (! $project) {
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
$environment = $project->load(['environments'])->environments->where('uuid', request()->route('environment_uuid'))->first()->load(['applications']);
if (! $environment) {
return redirect()->route('dashboard');
}
Expand Down
4 changes: 2 additions & 2 deletions app/Livewire/Project/Database/Backup/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function mount()
if (! $project) {
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
$environment = $project->load(['environments'])->environments->where('uuid', request()->route('environment_uuid'))->first()->load(['applications']);
if (! $environment) {
return redirect()->route('dashboard');
}
Expand All @@ -31,7 +31,7 @@ public function mount()
) {
return redirect()->route('project.database.configuration', [
'project_uuid' => $project->uuid,
'environment_name' => $environment->name,
'environment_uuid' => $environment->uuid,
'database_uuid' => $database->uuid,
]);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Livewire/Project/Database/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function mount()
->where('uuid', request()->route('project_uuid'))
->firstOrFail();
$environment = $project->environments()
->select('id', 'name', 'project_id')
->where('name', request()->route('environment_name'))
->select('id', 'name', 'project_id', 'uuid')
->where('uuid', request()->route('environment_uuid'))
->firstOrFail();
$database = $environment->databases()
->where('uuid', request()->route('database_uuid'))
Expand Down
Loading

0 comments on commit f92ddd7

Please sign in to comment.