Skip to content

Commit

Permalink
add blank php site (#94)
Browse files Browse the repository at this point in the history
* add blank php site

* fix frontend

* fix source control check
  • Loading branch information
saeedvaziry authored Jan 18, 2024
1 parent 0ec6a9d commit 8665435
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 70 deletions.
2 changes: 2 additions & 0 deletions app/Enums/SiteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ final class SiteType extends Enum
{
const PHP = 'php';

const PHP_BLANK = 'php-blank';

const LARAVEL = 'laravel';

const WORDPRESS = 'wordpress';
Expand Down
19 changes: 19 additions & 0 deletions app/Http/Livewire/Application/PhpBlankApp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Livewire\Application;

use App\Models\Site;
use App\Traits\RefreshComponentOnBroadcast;
use Livewire\Component;

class PhpBlankApp extends Component
{
use RefreshComponentOnBroadcast;

public Site $site;

public function render()
{
return view('livewire.application.php-blank-app');
}
}
67 changes: 67 additions & 0 deletions app/SiteTypes/PHPBlank.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace App\SiteTypes;

use App\Enums\SiteFeature;
use App\Jobs\Site\CreateVHost;
use Illuminate\Support\Facades\Bus;
use Illuminate\Validation\Rule;
use Throwable;

class PHPBlank extends PHPSite
{
public function supportedFeatures(): array
{
return [
SiteFeature::DEPLOYMENT,
SiteFeature::ENV,
SiteFeature::SSL,
SiteFeature::QUEUES,
];
}

public function createValidationRules(array $input): array
{
return [
'php_version' => [
'required',
Rule::in($this->site->server->installedPHPVersions()),
],
];
}

public function createFields(array $input): array
{
return [
'web_directory' => $input['web_directory'] ?? '',
'php_version' => $input['php_version'] ?? '',
];
}

public function data(array $input): array
{
return [];
}

public function install(): void
{
$chain = [
new CreateVHost($this->site),
$this->progress(65),
function () {
$this->site->php()?->restart();
},
];

$chain[] = function () {
$this->site->installationFinished();
};

Bus::chain($chain)
->catch(function (Throwable $e) {
$this->site->installationFailed($e);
})
->onConnection('ssh-long')
->dispatch();
}
}
3 changes: 3 additions & 0 deletions config/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use App\ServiceHandlers\ProcessManager\Supervisor;
use App\ServiceHandlers\Webserver\Nginx;
use App\SiteTypes\Laravel;
use App\SiteTypes\PHPBlank;
use App\SiteTypes\PHPSite;
use App\SiteTypes\Wordpress;
use App\SourceControlProviders\Bitbucket;
Expand Down Expand Up @@ -263,11 +264,13 @@
*/
'site_types' => [
\App\Enums\SiteType::PHP,
\App\Enums\SiteType::PHP_BLANK,
\App\Enums\SiteType::LARAVEL,
\App\Enums\SiteType::WORDPRESS,
],
'site_types_class' => [
\App\Enums\SiteType::PHP => PHPSite::class,
\App\Enums\SiteType::PHP_BLANK => PHPBlank::class,
\App\Enums\SiteType::LARAVEL => Laravel::class,
\App\Enums\SiteType::WORDPRESS => Wordpress::class,
],
Expand Down
1 change: 0 additions & 1 deletion public/build/assets/app-8b808e33.css

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/app-ae945733.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/build/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"resources/css/app.css": {
"file": "assets/app-8b808e33.css",
"file": "assets/app-ae945733.css",
"isEntry": true,
"src": "resources/css/app.css"
},
Expand Down
37 changes: 37 additions & 0 deletions public/static/images/php-blank.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 1 addition & 36 deletions resources/views/livewire/application/laravel-app.blade.php
Original file line number Diff line number Diff line change
@@ -1,36 +1 @@
<div>
<x-card-header>
<x-slot name="title">{{ __("Application") }}</x-slot>
<x-slot name="description">{{ __("Here you can manage your application") }}</x-slot>
<x-slot name="aside">
<div class="flex items-center">
<div class="mr-2">
<livewire:application.deploy :site="$site" />
</div>
<div class="mr-2">
<livewire:application.auto-deployment :site="$site" />
</div>
<x-dropdown>
<x-slot name="trigger">
<x-secondary-button>
{{ __('Manage') }}
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5 ml-1">
<path stroke-linecap="round" stroke-linejoin="round" d="M8.25 15L12 18.75 15.75 15m-7.5-6L12 5.25 15.75 9" />
</svg>
</x-secondary-button>
</x-slot>
<x-slot name="content">
<x-dropdown-link class="cursor-pointer" x-on:click="$dispatch('open-modal', 'change-branch')">{{ __("Branch") }}</x-dropdown-link>
<x-dropdown-link class="cursor-pointer" x-on:click="$dispatch('open-modal', 'deployment-script')">{{ __("Deployment Script") }}</x-dropdown-link>
<x-dropdown-link class="cursor-pointer" x-on:click="$dispatch('open-modal', 'update-env')">{{ __(".env") }}</x-dropdown-link>
</x-slot>
</x-dropdown>
<livewire:application.change-branch :site="$site" />
<livewire:application.deployment-script :site="$site" />
<livewire:application.env :site="$site" />
</div>
</x-slot>
</x-card-header>

<livewire:application.deployments-list :site="$site" />
</div>
@include('livewire.application.php-app')
59 changes: 59 additions & 0 deletions resources/views/livewire/application/php-app.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
<div>
<x-card-header>
<x-slot name="title">{{ __('Application') }}</x-slot>
<x-slot name="description">{{ __('Here you can manage your application') }}</x-slot>
<x-slot name="aside">
<div class="flex items-center">
<div class="mr-2">
<livewire:application.deploy :site="$site" />
</div>
@if ($site->source_control_id)
<div class="mr-2">
<livewire:application.auto-deployment :site="$site" />
</div>
@endif
<x-dropdown>
<x-slot name="trigger">
<x-secondary-button>
{{ __('Manage') }}
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="ml-1 h-5 w-5"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M8.25 15L12 18.75 15.75 15m-7.5-6L12 5.25 15.75 9"
/>
</svg>
</x-secondary-button>
</x-slot>
<x-slot name="content">
@if ($site->source_control_id)
<x-dropdown-link
class="cursor-pointer"
x-on:click="$dispatch('open-modal', 'change-branch')"
>{{ __('Branch') }}</x-dropdown-link>
@endif
<x-dropdown-link
class="cursor-pointer"
x-on:click="$dispatch('open-modal', 'deployment-script')"
>{{ __('Deployment Script') }}</x-dropdown-link>
<x-dropdown-link
class="cursor-pointer"
x-on:click="$dispatch('open-modal', 'update-env')"
>{{ __('.env') }}</x-dropdown-link>
</x-slot>
</x-dropdown>
@if ($site->source_control_id)
<livewire:application.change-branch :site="$site" />
@endif
<livewire:application.deployment-script :site="$site" />
<livewire:application.env :site="$site" />
</div>
</x-slot>
</x-card-header>

<livewire:application.deployments-list :site="$site" />
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@include('livewire.application.php-app')
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@include('livewire.sites.partials.create.fields.php-version')

@include('livewire.sites.partials.create.fields.web-directory')
12 changes: 1 addition & 11 deletions resources/views/livewire/sites/show-site.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@
<livewire:server-logs.logs-list :server="$site->server" :site="$site" :count="10" />
@endif
@if($site->status === \App\Enums\SiteStatus::READY)
@if($site->type == \App\Enums\SiteType::LARAVEL)
<livewire:application.laravel-app :site="$site" />
@endif

@if($site->type == \App\Enums\SiteType::PHP)
<livewire:application.php-app :site="$site" />
@endif

@if($site->type == \App\Enums\SiteType::WORDPRESS)
<livewire:application.wordpress-app :site="$site" />
@endif
@livewire('application.' . $site->type . '-app', ['site' => $site])
@endif
</div>
22 changes: 9 additions & 13 deletions resources/views/sites/application.blade.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<x-site-layout :site="$site">
<x-slot name="pageTitle">{{ __("Application") }}</x-slot>
@if($site->type == \App\Enums\SiteType::LARAVEL)
<livewire:application.laravel-app :site="$site" />
@endif

@if($site->type == \App\Enums\SiteType::LARAVEL)
<livewire:application.laravel-app :site="$site" />
@endif
@if($site->type == \App\Enums\SiteType::PHP)
<livewire:application.php-app :site="$site" />
@endif

@if($site->type == \App\Enums\SiteType::PHP)
<livewire:application.php-app :site="$site" />
@endif

@if($site->type == \App\Enums\SiteType::WORDPRESS)
<livewire:application.wordpress-app :site="$site" />
@endif
</x-site-layout>
@if($site->type == \App\Enums\SiteType::WORDPRESS)
<livewire:application.wordpress-app :site="$site" />
@endif
18 changes: 10 additions & 8 deletions resources/views/sites/settings.blade.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<x-site-layout :site="$site">
<x-slot name="pageTitle">{{ __("Settings") }}</x-slot>
<x-slot name="pageTitle">{{ __('Settings') }}</x-slot>

<livewire:sites.change-php-version :site="$site"/>
<livewire:sites.change-php-version :site="$site" />

<livewire:sites.update-source-control-provider :site="$site"/>
@if ($site->source_control_id)
<livewire:sites.update-source-control-provider :site="$site" />
@endif

<livewire:sites.update-v-host :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>
<p>{{ __("Once your site is deleted, all of its files will be deleted from the server.") }}</p>
<x-slot name="title">{{ __('Delete Site') }}</x-slot>
<x-slot name="description">{{ __('Permanently delete the site from server') }}</x-slot>
<p>{{ __('Once your site is deleted, all of its files will be deleted from the server.') }}</p>
<div class="mt-5">
<livewire:sites.delete-site :site="$site"/>
<livewire:sites.delete-site :site="$site" />
</div>
</x-card>
</x-site-layout>
9 changes: 9 additions & 0 deletions tests/Feature/Http/SitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ public static function create_data(): array
'inputs.database_password' => 'password',
],
],
[
[
'inputs.type' => SiteType::PHP_BLANK,
'inputs.domain' => 'example.com',
'inputs.alias' => 'www.example.com',
'inputs.php_version' => '8.2',
'inputs.web_directory' => 'public',
],
],
];
}
}

0 comments on commit 8665435

Please sign in to comment.