Compare commits

...

5 Commits
0.4.0 ... 0.6.0

Author SHA1 Message Date
10a6bb57a8 adding Projects feature (#85) 2024-01-02 19:50:49 +01:00
fd2244d382 update composer (#84)
* update composer
log viewer
code style format

* fix composer
2024-01-01 22:05:31 +01:00
551f1ce40e fix issue with php site creation 2024-01-01 21:47:05 +01:00
1ce92d9361 fix issue with php site creation 2024-01-01 21:44:49 +01:00
ec6e55e30c Update README.md 2024-01-01 19:49:51 +01:00
65 changed files with 2387 additions and 1055 deletions

View File

@ -10,6 +10,14 @@ ## Documentation
https://vitodeploy.com https://vitodeploy.com
## Feedbacks
https://features.vitodeploy.com
## Roadmap
https://https://features.vitodeploy.com/roadmap
## Contribution ## Contribution
Please read the contribution guide [Here](/CONTRIBUTING.md) Please read the contribution guide [Here](/CONTRIBUTING.md)

View File

@ -0,0 +1,36 @@
<?php
namespace App\Actions\Projects;
use App\Models\Project;
use App\Models\User;
use Illuminate\Support\Facades\Validator;
class CreateProject
{
public function create(User $user, array $input): Project
{
$this->validate($user, $input);
$project = new Project([
'user_id' => $user->id,
'name' => $input['name'],
]);
$project->save();
return $project;
}
private function validate(User $user, array $input): void
{
Validator::make($input, [
'name' => [
'required',
'string',
'max:255',
'unique:projects,name,NULL,id,user_id,'.$user->id,
],
])->validate();
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace App\Actions\Projects;
use App\Models\Project;
use App\Models\User;
use Illuminate\Validation\ValidationException;
class DeleteProject
{
public function delete(User $user, int $projectId): void
{
/** @var Project $project */
$project = $user->projects()->findOrFail($projectId);
if ($user->projects()->count() === 1) {
throw ValidationException::withMessages([
'project' => __('Cannot delete the last project.'),
]);
}
if ($user->current_project_id == $project->id) {
/** @var Project $randomProject */
$randomProject = $user->projects()->where('id', '!=', $project->id)->first();
$user->current_project_id = $randomProject->id;
$user->save();
}
$project->delete();
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace App\Actions\Projects;
use App\Models\Project;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
class UpdateProject
{
public function update(Project $project, array $input): Project
{
$this->validate($project, $input);
$project->name = $input['name'];
$project->save();
return $project;
}
private function validate(Project $project, array $input): void
{
Validator::make($input, [
'name' => [
'required',
'string',
'max:255',
Rule::unique('projects')->ignore($project->id),
],
])->validate();
}
}

View File

@ -26,6 +26,7 @@ public function create(User $creator, array $input): Server
$this->validateInputs($input); $this->validateInputs($input);
$server = new Server([ $server = new Server([
'project_id' => $creator->currentProject->id,
'user_id' => $creator->id, 'user_id' => $creator->id,
'name' => $input['name'], 'name' => $input['name'],
'ssh_user' => config('core.server_providers_default_user')[$input['provider']][$input['os']], 'ssh_user' => config('core.server_providers_default_user')[$input['provider']][$input['os']],

View File

@ -15,13 +15,13 @@ public function create(
?int $siteId = null ?int $siteId = null
): void; ): void;
public function delete(int $id, int $siteId = null): void; public function delete(int $id, ?int $siteId = null): void;
public function restart(int $id, int $siteId = null): void; public function restart(int $id, ?int $siteId = null): void;
public function stop(int $id, int $siteId = null): void; public function stop(int $id, ?int $siteId = null): void;
public function start(int $id, int $siteId = null): void; public function start(int $id, ?int $siteId = null): void;
public function getLogs(string $logPath): string; public function getLogs(string $logPath): string;
} }

View File

@ -12,7 +12,7 @@ public function credentialData(array $input): array;
public function data(array $input): array; public function data(array $input): array;
public function connect(array $credentials = null): bool; public function connect(?array $credentials = null): bool;
public function plans(): array; public function plans(): array;

View File

@ -6,7 +6,7 @@ interface SourceControlProvider
{ {
public function connect(): bool; public function connect(): bool;
public function getRepo(string $repo = null): mixed; public function getRepo(?string $repo = null): mixed;
public function fullRepoUrl(string $repo, string $key): string; public function fullRepoUrl(string $repo, string $key): string;

View File

@ -7,7 +7,7 @@
class SourceControlIsNotConnected extends Exception class SourceControlIsNotConnected extends Exception
{ {
public function __construct(protected SourceControl|string|null $sourceControl, string $message = null) public function __construct(protected SourceControl|string|null $sourceControl, ?string $message = null)
{ {
parent::__construct($message ?? 'Source control is not connected'); parent::__construct($message ?? 'Source control is not connected');
} }

View File

@ -31,7 +31,7 @@ class SSH
protected PrivateKey $privateKey; protected PrivateKey $privateKey;
public function init(Server $server, string $asUser = null): self public function init(Server $server, ?string $asUser = null): self
{ {
$this->connection = null; $this->connection = null;
$this->log = null; $this->log = null;
@ -87,7 +87,7 @@ public function connect(bool $sftp = false): void
/** /**
* @throws Throwable * @throws Throwable
*/ */
public function exec(string|array|SSHCommand $commands, string $log = '', int $siteId = null): string public function exec(string|array|SSHCommand $commands, string $log = '', ?int $siteId = null): string
{ {
if ($log) { if ($log) {
$this->setLog($log, $siteId); $this->setLog($log, $siteId);

View File

@ -0,0 +1,29 @@
<?php
namespace App\Http\Controllers;
use App\Models\Project;
use App\Models\User;
use Illuminate\Contracts\View\View;
class ProjectController extends Controller
{
public function index(): View
{
return view('projects.index');
}
public function switch($projectId)
{
/** @var User $user */
$user = auth()->user();
/** @var Project $project */
$project = $user->projects()->findOrFail($projectId);
$user->current_project_id = $project->id;
$user->save();
return redirect()->route('servers');
}
}

View File

@ -12,8 +12,8 @@
class AutoDeployment extends Component class AutoDeployment extends Component
{ {
use RefreshComponentOnBroadcast;
use HasToast; use HasToast;
use RefreshComponentOnBroadcast;
public Site $site; public Site $site;

View File

@ -11,8 +11,8 @@
class Deploy extends Component class Deploy extends Component
{ {
use RefreshComponentOnBroadcast;
use HasToast; use HasToast;
use RefreshComponentOnBroadcast;
public Site $site; public Site $site;

View File

@ -10,8 +10,8 @@
class DeploymentsList extends Component class DeploymentsList extends Component
{ {
use RefreshComponentOnBroadcast;
use HasCustomPaginationView; use HasCustomPaginationView;
use RefreshComponentOnBroadcast;
public Site $site; public Site $site;

View File

@ -0,0 +1,37 @@
<?php
namespace App\Http\Livewire\Projects;
use App\Traits\HasToast;
use App\Traits\RefreshComponentOnBroadcast;
use Illuminate\Contracts\View\View;
use Livewire\Component;
class CreateProject extends Component
{
use HasToast;
use RefreshComponentOnBroadcast;
public bool $open = false;
public array $inputs = [];
public function create(): void
{
app(\App\Actions\Projects\CreateProject::class)
->create(auth()->user(), $this->inputs);
$this->emitTo(ProjectsList::class, '$refresh');
$this->dispatchBrowserEvent('created', true);
}
public function render(): View
{
if (request()->query('create')) {
$this->open = true;
}
return view('livewire.projects.create-project');
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace App\Http\Livewire\Projects;
use App\Actions\Projects\UpdateProject;
use App\Models\Project;
use App\Traits\RefreshComponentOnBroadcast;
use Illuminate\Contracts\View\View;
use Livewire\Component;
class EditProject extends Component
{
use RefreshComponentOnBroadcast;
public Project $project;
public array $inputs = [];
public function save(): void
{
app(UpdateProject::class)->update($this->project, $this->inputs);
$this->redirect(route('projects'));
}
public function mount(): void
{
$this->inputs = [
'name' => $this->project->name,
];
}
public function render(): View
{
return view('livewire.projects.edit-project');
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace App\Http\Livewire\Projects;
use App\Actions\Projects\DeleteProject;
use App\Traits\HasToast;
use App\Traits\RefreshComponentOnBroadcast;
use Illuminate\Contracts\View\View;
use Illuminate\Validation\ValidationException;
use Livewire\Component;
class ProjectsList extends Component
{
use HasToast;
use RefreshComponentOnBroadcast;
protected $listeners = [
'$refresh',
];
public int $deleteId;
public function delete(): void
{
try {
app(DeleteProject::class)->delete(auth()->user(), $this->deleteId);
$this->redirect(route('projects'));
return;
} catch (ValidationException $e) {
$this->toast()->error($e->getMessage());
}
}
public function render(): View
{
return view('livewire.projects.projects-list', [
'projects' => auth()->user()->projects()->orderByDesc('id')->get(),
]);
}
}

View File

@ -11,8 +11,8 @@
class LogsList extends Component class LogsList extends Component
{ {
use RefreshComponentOnBroadcast;
use HasCustomPaginationView; use HasCustomPaginationView;
use RefreshComponentOnBroadcast;
public ?int $count = null; public ?int $count = null;

View File

@ -2,7 +2,7 @@
namespace App\Http\Livewire\Servers; namespace App\Http\Livewire\Servers;
use App\Models\Server; use App\Models\User;
use App\Traits\RefreshComponentOnBroadcast; use App\Traits\RefreshComponentOnBroadcast;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Livewire\Component; use Livewire\Component;
@ -13,8 +13,12 @@ class ServersList extends Component
public function render(): View public function render(): View
{ {
/** @var User $user */
$user = auth()->user();
$servers = $user->currentProject->servers()->orderByDesc('created_at')->get();
return view('livewire.servers.servers-list', [ return view('livewire.servers.servers-list', [
'servers' => Server::all(), 'servers' => $servers,
]); ]);
} }
} }

View File

@ -10,8 +10,8 @@
class SslsList extends Component class SslsList extends Component
{ {
use RefreshComponentOnBroadcast;
use HasToast; use HasToast;
use RefreshComponentOnBroadcast;
public Site $site; public Site $site;

View File

@ -13,7 +13,7 @@ class Initialize extends InstallationJob
protected ?string $asUser; protected ?string $asUser;
public function __construct(Server $server, string $asUser = null) public function __construct(Server $server, ?string $asUser = null)
{ {
$this->server = $server->refresh(); $this->server = $server->refresh();
$this->asUser = $asUser; $this->asUser = $asUser;

56
app/Models/Project.php Normal file
View File

@ -0,0 +1,56 @@
<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* @property int $id
* @property int $user_id
* @property string $name
* @property Carbon $created_at
* @property Carbon $updated_at
* @property User $user
* @property Collection<Server> $servers
* @property Collection<NotificationChannel> $notificationChannels
*/
class Project extends Model
{
use HasFactory;
protected $fillable = [
'user_id',
'name',
];
public static function boot(): void
{
parent::boot();
static::deleting(function (Project $project) {
$project->servers()->each(function (Server $server) {
$server->delete();
});
});
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function servers(): HasMany
{
return $this->hasMany(Server::class);
}
public function notificationChannels(): HasMany
{
return $this->hasMany(NotificationChannel::class);
}
}

View File

@ -18,6 +18,7 @@
use Illuminate\Support\Str; use Illuminate\Support\Str;
/** /**
* @property int $project_id
* @property int $user_id * @property int $user_id
* @property string $name * @property string $name
* @property string $ssh_user * @property string $ssh_user
@ -38,6 +39,7 @@
* @property int $security_updates * @property int $security_updates
* @property int $progress * @property int $progress
* @property string $progress_step * @property string $progress_step
* @property Project $project
* @property User $creator * @property User $creator
* @property ServerProvider $serverProvider * @property ServerProvider $serverProvider
* @property ServerLog[] $logs * @property ServerLog[] $logs
@ -59,6 +61,7 @@ class Server extends AbstractModel
use HasFactory; use HasFactory;
protected $fillable = [ protected $fillable = [
'project_id',
'user_id', 'user_id',
'name', 'name',
'ssh_user', 'ssh_user',
@ -82,6 +85,7 @@ class Server extends AbstractModel
]; ];
protected $casts = [ protected $casts = [
'project_id' => 'integer',
'user_id' => 'integer', 'user_id' => 'integer',
'type_data' => 'json', 'type_data' => 'json',
'port' => 'integer', 'port' => 'integer',
@ -125,6 +129,11 @@ public static function boot(): void
}); });
} }
public function project(): BelongsTo
{
return $this->belongsTo(Project::class, 'project_id');
}
public function creator(): BelongsTo public function creator(): BelongsTo
{ {
return $this->belongsTo(User::class, 'user_id'); return $this->belongsTo(User::class, 'user_id');
@ -233,7 +242,7 @@ public function install(): void
// $this->team->notify(new ServerInstallationStarted($this)); // $this->team->notify(new ServerInstallationStarted($this));
} }
public function ssh(string $user = null): \App\Helpers\SSH|SSHFake public function ssh(?string $user = null): \App\Helpers\SSH|SSHFake
{ {
return SSH::init($this, $user); return SSH::init($this, $user);
} }
@ -263,7 +272,7 @@ public function provider(): \App\Contracts\ServerProvider
return new $providerClass($this); return new $providerClass($this);
} }
public function webserver(string $version = null): ?Service public function webserver(?string $version = null): ?Service
{ {
if (! $version) { if (! $version) {
return $this->defaultService('webserver'); return $this->defaultService('webserver');
@ -272,7 +281,7 @@ public function webserver(string $version = null): ?Service
return $this->service('webserver', $version); return $this->service('webserver', $version);
} }
public function database(string $version = null): ?Service public function database(?string $version = null): ?Service
{ {
if (! $version) { if (! $version) {
return $this->defaultService('database'); return $this->defaultService('database');
@ -281,7 +290,7 @@ public function database(string $version = null): ?Service
return $this->service('database', $version); return $this->service('database', $version);
} }
public function firewall(string $version = null): ?Service public function firewall(?string $version = null): ?Service
{ {
if (! $version) { if (! $version) {
return $this->defaultService('firewall'); return $this->defaultService('firewall');
@ -290,7 +299,7 @@ public function firewall(string $version = null): ?Service
return $this->service('firewall', $version); return $this->service('firewall', $version);
} }
public function processManager(string $version = null): ?Service public function processManager(?string $version = null): ?Service
{ {
if (! $version) { if (! $version) {
return $this->defaultService('process_manager'); return $this->defaultService('process_manager');
@ -299,7 +308,7 @@ public function processManager(string $version = null): ?Service
return $this->service('process_manager', $version); return $this->service('process_manager', $version);
} }
public function php(string $version = null): ?Service public function php(?string $version = null): ?Service
{ {
if (! $version) { if (! $version) {
return $this->defaultService('php'); return $this->defaultService('php');

View File

@ -33,7 +33,7 @@ public function provider(): SourceControlProvider
return new $providerClass($this); return new $providerClass($this);
} }
public function getRepo(string $repo = null): ?array public function getRepo(?string $repo = null): ?array
{ {
return $this->provider()->getRepo($repo); return $this->provider()->getRepo($repo);
} }

View File

@ -28,6 +28,9 @@
* @property Collection $tokens * @property Collection $tokens
* @property string $profile_photo_url * @property string $profile_photo_url
* @property string $timezone * @property string $timezone
* @property int $current_project_id
* @property Project $currentProject
* @property Collection<Project> $projects
*/ */
class User extends Authenticatable class User extends Authenticatable
{ {
@ -41,6 +44,7 @@ class User extends Authenticatable
'email', 'email',
'password', 'password',
'timezone', 'timezone',
'current_project_id',
]; ];
protected $hidden = [ protected $hidden = [
@ -53,6 +57,20 @@ class User extends Authenticatable
protected $appends = [ protected $appends = [
]; ];
public static function boot(): void
{
parent::boot();
static::created(function (User $user) {
$user->createDefaultProject();
});
}
public function servers(): HasMany
{
return $this->hasMany(Server::class);
}
public function sshKeys(): HasMany public function sshKeys(): HasMany
{ {
return $this->hasMany(SshKey::class); return $this->hasMany(SshKey::class);
@ -105,4 +123,36 @@ public function connectedSourceControls(): array
return $connectedSourceControls; return $connectedSourceControls;
} }
public function projects(): HasMany
{
return $this->hasMany(Project::class);
}
public function currentProject(): HasOne
{
return $this->HasOne(Project::class, 'id', 'current_project_id');
}
public function isMemberOfProject(Project $project): bool
{
return $project->user_id === $this->id;
}
public function createDefaultProject(): Project
{
$project = $this->projects()->first();
if (! $project) {
$project = new Project();
$project->user_id = $this->id;
$project->name = 'Default';
$project->save();
}
$this->current_project_id = $project->id;
$this->save();
return $project;
}
} }

View File

@ -63,7 +63,7 @@ public function data(array $input): array
/** /**
* @throws CouldNotConnectToProvider * @throws CouldNotConnectToProvider
*/ */
public function connect(array $credentials = null): bool public function connect(?array $credentials = null): bool
{ {
try { try {
$this->connectToEc2ClientTest($credentials); $this->connectToEc2ClientTest($credentials);

View File

@ -10,7 +10,7 @@ abstract class AbstractProvider implements ServerProvider
{ {
protected ?Server $server; protected ?Server $server;
public function __construct(Server $server = null) public function __construct(?Server $server = null)
{ {
$this->server = $server; $this->server = $server;
} }

View File

@ -42,7 +42,7 @@ public function data(array $input): array
return []; return [];
} }
public function connect(array $credentials = null): bool public function connect(?array $credentials = null): bool
{ {
return true; return true;
} }

View File

@ -58,7 +58,7 @@ public function data(array $input): array
/** /**
* @throws CouldNotConnectToProvider * @throws CouldNotConnectToProvider
*/ */
public function connect(array $credentials = null): bool public function connect(?array $credentials = null): bool
{ {
$connect = Http::withToken($credentials['token'])->get($this->apiUrl.'/account'); $connect = Http::withToken($credentials['token'])->get($this->apiUrl.'/account');
if (! $connect->ok()) { if (! $connect->ok()) {

View File

@ -45,7 +45,7 @@ public function data(array $input): array
/** /**
* @throws CouldNotConnectToProvider * @throws CouldNotConnectToProvider
*/ */
public function connect(array $credentials = null): bool public function connect(?array $credentials = null): bool
{ {
$connect = Http::withToken($credentials['token'])->get($this->apiUrl.'/servers'); $connect = Http::withToken($credentials['token'])->get($this->apiUrl.'/servers');
if (! $connect->ok()) { if (! $connect->ok()) {

View File

@ -57,7 +57,7 @@ public function data(array $input): array
/** /**
* @throws CouldNotConnectToProvider * @throws CouldNotConnectToProvider
*/ */
public function connect(array $credentials = null): bool public function connect(?array $credentials = null): bool
{ {
$connect = Http::withToken($credentials['token'])->get($this->apiUrl.'/account'); $connect = Http::withToken($credentials['token'])->get($this->apiUrl.'/account');
if (! $connect->ok()) { if (! $connect->ok()) {

View File

@ -59,7 +59,7 @@ public function data(array $input): array
/** /**
* @throws CouldNotConnectToProvider * @throws CouldNotConnectToProvider
*/ */
public function connect(array $credentials = null): bool public function connect(?array $credentials = null): bool
{ {
$connect = Http::withToken($credentials['token'])->get($this->apiUrl.'/account'); $connect = Http::withToken($credentials['token'])->get($this->apiUrl.'/account');
if (! $connect->ok()) { if (! $connect->ok()) {

View File

@ -16,7 +16,7 @@ public function __construct(Server $server)
$this->server = $server; $this->server = $server;
} }
protected function progress(int $percentage, string $step = null): Closure protected function progress(int $percentage, ?string $step = null): Closure
{ {
return function () use ($percentage, $step) { return function () use ($percentage, $step) {
$this->server->progress = $percentage; $this->server->progress = $percentage;

View File

@ -47,7 +47,7 @@ public function create(
/** /**
* @throws Throwable * @throws Throwable
*/ */
public function delete(int $id, int $siteId = null): void public function delete(int $id, ?int $siteId = null): void
{ {
$this->service->server->ssh()->exec( $this->service->server->ssh()->exec(
new DeleteWorkerCommand($id), new DeleteWorkerCommand($id),
@ -59,7 +59,7 @@ public function delete(int $id, int $siteId = null): void
/** /**
* @throws Throwable * @throws Throwable
*/ */
public function restart(int $id, int $siteId = null): void public function restart(int $id, ?int $siteId = null): void
{ {
$this->service->server->ssh()->exec( $this->service->server->ssh()->exec(
new RestartWorkerCommand($id), new RestartWorkerCommand($id),
@ -71,7 +71,7 @@ public function restart(int $id, int $siteId = null): void
/** /**
* @throws Throwable * @throws Throwable
*/ */
public function stop(int $id, int $siteId = null): void public function stop(int $id, ?int $siteId = null): void
{ {
$this->service->server->ssh()->exec( $this->service->server->ssh()->exec(
new StopWorkerCommand($id), new StopWorkerCommand($id),
@ -83,7 +83,7 @@ public function stop(int $id, int $siteId = null): void
/** /**
* @throws Throwable * @throws Throwable
*/ */
public function start(int $id, int $siteId = null): void public function start(int $id, ?int $siteId = null): void
{ {
$this->service->server->ssh()->exec( $this->service->server->ssh()->exec(
new StartWorkerCommand($id), new StartWorkerCommand($id),

View File

@ -52,17 +52,17 @@ public function createFields(array $input): array
{ {
return [ return [
'web_directory' => $input['web_directory'] ?? '', 'web_directory' => $input['web_directory'] ?? '',
'source_control_id' => $input['source_control'], 'source_control_id' => $input['source_control'] ?? '',
'repository' => $input['repository'], 'repository' => $input['repository'] ?? '',
'branch' => $input['branch'], 'branch' => $input['branch'] ?? '',
]; ];
} }
public function data(array $input): array public function data(array $input): array
{ {
return [ return [
'composer' => (bool) $input['composer'], 'composer' => isset($input['composer']) && $input['composer'],
'php_version' => $input['php_version'], 'php_version' => $input['php_version'] ?? '',
]; ];
} }

View File

@ -24,7 +24,7 @@ public function connect(): bool
/** /**
* @throws Exception * @throws Exception
*/ */
public function getRepo(string $repo = null): mixed public function getRepo(?string $repo = null): mixed
{ {
$res = Http::withToken($this->sourceControl->access_token) $res = Http::withToken($this->sourceControl->access_token)
->get($this->apiUrl."/repositories/$repo"); ->get($this->apiUrl."/repositories/$repo");

View File

@ -25,7 +25,7 @@ public function connect(): bool
/** /**
* @throws Exception * @throws Exception
*/ */
public function getRepo(string $repo = null): mixed public function getRepo(?string $repo = null): mixed
{ {
if ($repo) { if ($repo) {
$url = $this->apiUrl.'/repos/'.$repo; $url = $this->apiUrl.'/repos/'.$repo;

View File

@ -25,7 +25,7 @@ public function connect(): bool
/** /**
* @throws Exception * @throws Exception
*/ */
public function getRepo(string $repo = null): mixed public function getRepo(?string $repo = null): mixed
{ {
$repository = $repo ? urlencode($repo) : null; $repository = $repo ? urlencode($repo) : null;
$res = Http::withToken($this->sourceControl->access_token) $res = Http::withToken($this->sourceControl->access_token)

View File

@ -15,7 +15,7 @@ class SSHFake
protected string $output = ''; protected string $output = '';
public function init(Server $server, string $asUser = null): self public function init(Server $server, ?string $asUser = null): self
{ {
return $this; return $this;
} }
@ -47,7 +47,7 @@ public function assertExecuted(array|string $commands): void
PHPUnit::assertTrue(true, $allExecuted); PHPUnit::assertTrue(true, $allExecuted);
} }
public function exec(string|array|SSHCommand $commands, string $log = '', int $siteId = null): string public function exec(string|array|SSHCommand $commands, string $log = '', ?int $siteId = null): string
{ {
if (! is_array($commands)) { if (! is_array($commands)) {
$commands = [$commands]; $commands = [$commands];

View File

@ -16,6 +16,7 @@
"laravel/tinker": "^2.8", "laravel/tinker": "^2.8",
"livewire/livewire": "^2.12", "livewire/livewire": "^2.12",
"phpseclib/phpseclib": "~3.0", "phpseclib/phpseclib": "~3.0",
"opcodesio/log-viewer": "^2.5",
"ext-ftp": "*" "ext-ftp": "*"
}, },
"require-dev": { "require-dev": {
@ -24,7 +25,6 @@
"laravel/sail": "^1.18", "laravel/sail": "^1.18",
"mockery/mockery": "^1.4.4", "mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0", "nunomaduro/collision": "^7.0",
"opcodesio/log-viewer": "^2.5",
"phpunit/phpunit": "^10.0", "phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^2.0" "spatie/laravel-ignition": "^2.0"
}, },

2188
composer.lock generated

File diff suppressed because it is too large Load Diff

217
config/log-viewer.php Normal file
View File

@ -0,0 +1,217 @@
<?php
use Opcodes\LogViewer\Level;
return [
/*
|--------------------------------------------------------------------------
| Log Viewer
|--------------------------------------------------------------------------
| Log Viewer can be disabled, so it's no longer accessible via browser.
|
*/
'enabled' => env('LOG_VIEWER_ENABLED', true),
/*
|--------------------------------------------------------------------------
| Log Viewer Domain
|--------------------------------------------------------------------------
| You may change the domain where Log Viewer should be active.
| If the domain is empty, all domains will be valid.
|
*/
'route_domain' => null,
/*
|--------------------------------------------------------------------------
| Log Viewer Route
|--------------------------------------------------------------------------
| Log Viewer will be available under this URL.
|
*/
'route_path' => 'log-viewer',
/*
|--------------------------------------------------------------------------
| Back to system URL
|--------------------------------------------------------------------------
| When set, displays a link to easily get back to this URL.
| Set to `null` to hide this link.
|
| Optional label to display for the above URL.
|
*/
'back_to_system_url' => config('app.url', null),
'back_to_system_label' => null, // Displayed by default: "Back to {{ app.name }}"
/*
|--------------------------------------------------------------------------
| Log Viewer time zone.
|--------------------------------------------------------------------------
| The time zone in which to display the times in the UI. Defaults to
| the application's timezone defined in config/app.php.
|
*/
'timezone' => null,
/*
|--------------------------------------------------------------------------
| Log Viewer route middleware.
|--------------------------------------------------------------------------
| Optional middleware to use when loading the initial Log Viewer page.
|
*/
'middleware' => [
'web',
\Opcodes\LogViewer\Http\Middleware\AuthorizeLogViewer::class,
'auth',
],
/*
|--------------------------------------------------------------------------
| Log Viewer API middleware.
|--------------------------------------------------------------------------
| Optional middleware to use on every API request. The same API is also
| used from within the Log Viewer user interface.
|
*/
'api_middleware' => [
\Opcodes\LogViewer\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\Opcodes\LogViewer\Http\Middleware\AuthorizeLogViewer::class,
],
/*
|--------------------------------------------------------------------------
| Log Viewer Remote hosts.
|--------------------------------------------------------------------------
| Log Viewer supports viewing Laravel logs from remote hosts. They must
| be running Log Viewer as well. Below you can define the hosts you
| would like to show in this Log Viewer instance.
|
*/
'hosts' => [
'local' => [
'name' => ucfirst(env('APP_ENV', 'local')),
],
// 'staging' => [
// 'name' => 'Staging',
// 'host' => 'https://staging.example.com/log-viewer',
// 'auth' => [ // Example of HTTP Basic auth
// 'username' => 'username',
// 'password' => 'password',
// ],
// ],
//
// 'production' => [
// 'name' => 'Production',
// 'host' => 'https://example.com/log-viewer',
// 'auth' => [ // Example of Bearer token auth
// 'token' => env('LOG_VIEWER_PRODUCTION_TOKEN'),
// ],
// 'headers' => [
// 'X-Foo' => 'Bar',
// ],
// ],
],
/*
|--------------------------------------------------------------------------
| Include file patterns
|--------------------------------------------------------------------------
|
*/
'include_files' => [
'*.log',
'**/*.log',
// '/absolute/paths/supported',
],
/*
|--------------------------------------------------------------------------
| Exclude file patterns.
|--------------------------------------------------------------------------
| This will take precedence over included files.
|
*/
'exclude_files' => [
// 'my_secret.log'
],
/*
|--------------------------------------------------------------------------
| Shorter stack trace filters.
|--------------------------------------------------------------------------
| Lines containing any of these strings will be excluded from the full log.
| This setting is only active when the function is enabled via the user interface.
|
*/
'shorter_stack_trace_excludes' => [
'/vendor/symfony/',
'/vendor/laravel/framework/',
'/vendor/barryvdh/laravel-debugbar/',
],
/*
|--------------------------------------------------------------------------
| Log matching patterns
|--------------------------------------------------------------------------
| Regexes for matching log files
|
*/
'patterns' => [
'laravel' => [
'log_matching_regex' => '/^\[(\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}\.?(\d{6}([\+-]\d\d:\d\d)?)?)\].*/',
/**
* This pattern, used for processing Laravel logs, returns these results:
* $matches[0] - the full log line being tested.
* $matches[1] - full timestamp between the square brackets (includes microseconds and timezone offset)
* $matches[2] - timestamp microseconds, if available
* $matches[3] - timestamp timezone offset, if available
* $matches[4] - contents between timestamp and the severity level
* $matches[5] - environment (local, production, etc)
* $matches[6] - log severity (info, debug, error, etc)
* $matches[7] - the log text, the rest of the text.
*/
'log_parsing_regex' => '/^\[(\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}\.?(\d{6}([\+-]\d\d:\d\d)?)?)\](.*?(\w+)\.|.*?)('
.implode('|', array_filter(Level::caseValues()))
.')?: (.*?)( in [\/].*?:[0-9]+)?$/is',
],
],
/*
|--------------------------------------------------------------------------
| Cache driver
|--------------------------------------------------------------------------
| Cache driver to use for storing the log indices. Indices are used to speed up
| log navigation. Defaults to your application's default cache driver.
|
*/
'cache_driver' => env('LOG_VIEWER_CACHE_DRIVER', null),
/*
|--------------------------------------------------------------------------
| Chunk size when scanning log files lazily
|--------------------------------------------------------------------------
| The size in MB of files to scan before updating the progress bar when searching across all files.
|
*/
'lazy_scan_chunk_size_in_mb' => 50,
];

View File

@ -0,0 +1,25 @@
<?php
namespace Database\Factories;
use App\Models\Project;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
/**
* @extends Factory<Project>
*/
class ProjectFactory extends Factory
{
protected $model = Project::class;
public function definition(): array
{
return [
'user_id' => $this->faker->randomNumber(),
'name' => $this->faker->name(),
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
];
}
}

View File

@ -0,0 +1,23 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('projects', function (Blueprint $table) {
$table->id();
$table->bigInteger('user_id');
$table->string('name');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('projects');
}
};

View File

@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('servers', function (Blueprint $table) {
$table->unsignedBigInteger('project_id')->nullable()->after('id');
});
}
public function down(): void
{
Schema::table('servers', function (Blueprint $table) {
$table->dropColumn('project_id');
});
}
};

View File

@ -0,0 +1,27 @@
<?php
use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->unsignedBigInteger('current_project_id')->nullable()->after('timezone');
});
User::query()->each(function (User $user) {
$project = $user->createDefaultProject();
$user->servers()->update(['project_id' => $project->id]);
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('current_project_id');
});
}
};

View File

@ -22,6 +22,7 @@ public function run(): void
]); ]);
$server = Server::factory()->create([ $server = Server::factory()->create([
'user_id' => $user->id, 'user_id' => $user->id,
'project_id' => $user->currentProject->id,
]); ]);
$server->services()->create([ $server->services()->create([
'type' => 'database', 'type' => 'database',

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"resources/css/app.css": { "resources/css/app.css": {
"file": "assets/app-328222da.css", "file": "assets/app-f482c864.css",
"isEntry": true, "isEntry": true,
"src": "resources/css/app.css" "src": "resources/css/app.css"
}, },

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"/app.js": "/app.js?id=2ca3fa12f273bd645611f1acf3d81355", "/app.js": "/app.js?id=5f574f36f456b103dffcfa21d5612785",
"/app.css": "/app.css?id=93151d8b186ef7758df8582425ff8082", "/app.css": "/app.css?id=b701a4344131bb2c00e9f0b1ef1ab3c1",
"/img/log-viewer-128.png": "/img/log-viewer-128.png?id=d576c6d2e16074d3f064e60fe4f35166", "/img/log-viewer-128.png": "/img/log-viewer-128.png?id=d576c6d2e16074d3f064e60fe4f35166",
"/img/log-viewer-32.png": "/img/log-viewer-32.png?id=f8ec67d10f996aa8baf00df3b61eea6d", "/img/log-viewer-32.png": "/img/log-viewer-32.png?id=f8ec67d10f996aa8baf00df3b61eea6d",
"/img/log-viewer-64.png": "/img/log-viewer-64.png?id=8902d596fc883ca9eb8105bb683568c6" "/img/log-viewer-64.png": "/img/log-viewer-64.png?id=8902d596fc883ca9eb8105bb683568c6"

File diff suppressed because one or more lines are too long

View File

@ -37,16 +37,25 @@
<div <div
class="left-0 top-0 min-h-screen w-64 flex-none bg-gray-800 dark:bg-gray-800/50 p-3 dark:border-r-2 dark:border-gray-800"> class="left-0 top-0 min-h-screen w-64 flex-none bg-gray-800 dark:bg-gray-800/50 p-3 dark:border-r-2 dark:border-gray-800">
<div class="h-16 block"> <div class="h-16 block">
<div class="flex items-center justify-start text-3xl font-extrabold text-white"> <div class="flex items-center justify-start text-2xl font-extrabold text-white">
<x-application-logo class="w-10 h-10 rounded-md"/> <x-application-logo class="w-7 h-7 rounded-md" />
<span class="ml-1">Deploy</span> <span class="ml-1">Deploy</span>
</div> </div>
</div> </div>
<div class="mb-5 space-y-2"> <div class="mb-5">
<div class="uppercase text-gray-300 text-sm font-semibold">{{ __("Projects") }}</div>
<div class="mt-2">
@include('layouts.partials.project-select', ['project' => auth()->user()->currentProject])
</div>
<div class="mt-5 uppercase text-gray-300 text-sm font-semibold">{{ __("Servers") }}</div>
<div class="mt-2">
@include('layouts.partials.server-select', ['server' => isset($server) ? $server : null]) @include('layouts.partials.server-select', ['server' => isset($server) ? $server : null])
</div>
@if (isset($server)) @if (isset($server))
<div class="mt-3 space-y-1">
<x-sidebar-link :href="route('servers.show', ['server' => $server])" :active="request()->routeIs('servers.show')"> <x-sidebar-link :href="route('servers.show', ['server' => $server])" :active="request()->routeIs('servers.show')">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-6 h-6"> stroke="currentColor" class="w-6 h-6">
@ -142,6 +151,7 @@ class="left-0 top-0 min-h-screen w-64 flex-none bg-gray-800 dark:bg-gray-800/50
</svg> </svg>
<span class="ml-2 text-gray-50">{{ __('Logs') }}</span> <span class="ml-2 text-gray-50">{{ __('Logs') }}</span>
</x-sidebar-link> </x-sidebar-link>
</div>
@endif @endif
</div> </div>
</div> </div>

View File

@ -20,11 +20,14 @@
<div class="min-h-screen flex flex-col sm:justify-center items-center pt-6 sm:pt-0 bg-gray-100 dark:bg-gray-900"> <div class="min-h-screen flex flex-col sm:justify-center items-center pt-6 sm:pt-0 bg-gray-100 dark:bg-gray-900">
<div> <div>
<a href="/"> <a href="/">
<x-application-logo class="w-20 h-20 fill-current text-gray-500 rounded-lg" /> <div class="flex items-center justify-start text-3xl font-extrabold">
<x-application-logo class="w-9 h-9 rounded-md" />
<span class="ml-1">Deploy</span>
</div>
</a> </a>
</div> </div>
<div class="w-full sm:max-w-md mt-6 px-6 py-4 bg-white dark:bg-gray-800 shadow-md overflow-hidden rounded-lg"> <div class="w-full sm:max-w-md mt-10 px-6 py-4 bg-white dark:bg-gray-800 shadow-md overflow-hidden rounded-lg">
{{ $slot }} {{ $slot }}
</div> </div>
</div> </div>

View File

@ -0,0 +1,90 @@
<div x-data="projectCombobox()">
<div class="relative">
<div @click="open = !open" class="z-0 w-full cursor-pointer px-4 py-3 pr-10 text-md leading-5 text-gray-100 focus:ring-1 focus:ring-gray-700 bg-gray-900 rounded-md h-10 flex items-center" x-text="selected.name ?? 'Select Project'"></div>
<button type="button" @click="open = !open" class="z-0 absolute inset-y-0 right-0 flex items-center pr-2">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" class="h-5 w-5 text-gray-400"><path fill-rule="evenodd" d="M10 3a.75.75 0 01.55.24l3.25 3.5a.75.75 0 11-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 01-1.1-1.02l3.25-3.5A.75.75 0 0110 3zm-3.76 9.2a.75.75 0 011.06.04l2.7 2.908 2.7-2.908a.75.75 0 111.1 1.02l-3.25 3.5a.75.75 0 01-1.1 0l-3.25-3.5a.75.75 0 01.04-1.06z" clip-rule="evenodd"></path></svg>
</button>
<div
x-show="open"
@click.away="open = false"
class="z-10 absolute mt-1 w-full overflow-auto rounded-md pb-1 bg-white dark:bg-gray-700 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm">
<div class="p-2 relative">
<input x-model="query"
@input="filterProjectsAndOpen"
placeholder="Filter"
class="w-full py-2 pl-3 pr-10 text-sm leading-5 dark:text-gray-100 focus:ring-1 focus:ring-gray-400 dark:focus:ring-800 bg-gray-200 dark:bg-gray-900 rounded-md"
>
</div>
<div class="relative max-h-[350px] overflow-y-auto">
<template x-for="(project, index) in filteredProjects" :key="index">
<div
@click="selectProject(project); open = false"
:class="project.id === selected.id ? 'cursor-default bg-primary-600 text-white' : 'cursor-pointer'"
class="relative select-none py-2 px-4 text-gray-700 dark:text-white hover:bg-primary-600 hover:text-white">
<span class="block truncate" x-text="project.name"></span>
<template x-if="project.id === selected.id">
<span class="absolute inset-y-0 right-0 flex items-center pr-3 text-white">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" class="h-5 w-5"><path fill-rule="evenodd" d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z" clip-rule="evenodd"></path></svg>
</span>
</template>
</div>
</template>
</div>
<div
x-show="filteredProjects.length === 0"
class="relative cursor-default select-none py-2 px-4 text-gray-700 dark:text-white block truncate">
No projects found!
</div>
<div class="py-1">
<hr class="border-gray-300 dark:border-gray-600">
</div>
<div>
<a
href="{{ route('projects') }}"
class="relative select-none py-2 px-4 text-gray-700 dark:text-white hover:bg-primary-600 hover:text-white block cursor-pointer">
<span class="block truncate">Projects List</span>
</a>
</div>
<div>
<a
href="{{ route('projects', ['create' => true]) }}"
class="relative select-none py-2 px-4 text-gray-700 dark:text-white hover:bg-primary-600 hover:text-white block cursor-pointer">
<span class="block truncate">Create a Project</span>
</a>
</div>
</div>
</div>
</div>
<script>
function projectCombobox() {
const projects = @json(auth()->user()->projects()->select('id', 'name')->get());
return {
open: false,
query: '',
projects: projects,
selected: @if(isset($project)) @json($project->only('id', 'name')) @else {} @endif,
filteredProjects: projects,
selectProject(project) {
if (this.selected.id !== project.id) {
this.selected = project;
window.location.href = '{{ url('/settings/projects/') }}/' + project.id
}
},
filterProjectsAndOpen() {
if (this.query === '') {
this.filteredProjects = this.projects;
this.open = false;
} else {
this.filteredProjects = this.projects.filter((project) =>
project.name
.toLowerCase()
.replace(/\s+/g, '')
.includes(this.query.toLowerCase().replace(/\s+/g, ''))
);
this.open = true;
}
},
};
}
</script>

View File

@ -1,13 +1,13 @@
<div x-data="serverCombobox()"> <div x-data="serverCombobox()">
<div class="relative"> <div class="relative">
<div @click="open = !open" class="w-full cursor-pointer px-4 py-3 pr-10 text-md leading-5 text-gray-100 focus:ring-1 focus:ring-gray-700 bg-gray-900 rounded-md h-10 flex items-center" x-text="selected.name ?? 'Select Server'"></div> <div @click="open = !open" class="z-0 w-full cursor-pointer px-4 py-3 pr-10 text-md leading-5 text-gray-100 focus:ring-1 focus:ring-gray-700 bg-gray-900 rounded-md h-10 flex items-center" x-text="selected.name ?? 'Select Server'"></div>
<button type="button" @click="open = !open" class="absolute inset-y-0 right-0 flex items-center pr-2"> <button type="button" @click="open = !open" class="z-0 absolute inset-y-0 right-0 flex items-center pr-2">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" class="h-5 w-5 text-gray-400"><path fill-rule="evenodd" d="M10 3a.75.75 0 01.55.24l3.25 3.5a.75.75 0 11-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 01-1.1-1.02l3.25-3.5A.75.75 0 0110 3zm-3.76 9.2a.75.75 0 011.06.04l2.7 2.908 2.7-2.908a.75.75 0 111.1 1.02l-3.25 3.5a.75.75 0 01-1.1 0l-3.25-3.5a.75.75 0 01.04-1.06z" clip-rule="evenodd"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" class="h-5 w-5 text-gray-400"><path fill-rule="evenodd" d="M10 3a.75.75 0 01.55.24l3.25 3.5a.75.75 0 11-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 01-1.1-1.02l3.25-3.5A.75.75 0 0110 3zm-3.76 9.2a.75.75 0 011.06.04l2.7 2.908 2.7-2.908a.75.75 0 111.1 1.02l-3.25 3.5a.75.75 0 01-1.1 0l-3.25-3.5a.75.75 0 01.04-1.06z" clip-rule="evenodd"></path></svg>
</button> </button>
<div <div
x-show="open" x-show="open"
@click.away="open = false" @click.away="open = false"
class="absolute mt-1 w-full overflow-auto rounded-md pb-1 bg-white dark:bg-gray-700 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm"> class="z-10 absolute mt-1 w-full overflow-auto rounded-md pb-1 bg-white dark:bg-gray-700 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm">
<div class="p-2 relative"> <div class="p-2 relative">
<input x-model="query" <input x-model="query"
@input="filterServersAndOpen" @input="filterServersAndOpen"
@ -58,7 +58,7 @@ class="relative select-none py-2 px-4 text-gray-700 dark:text-white hover:bg-pri
<script> <script>
function serverCombobox() { function serverCombobox() {
const servers = @json(\App\Models\Server::query()->select('id', 'name')->get()); const servers = @json(auth()->user()->currentProject->servers()->select('id', 'name')->get());
return { return {
open: false, open: false,
query: '', query: '',

View File

@ -16,6 +16,12 @@
</svg> </svg>
{{ __('Profile') }} {{ __('Profile') }}
</x-secondary-sidebar-link> </x-secondary-sidebar-link>
<x-secondary-sidebar-link :href="route('projects')" :active="request()->routeIs('projects')">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 mr-2">
<path stroke-linecap="round" stroke-linejoin="round" d="m7.875 14.25 1.214 1.942a2.25 2.25 0 0 0 1.908 1.058h2.006c.776 0 1.497-.4 1.908-1.058l1.214-1.942M2.41 9h4.636a2.25 2.25 0 0 1 1.872 1.002l.164.246a2.25 2.25 0 0 0 1.872 1.002h2.092a2.25 2.25 0 0 0 1.872-1.002l.164-.246A2.25 2.25 0 0 1 16.954 9h4.636M2.41 9a2.25 2.25 0 0 0-.16.832V12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 12V9.832c0-.287-.055-.57-.16-.832M2.41 9a2.25 2.25 0 0 1 .382-.632l3.285-3.832a2.25 2.25 0 0 1 1.708-.786h8.43c.657 0 1.281.287 1.709.786l3.284 3.832c.163.19.291.404.382.632M4.5 20.25h15A2.25 2.25 0 0 0 21.75 18v-2.625c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125V18a2.25 2.25 0 0 0 2.25 2.25Z" />
</svg>
{{ __('Projects') }}
</x-secondary-sidebar-link>
<x-secondary-sidebar-link :href="route('server-providers')" :active="request()->routeIs('server-providers')"> <x-secondary-sidebar-link :href="route('server-providers')" :active="request()->routeIs('server-providers')">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 mr-2"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 mr-2">
<path stroke-linecap="round" stroke-linejoin="round" d="M5.25 14.25h13.5m-13.5 0a3 3 0 01-3-3m3 3a3 3 0 100 6h13.5a3 3 0 100-6m-16.5-3a3 3 0 013-3h13.5a3 3 0 013 3m-19.5 0a4.5 4.5 0 01.9-2.7L5.737 5.1a3.375 3.375 0 012.7-1.35h7.126c1.062 0 2.062.5 2.7 1.35l2.587 3.45a4.5 4.5 0 01.9 2.7m0 0a3 3 0 01-3 3m0 3h.008v.008h-.008v-.008zm0-6h.008v.008h-.008v-.008zm-3 6h.008v.008h-.008v-.008zm0-6h.008v.008h-.008v-.008z" /> <path stroke-linecap="round" stroke-linejoin="round" d="M5.25 14.25h13.5m-13.5 0a3 3 0 01-3-3m3 3a3 3 0 100 6h13.5a3 3 0 100-6m-16.5-3a3 3 0 013-3h13.5a3 3 0 013 3m-19.5 0a4.5 4.5 0 01.9-2.7L5.737 5.1a3.375 3.375 0 012.7-1.35h7.126c1.062 0 2.062.5 2.7 1.35l2.587 3.45a4.5 4.5 0 01.9 2.7m0 0a3 3 0 01-3 3m0 3h.008v.008h-.008v-.008zm0-6h.008v.008h-.008v-.008zm-3 6h.008v.008h-.008v-.008zm0-6h.008v.008h-.008v-.008z" />

View File

@ -0,0 +1,31 @@
<div>
<x-primary-button x-data="" x-on:click.prevent="$dispatch('open-modal', 'create-project')">
{{ __('Connect') }}
</x-primary-button>
<x-modal name="create-project" :show="$open">
<form wire:submit.prevent="create" class="p-6">
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
{{ __('Create Project') }}
</h2>
<div class="mt-6">
<x-input-label for="name" value="Name" />
<x-text-input wire:model.defer="inputs.name" id="name" name="name" type="text" class="mt-1 w-full" />
@error('name')
<x-input-error class="mt-2" :messages="$message" />
@enderror
</div>
<div class="mt-6 flex justify-end">
<x-secondary-button type="button" x-on:click="$dispatch('close')">
{{ __('Cancel') }}
</x-secondary-button>
<x-primary-button class="ml-3" @created.window="$dispatch('close')">
{{ __('Create') }}
</x-primary-button>
</div>
</form>
</x-modal>
</div>

View File

@ -0,0 +1,31 @@
<div>
<x-icon-button x-data="" x-on:click.prevent="$dispatch('open-modal', 'edit-project-{{ $project->id }}')">
{{ __('Edit') }}
</x-icon-button>
<x-modal name="edit-project-{{ $project->id }}">
<form wire:submit.prevent="save" class="p-6 text-left">
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
{{ __('Edit Project') }}
</h2>
<div class="mt-6">
<x-input-label for="edit-name-{{ $project->id }}" value="Name" />
<x-text-input wire:model.defer="inputs.name" id="edit-name-{{ $project->id }}" name="name" type="text" class="mt-1 w-full" />
@error('name')
<x-input-error class="mt-2" :messages="$message" />
@enderror
</div>
<div class="mt-6 flex justify-end">
<x-secondary-button type="button" x-on:click="$dispatch('close')">
{{ __('Cancel') }}
</x-secondary-button>
<x-primary-button class="ml-3" @created.window="$dispatch('close')">
{{ __('Save') }}
</x-primary-button>
</div>
</form>
</x-modal>
</div>

View File

@ -0,0 +1,38 @@
<div>
<x-card-header>
<x-slot name="title">{{ __("Projects") }}</x-slot>
<x-slot name="description">{{ __("Here you can manage your projects") }}</x-slot>
<x-slot name="aside">
<livewire:projects.create-project />
</x-slot>
</x-card-header>
<div x-data="" class="space-y-3">
@foreach($projects as $project)
<x-item-card>
<div class="ml-3 flex flex-grow flex-col items-start justify-center">
<div class="mb-1 flex items-center">
{{ $project->name }}
@if($project->id == auth()->user()->current_project_id)
<x-status status="success" class="ml-1">{{ __('Current') }}</x-status>
@endif
</div>
<span class="text-sm text-gray-400">
<x-datetime :value="$project->created_at" />
</span>
</div>
<div class="flex items-center">
<livewire:projects.edit-project :project="$project" />
<x-icon-button x-on:click="$wire.deleteId = '{{ $project->id }}'; $dispatch('open-modal', 'delete-project')">
Delete
</x-icon-button>
</div>
</x-item-card>
@endforeach
<x-confirm-modal
name="delete-project"
:title="__('Confirm')"
:description="__('Deleting a project will delete all of its servers, sites, etc. Are you sure you want to delete this project?')"
method="delete"
/>
</div>
</div>

View File

@ -0,0 +1,5 @@
<x-profile-layout>
<x-slot name="pageTitle">{{ __("Projects") }}</x-slot>
<livewire:projects.projects-list />
</x-profile-layout>

View File

@ -5,6 +5,7 @@
use App\Http\Controllers\DatabaseController; use App\Http\Controllers\DatabaseController;
use App\Http\Controllers\FirewallController; use App\Http\Controllers\FirewallController;
use App\Http\Controllers\PHPController; use App\Http\Controllers\PHPController;
use App\Http\Controllers\ProjectController;
use App\Http\Controllers\ServerController; use App\Http\Controllers\ServerController;
use App\Http\Controllers\ServerSettingController; use App\Http\Controllers\ServerSettingController;
use App\Http\Controllers\ServiceController; use App\Http\Controllers\ServiceController;
@ -19,6 +20,8 @@
Route::middleware('auth')->group(function () { Route::middleware('auth')->group(function () {
Route::prefix('/settings')->group(function () { Route::prefix('/settings')->group(function () {
Route::view('/profile', 'profile.index')->name('profile'); Route::view('/profile', 'profile.index')->name('profile');
Route::get('/projects', [ProjectController::class, 'index'])->name('projects');
Route::get('/projects/{projectId}', [ProjectController::class, 'switch'])->name('projects.switch');
Route::view('/server-providers', 'server-providers.index')->name('server-providers'); Route::view('/server-providers', 'server-providers.index')->name('server-providers');
Route::view('/source-controls', 'source-controls.index')->name('source-controls'); Route::view('/source-controls', 'source-controls.index')->name('source-controls');
Route::view('/storage-providers', 'storage-providers.index')->name('storage-providers'); Route::view('/storage-providers', 'storage-providers.index')->name('storage-providers');

View File

@ -0,0 +1,83 @@
<?php
namespace Feature\Http;
use App\Http\Livewire\Projects\CreateProject;
use App\Http\Livewire\Projects\EditProject;
use App\Http\Livewire\Projects\ProjectsList;
use App\Models\Project;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class ProjectsTest extends TestCase
{
use RefreshDatabase;
public function test_create_project(): void
{
$this->actingAs($this->user);
Livewire::test(CreateProject::class)
->set('inputs.name', 'test')
->call('create')
->assertSuccessful();
$this->assertDatabaseHas('projects', [
'name' => 'test',
]);
}
public function test_see_projects_list(): void
{
$this->actingAs($this->user);
$project = Project::factory()->create([
'user_id' => $this->user->id,
]);
Livewire::test(ProjectsList::class)
->assertSee([
$project->name,
]);
}
public function test_delete_project(): void
{
$this->actingAs($this->user);
$project = Project::factory()->create([
'user_id' => $this->user->id,
]);
Livewire::test(ProjectsList::class)
->set('deleteId', $project->id)
->call('delete')
->assertSuccessful();
$this->assertDatabaseMissing('projects', [
'id' => $project->id,
]);
}
public function test_edit_project(): void
{
$this->actingAs($this->user);
$project = Project::factory()->create([
'user_id' => $this->user->id,
]);
Livewire::test(EditProject::class, [
'project' => $project,
])
->set('inputs.name', 'test')
->call('save')
->assertSuccessful();
$this->assertDatabaseHas('projects', [
'id' => $project->id,
'name' => 'test',
]);
}
}