Skip to content

Commit

Permalink
Merge pull request #477 from andreapollastri/4.x
Browse files Browse the repository at this point in the history
Installation Fix
  • Loading branch information
andreapollastri authored Mar 17, 2024
2 parents dae05fe + bf693d9 commit 542b5f7
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ AWS_USE_PATH_STYLE_ENDPOINT=false

VITE_APP_NAME="${APP_NAME}"

PANEL_SSH_SERVER_HOST=changeme
PANEL_SSH_SERVER_PASS=changeme
PANEL_SQL_DBROOT_PASS=changeme
PANEL_SERVER_IP=changeme
PANEL_CIPI_PASSWORD=changeme
PANEL_MYSQL_PASSWORD=changeme
113 changes: 113 additions & 0 deletions app/Filament/Resources/SiteResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\SiteResource\Pages;
use App\Models\Site;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\Str;

class SiteResource extends Resource
{
protected static ?string $model = Site::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
{
$username = Str::lower(Str::random(12));

return $form
->schema([
Forms\Components\TextInput::make('domain')
->required()
->maxLength(255),
Forms\Components\Hidden::make('username')
->default($username),
Forms\Components\Select::make('basepath')
->required()
->prefix('/home/'.$username.'/www')
->options([
'/' => '/',
'/web' => '/web',
'/build' => '/build',
'/public' => '/public',
])
->default('/public')
->native(false),
Forms\Components\TextInput::make('repository')
->maxLength(255),
Forms\Components\TextInput::make('branch')
->maxLength(255),
Forms\Components\Select::make('php')
->required()
->options(\App\Helpers\Php::availableVersions())
->default(\App\Helpers\Php::defaultVersion())
->native(false),
Forms\Components\TextInput::make('supervisor'),
Forms\Components\TextInput::make('nginx'),
Forms\Components\TextInput::make('deploy'),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id')
->label('ID')
->searchable(),
Tables\Columns\TextColumn::make('domain')
->searchable(),
Tables\Columns\TextColumn::make('username')
->searchable(),
Tables\Columns\TextColumn::make('basepath')
->searchable(),
Tables\Columns\TextColumn::make('repository')
->searchable(),
Tables\Columns\TextColumn::make('branch')
->searchable(),
Tables\Columns\TextColumn::make('php')
->searchable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListSites::route('/'),
'create' => Pages\CreateSite::route('/create'),
'edit' => Pages\EditSite::route('/{record}/edit'),
];
}
}
11 changes: 11 additions & 0 deletions app/Filament/Resources/SiteResource/Pages/CreateSite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Filament\Resources\SiteResource\Pages;

use App\Filament\Resources\SiteResource;
use Filament\Resources\Pages\CreateRecord;

class CreateSite extends CreateRecord
{
protected static string $resource = SiteResource::class;
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/SiteResource/Pages/EditSite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\SiteResource\Pages;

use App\Filament\Resources\SiteResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditSite extends EditRecord
{
protected static string $resource = SiteResource::class;

protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/SiteResource/Pages/ListSites.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\SiteResource\Pages;

use App\Filament\Resources\SiteResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

class ListSites extends ListRecords
{
protected static string $resource = SiteResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
21 changes: 21 additions & 0 deletions app/Helpers/Php.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Helpers;

class Php
{
public static function availableVersions()
{
return [
'8.0' => '8.0',
'8.1' => '8.1',
'8.2' => '8.2',
'8.3' => '8.3',
];
}

public static function defaultVersion()
{
return '8.3';
}
}
26 changes: 26 additions & 0 deletions app/Models/Site.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Site extends Model
{
use HasFactory;
use HasUuids;

protected $fillable = [
'domain',
'username',
'password',
'basepath',
'repository',
'branch',
'php',
'supervisor',
'nginx',
'deploy',
];
}
38 changes: 38 additions & 0 deletions database/migrations/0001_01_01_000006_create_sites_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('sites', function (Blueprint $table) {
$table->uuid('id');
$table->string('domain')->index()->unique();
$table->string('username');
$table->string('password');
$table->string('basepath')->nullable();
$table->string('repository')->nullable();
$table->string('branch')->nullable();
$table->string('php');
$table->text('supervisor')->nullable();
$table->text('nginx')->nullable();
$table->text('deploy')->nullable();
$table->text('crontab')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('sites');
}
};
22 changes: 12 additions & 10 deletions go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -521,33 +521,35 @@ sudo chmod -R o+w /var/www/html/storage
sudo chmod -R 775 /var/www/html/storage
sudo chmod -R o+w /var/www/html/bootstrap/cache
sudo chmod -R 775 /var/www/html/bootstrap/cache
sudo chown -R www-data:cipi /var/www/html
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 775 /var/www/html
PANELSETUP=/var/www/panel.sh
sudo touch $PANELSETUP
sudo cat > $PANELSETUP <<EOF
cd /var/www/html && unlink .env
cd /var/www/html && cp .env.example .env
cd /var/www/html && composer install --no-interaction
cd /var/www/html && php artisan key:generate
sudo chown -R www-data:www-data /var/www/html
sudo su -l www-data -s /bin/bash -c "cd /var/www/html && composer install --no-interaction"
sudo su -l www-data -s /bin/bash -c "cd /var/www/html && php artisan key:generate"
rpl -i -w "APP_ENV=local" "APP_ENV=production" /var/www/html/.env
rpl -i -w "APP_DEBUG=true" "APP_DEBUG=false" /var/www/html/.env
rpl -i -w "APP_URL=http://localhost" "APP_URL=https://cipi-$SERVERIPWITHDASH$IPDOMAIN" /var/www/html/.env
rpl -i -w "DB_PASSWORD=changeme" "DB_PASSWORD=$DATABASEPASSWORD" /var/www/html/.env
rpl -i -w "PANEL_SSH_SERVER_HOST=changeme" "PANEL_SSH_SERVER_HOST=$SERVERIP" /var/www/html/.env
rpl -i -w "PANEL_SSH_SERVER_PASS=changeme" "PANEL_SSH_SERVER_PASS=$USERPASSWORD" /var/www/html/.env
rpl -i -w "PANEL_SQL_DBROOT_PASS=changeme" "PANEL_SQL_DBROOT_PASS=$DATABASEPASSWORD" /var/www/html/.env
rpl -i -w "PANEL_SERVER_IP=changeme" "PANEL_SERVER_IP=$SERVERIP" /var/www/html/.env
rpl -i -w "PANEL_CIPI_PASSWORD=changeme" "PANEL_CIPI_PASSWORD=$USERPASSWORD" /var/www/html/.env
rpl -i -w "PANEL_MYSQL_PASSWORD=changeme" "PANEL_MYSQL_PASSWORD=$DATABASEPASSWORD" /var/www/html/.env
cd /var/www/html && php artisan config:clear
cd /var/www/html && php artisan migrate --seed --force
cd /var/www/html && php artisan storage:link
cd /var/www/html && php artisan config:cache
cd /var/www/html && php artisan route:cache
cd /var/www/html && php artisan view:cache
cd /var/www/html && php artisan optimize
sudo chown -R www-data:www-data /var/www/html
EOF
su -c "sh $PANELSETUP" cipi
sudo unlink $PANELSETUP
sudo chown -R www-data:cipi /var/www/html
sudo chmod -R 775 /var/www/html



Expand All @@ -558,8 +560,8 @@ echo "Fine tuning..."
echo "${reset}"
sleep 1s

sudo chown www-data:cipi -R /var/www/html
sudo chmod -R 750 /var/www/html
sudo chown www-data:www-data -R /var/www/html
sudo chmod -R 775 /var/www/html
sudo echo 'DefaultStartLimitIntervalSec=1s' >> /usr/lib/systemd/system/user@.service
sudo echo 'DefaultStartLimitBurst=50' >> /usr/lib/systemd/system/user@.service
sudo echo 'StartLimitBurst=0' >> /usr/lib/systemd/system/user@.service
Expand Down Expand Up @@ -603,7 +605,7 @@ autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=cipi
user=www-data
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/worker.log
Expand Down

0 comments on commit 542b5f7

Please sign in to comment.