mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
f06b8f7d20 | |||
f120a570e8 | |||
2d7f225ff2 | |||
31bd146239 | |||
10a6bb57a8 |
27
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
27
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
12
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
12
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: feature
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
To request a feature or suggest an idea please add it to the feedback boards
|
||||
|
||||
https://features.vitodeploy.com/
|
@ -17,9 +17,12 @@ public function update(Service $service, string $ini): void
|
||||
{
|
||||
$tmpName = Str::random(10).strtotime('now');
|
||||
try {
|
||||
Storage::disk('local')->put($tmpName, $ini);
|
||||
/** @var \Illuminate\Filesystem\FilesystemAdapter $storageDisk */
|
||||
$storageDisk = Storage::disk('local');
|
||||
|
||||
$storageDisk->put($tmpName, $ini);
|
||||
$service->server->ssh('root')->upload(
|
||||
Storage::disk('local')->path($tmpName),
|
||||
$storageDisk->path($tmpName),
|
||||
"/etc/php/$service->version/cli/php.ini"
|
||||
);
|
||||
$this->deleteTempFile($tmpName);
|
||||
|
36
app/Actions/Projects/CreateProject.php
Normal file
36
app/Actions/Projects/CreateProject.php
Normal 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();
|
||||
}
|
||||
}
|
31
app/Actions/Projects/DeleteProject.php
Normal file
31
app/Actions/Projects/DeleteProject.php
Normal 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();
|
||||
}
|
||||
}
|
33
app/Actions/Projects/UpdateProject.php
Normal file
33
app/Actions/Projects/UpdateProject.php
Normal 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();
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ public function create(User $creator, array $input): Server
|
||||
$this->validateInputs($input);
|
||||
|
||||
$server = new Server([
|
||||
'project_id' => $creator->currentProject->id,
|
||||
'user_id' => $creator->id,
|
||||
'name' => $input['name'],
|
||||
'ssh_user' => config('core.server_providers_default_user')[$input['provider']][$input['os']],
|
||||
|
@ -9,7 +9,9 @@ interface Webserver
|
||||
{
|
||||
public function createVHost(Site $site): void;
|
||||
|
||||
public function updateVHost(Site $site): void;
|
||||
public function updateVHost(Site $site, bool $noSSL = false, ?string $vhost = null): void;
|
||||
|
||||
public function getVHost(Site $site): string;
|
||||
|
||||
public function deleteSite(Site $site): void;
|
||||
|
||||
|
29
app/Http/Controllers/ProjectController.php
Normal file
29
app/Http/Controllers/ProjectController.php
Normal 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');
|
||||
}
|
||||
}
|
37
app/Http/Livewire/Projects/CreateProject.php
Normal file
37
app/Http/Livewire/Projects/CreateProject.php
Normal 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');
|
||||
}
|
||||
}
|
37
app/Http/Livewire/Projects/EditProject.php
Normal file
37
app/Http/Livewire/Projects/EditProject.php
Normal 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');
|
||||
}
|
||||
}
|
42
app/Http/Livewire/Projects/ProjectsList.php
Normal file
42
app/Http/Livewire/Projects/ProjectsList.php
Normal 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(),
|
||||
]);
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Http\Livewire\Servers;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\User;
|
||||
use App\Traits\RefreshComponentOnBroadcast;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
@ -13,8 +13,12 @@ class ServersList extends Component
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$servers = $user->currentProject->servers()->orderByDesc('created_at')->get();
|
||||
|
||||
return view('livewire.servers.servers-list', [
|
||||
'servers' => Server::all(),
|
||||
'servers' => $servers,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
41
app/Http/Livewire/Sites/UpdateVHost.php
Normal file
41
app/Http/Livewire/Sites/UpdateVHost.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Sites;
|
||||
|
||||
use App\Models\Site;
|
||||
use App\Traits\HasToast;
|
||||
use App\Traits\RefreshComponentOnBroadcast;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
use Throwable;
|
||||
|
||||
class UpdateVHost extends Component
|
||||
{
|
||||
use HasToast;
|
||||
use RefreshComponentOnBroadcast;
|
||||
|
||||
public Site $site;
|
||||
|
||||
public string $vHost = 'Loading...';
|
||||
|
||||
public function loadVHost(): void
|
||||
{
|
||||
$this->vHost = $this->site->server->webserver()->handler()->getVHost($this->site);
|
||||
}
|
||||
|
||||
public function update(): void
|
||||
{
|
||||
try {
|
||||
$this->site->server->webserver()->handler()->updateVHost($this->site, false, $this->vHost);
|
||||
|
||||
$this->toast()->success('VHost updated successfully!');
|
||||
} catch (Throwable $e) {
|
||||
$this->toast()->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.sites.update-v-host');
|
||||
}
|
||||
}
|
56
app/Models/Project.php
Normal file
56
app/Models/Project.php
Normal 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);
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property int $project_id
|
||||
* @property int $user_id
|
||||
* @property string $name
|
||||
* @property string $ssh_user
|
||||
@ -38,6 +39,7 @@
|
||||
* @property int $security_updates
|
||||
* @property int $progress
|
||||
* @property string $progress_step
|
||||
* @property Project $project
|
||||
* @property User $creator
|
||||
* @property ServerProvider $serverProvider
|
||||
* @property ServerLog[] $logs
|
||||
@ -59,6 +61,7 @@ class Server extends AbstractModel
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'project_id',
|
||||
'user_id',
|
||||
'name',
|
||||
'ssh_user',
|
||||
@ -82,6 +85,7 @@ class Server extends AbstractModel
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'project_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'type_data' => 'json',
|
||||
'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
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
@ -334,10 +343,13 @@ public function sshKey(): array
|
||||
];
|
||||
}
|
||||
|
||||
/** @var \Illuminate\Filesystem\FilesystemAdapter $storageDisk */
|
||||
$storageDisk = Storage::disk(config('core.key_pairs_disk'));
|
||||
|
||||
return [
|
||||
'public_key' => Str::replace("\n", '', Storage::disk(config('core.key_pairs_disk'))->get($this->id.'.pub')),
|
||||
'public_key_path' => Storage::disk(config('core.key_pairs_disk'))->path($this->id.'.pub'),
|
||||
'private_key_path' => Storage::disk(config('core.key_pairs_disk'))->path((string) $this->id),
|
||||
'public_key_path' => $storageDisk->path($this->id.'.pub'),
|
||||
'private_key_path' => $storageDisk->path((string) $this->id),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,9 @@
|
||||
* @property Collection $tokens
|
||||
* @property string $profile_photo_url
|
||||
* @property string $timezone
|
||||
* @property int $current_project_id
|
||||
* @property Project $currentProject
|
||||
* @property Collection<Project> $projects
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
@ -41,6 +44,7 @@ class User extends Authenticatable
|
||||
'email',
|
||||
'password',
|
||||
'timezone',
|
||||
'current_project_id',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
@ -53,6 +57,20 @@ class User extends Authenticatable
|
||||
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
|
||||
{
|
||||
return $this->hasMany(SshKey::class);
|
||||
@ -105,4 +123,36 @@ public function connectedSourceControls(): array
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
26
app/SSHCommands/Nginx/GetNginxVHostCommand.php
Executable file
26
app/SSHCommands/Nginx/GetNginxVHostCommand.php
Executable file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSHCommands\Nginx;
|
||||
|
||||
use App\SSHCommands\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class GetNginxVHostCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
protected string $domain
|
||||
) {
|
||||
}
|
||||
|
||||
public function file(): string
|
||||
{
|
||||
return File::get(resource_path('commands/webserver/nginx/get-vhost.sh'));
|
||||
}
|
||||
|
||||
public function content(): string
|
||||
{
|
||||
return str($this->file())
|
||||
->replace('__domain__', $this->domain)
|
||||
->toString();
|
||||
}
|
||||
}
|
@ -164,10 +164,12 @@ private function createKeyPair(): void
|
||||
$result = $this->ec2Client->createKeyPair([
|
||||
'KeyName' => $keyName,
|
||||
]);
|
||||
Storage::disk(config('core.key_pairs_disk'))->put((string) $this->server->id, $result['KeyMaterial']);
|
||||
/** @var \Illuminate\Filesystem\FilesystemAdapter $storageDisk */
|
||||
$storageDisk = Storage::disk(config('core.key_pairs_disk'));
|
||||
$storageDisk->put((string) $this->server->id, $result['KeyMaterial']);
|
||||
generate_public_key(
|
||||
Storage::disk(config('core.key_pairs_disk'))->path((string) $this->server->id),
|
||||
Storage::disk(config('core.key_pairs_disk'))->path($this->server->id.'.pub'),
|
||||
$storageDisk->path((string) $this->server->id),
|
||||
$storageDisk->path($this->server->id.'.pub'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@ public function __construct(?Server $server = null)
|
||||
|
||||
protected function generateKeyPair(): void
|
||||
{
|
||||
generate_key_pair(Storage::disk(config('core.key_pairs_disk'))->path((string) $this->server->id));
|
||||
/** @var \Illuminate\Filesystem\FilesystemAdapter $storageDisk */
|
||||
$storageDisk = Storage::disk(config('core.key_pairs_disk'));
|
||||
generate_key_pair($storageDisk->path((string) $this->server->id));
|
||||
}
|
||||
}
|
||||
|
@ -59,13 +59,15 @@ public function regions(): array
|
||||
|
||||
public function create(): void
|
||||
{
|
||||
/** @var \Illuminate\Filesystem\FilesystemAdapter $storageDisk */
|
||||
$storageDisk = Storage::disk(config('core.key_pairs_disk'));
|
||||
File::copy(
|
||||
storage_path(config('core.ssh_private_key_name')),
|
||||
Storage::disk(config('core.key_pairs_disk'))->path($this->server->id)
|
||||
$storageDisk->path($this->server->id)
|
||||
);
|
||||
File::copy(
|
||||
storage_path(config('core.ssh_public_key_name')),
|
||||
Storage::disk(config('core.key_pairs_disk'))->path($this->server->id.'.pub')
|
||||
$storageDisk->path($this->server->id.'.pub')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,9 @@ public function regions(): array
|
||||
public function create(): void
|
||||
{
|
||||
// generate key pair
|
||||
generate_key_pair(Storage::disk(config('core.key_pairs_disk'))->path((string) $this->server->id));
|
||||
/** @var \Illuminate\Filesystem\FilesystemAdapter $storageDisk */
|
||||
$storageDisk = Storage::disk(config('core.key_pairs_disk'));
|
||||
generate_key_pair($storageDisk->path((string) $this->server->id));
|
||||
|
||||
$createSshKey = Http::withToken($this->server->serverProvider->credentials['token'])
|
||||
->post($this->apiUrl.'/ssh-keys', [
|
||||
|
@ -9,6 +9,7 @@
|
||||
use App\SSHCommands\Nginx\ChangeNginxPHPVersionCommand;
|
||||
use App\SSHCommands\Nginx\CreateNginxVHostCommand;
|
||||
use App\SSHCommands\Nginx\DeleteNginxSiteCommand;
|
||||
use App\SSHCommands\Nginx\GetNginxVHostCommand;
|
||||
use App\SSHCommands\Nginx\UpdateNginxRedirectsCommand;
|
||||
use App\SSHCommands\Nginx\UpdateNginxVHostCommand;
|
||||
use App\SSHCommands\SSL\CreateCustomSSLCommand;
|
||||
@ -39,19 +40,30 @@ public function createVHost(Site $site): void
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function updateVHost(Site $site, bool $noSSL = false): void
|
||||
public function updateVHost(Site $site, bool $noSSL = false, ?string $vhost = null): void
|
||||
{
|
||||
$this->service->server->ssh()->exec(
|
||||
new UpdateNginxVHostCommand(
|
||||
$site->domain,
|
||||
$site->path,
|
||||
$this->generateVhost($site, $noSSL)
|
||||
$vhost ?? $this->generateVhost($site, $noSSL)
|
||||
),
|
||||
'update-vhost',
|
||||
$site->id
|
||||
);
|
||||
}
|
||||
|
||||
public function getVHost(Site $site): string
|
||||
{
|
||||
return $this->service->server->ssh()->exec(
|
||||
new GetNginxVHostCommand(
|
||||
$site->domain
|
||||
),
|
||||
'get-vhost',
|
||||
$site->id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
|
@ -55,6 +55,7 @@ public function createFields(array $input): array
|
||||
'source_control_id' => $input['source_control'] ?? '',
|
||||
'repository' => $input['repository'] ?? '',
|
||||
'branch' => $input['branch'] ?? '',
|
||||
'php_version' => $input['php_version'] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
@ -62,7 +63,6 @@ public function data(array $input): array
|
||||
{
|
||||
return [
|
||||
'composer' => isset($input['composer']) && $input['composer'],
|
||||
'php_version' => $input['php_version'] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -39,8 +39,8 @@
|
||||
'ssh_user' => env('SSH_USER', 'vito'),
|
||||
'ssh_public_key_name' => env('SSH_PUBLIC_KEY_NAME', 'ssh-public.key'),
|
||||
'ssh_private_key_name' => env('SSH_PRIVATE_KEY_NAME', 'ssh-private.pem'),
|
||||
'logs_disk' => env('SERVER_LOGS_DISK', 'server-logs-local'),
|
||||
'key_pairs_disk' => env('KEY_PAIRS_DISK', 'key-pairs-local'),
|
||||
'logs_disk' => env('SERVER_LOGS_DISK', 'server-logs-local'), // should to be FilesystemAdapter storage
|
||||
'key_pairs_disk' => env('KEY_PAIRS_DISK', 'key-pairs-local'), // should to be FilesystemAdapter storage
|
||||
|
||||
/*
|
||||
* General
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
'disks' => [
|
||||
|
||||
// should be FilesystemAdapter
|
||||
'local' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app'),
|
||||
|
25
database/factories/ProjectFactory.php
Normal file
25
database/factories/ProjectFactory.php
Normal 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(),
|
||||
];
|
||||
}
|
||||
}
|
@ -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');
|
||||
}
|
||||
};
|
@ -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');
|
||||
});
|
||||
}
|
||||
};
|
27
database/migrations/2024_01_01_235900_update_users_table.php
Normal file
27
database/migrations/2024_01_01_235900_update_users_table.php
Normal 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');
|
||||
});
|
||||
}
|
||||
};
|
@ -22,6 +22,7 @@ public function run(): void
|
||||
]);
|
||||
$server = Server::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'project_id' => $user->currentProject->id,
|
||||
]);
|
||||
$server->services()->create([
|
||||
'type' => 'database',
|
||||
|
File diff suppressed because one or more lines are too long
1
public/build/assets/app-f482c864.css
Normal file
1
public/build/assets/app-f482c864.css
Normal file
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
{
|
||||
"resources/css/app.css": {
|
||||
"file": "assets/app-328222da.css",
|
||||
"file": "assets/app-f482c864.css",
|
||||
"isEntry": true,
|
||||
"src": "resources/css/app.css"
|
||||
},
|
||||
|
1
resources/commands/webserver/nginx/get-vhost.sh
Executable file
1
resources/commands/webserver/nginx/get-vhost.sh
Executable file
@ -0,0 +1 @@
|
||||
cat /etc/nginx/sites-available/__domain__
|
File diff suppressed because one or more lines are too long
@ -37,16 +37,25 @@
|
||||
<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">
|
||||
<div class="h-16 block">
|
||||
<div class="flex items-center justify-start text-3xl font-extrabold text-white">
|
||||
<x-application-logo class="w-10 h-10 rounded-md"/>
|
||||
<div class="flex items-center justify-start text-2xl font-extrabold text-white">
|
||||
<x-application-logo class="w-7 h-7 rounded-md" />
|
||||
<span class="ml-1">Deploy</span>
|
||||
</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])
|
||||
</div>
|
||||
|
||||
@if (isset($server))
|
||||
<div class="mt-3 space-y-1">
|
||||
<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"
|
||||
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>
|
||||
<span class="ml-2 text-gray-50">{{ __('Logs') }}</span>
|
||||
</x-sidebar-link>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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>
|
||||
<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>
|
||||
</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 }}
|
||||
</div>
|
||||
</div>
|
||||
|
90
resources/views/layouts/partials/project-select.blade.php
Normal file
90
resources/views/layouts/partials/project-select.blade.php
Normal 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>
|
@ -1,13 +1,13 @@
|
||||
<div x-data="serverCombobox()">
|
||||
<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>
|
||||
<button type="button" @click="open = !open" class="absolute inset-y-0 right-0 flex items-center pr-2">
|
||||
<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="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="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">
|
||||
<input x-model="query"
|
||||
@input="filterServersAndOpen"
|
||||
@ -58,7 +58,7 @@ class="relative select-none py-2 px-4 text-gray-700 dark:text-white hover:bg-pri
|
||||
|
||||
<script>
|
||||
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 {
|
||||
open: false,
|
||||
query: '',
|
||||
|
@ -16,6 +16,12 @@
|
||||
</svg>
|
||||
{{ __('Profile') }}
|
||||
</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')">
|
||||
<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" />
|
||||
|
31
resources/views/livewire/projects/create-project.blade.php
Normal file
31
resources/views/livewire/projects/create-project.blade.php
Normal 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>
|
31
resources/views/livewire/projects/edit-project.blade.php
Normal file
31
resources/views/livewire/projects/edit-project.blade.php
Normal 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>
|
38
resources/views/livewire/projects/projects-list.blade.php
Normal file
38
resources/views/livewire/projects/projects-list.blade.php
Normal 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>
|
34
resources/views/livewire/sites/update-v-host.blade.php
Normal file
34
resources/views/livewire/sites/update-v-host.blade.php
Normal file
@ -0,0 +1,34 @@
|
||||
<x-card>
|
||||
<x-slot name="title">{{ __('Update VHost') }}</x-slot>
|
||||
|
||||
<x-slot name="description">{{ __("You can change your site's PHP version here") }}</x-slot>
|
||||
|
||||
<form
|
||||
id="update-vhost"
|
||||
wire:submit.prevent="update"
|
||||
class="space-y-6"
|
||||
>
|
||||
<div>
|
||||
<x-textarea
|
||||
id="vHost"
|
||||
wire:init="loadVHost"
|
||||
wire:model.defer="vHost"
|
||||
rows="10"
|
||||
class="mt-1 block w-full"
|
||||
></x-textarea>
|
||||
@error('vHost')
|
||||
<x-input-error
|
||||
class="mt-2"
|
||||
:messages="$message"
|
||||
/>
|
||||
@enderror
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<x-slot name="actions">
|
||||
<x-primary-button
|
||||
form="update-vhost"
|
||||
wire:loading.attr="disabled"
|
||||
>{{ __('Save') }}</x-primary-button>
|
||||
</x-slot>
|
||||
</x-card>
|
5
resources/views/projects/index.blade.php
Normal file
5
resources/views/projects/index.blade.php
Normal file
@ -0,0 +1,5 @@
|
||||
<x-profile-layout>
|
||||
<x-slot name="pageTitle">{{ __("Projects") }}</x-slot>
|
||||
|
||||
<livewire:projects.projects-list />
|
||||
</x-profile-layout>
|
@ -5,6 +5,8 @@
|
||||
|
||||
<livewire:sites.update-source-control-provider :site="$site"/>
|
||||
|
||||
<livewire:sites.update-v-host :site="$site"/>
|
||||
|
||||
<x-card>
|
||||
<x-slot name="title">{{ __("Delete Site") }}</x-slot>
|
||||
<x-slot name="description">{{ __("Permanently delete the site from server") }}</x-slot>
|
||||
|
@ -5,6 +5,7 @@
|
||||
use App\Http\Controllers\DatabaseController;
|
||||
use App\Http\Controllers\FirewallController;
|
||||
use App\Http\Controllers\PHPController;
|
||||
use App\Http\Controllers\ProjectController;
|
||||
use App\Http\Controllers\ServerController;
|
||||
use App\Http\Controllers\ServerSettingController;
|
||||
use App\Http\Controllers\ServiceController;
|
||||
@ -19,6 +20,8 @@
|
||||
Route::middleware('auth')->group(function () {
|
||||
Route::prefix('/settings')->group(function () {
|
||||
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('/source-controls', 'source-controls.index')->name('source-controls');
|
||||
Route::view('/storage-providers', 'storage-providers.index')->name('storage-providers');
|
||||
|
83
tests/Feature/Http/ProjectsTest.php
Normal file
83
tests/Feature/Http/ProjectsTest.php
Normal 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',
|
||||
]);
|
||||
}
|
||||
}
|
@ -5,11 +5,13 @@
|
||||
use App\Enums\SiteStatus;
|
||||
use App\Enums\SiteType;
|
||||
use App\Enums\SourceControl;
|
||||
use App\Facades\SSH;
|
||||
use App\Http\Livewire\Sites\ChangePhpVersion;
|
||||
use App\Http\Livewire\Sites\CreateSite;
|
||||
use App\Http\Livewire\Sites\DeleteSite;
|
||||
use App\Http\Livewire\Sites\SitesList;
|
||||
use App\Http\Livewire\Sites\UpdateSourceControlProvider;
|
||||
use App\Http\Livewire\Sites\UpdateVHost;
|
||||
use App\Jobs\Site\CreateVHost;
|
||||
use App\Models\Site;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
@ -107,6 +109,22 @@ public function test_change_php_version(): void
|
||||
Bus::assertDispatched(\App\Jobs\Site\ChangePHPVersion::class);
|
||||
}
|
||||
|
||||
public function test_update_v_host(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$site = Site::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
]);
|
||||
|
||||
Livewire::test(UpdateVHost::class, ['site' => $site])
|
||||
->set('vHost', 'test-vhost')
|
||||
->call('update')
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_update_source_control(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
Reference in New Issue
Block a user