wip
This commit is contained in:
71
app/Http/Livewire/DemoDeployApplication.php
Normal file
71
app/Http/Livewire/DemoDeployApplication.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Application;
|
||||
use App\Models\CoolifyInstanceSettings;
|
||||
use App\Models\Deployment;
|
||||
use App\Traits\Shared;
|
||||
use Livewire\Component;
|
||||
use Visus\Cuid2\Cuid2;
|
||||
|
||||
class DemoDeployApplication extends Component
|
||||
{
|
||||
use Shared;
|
||||
|
||||
public $activity;
|
||||
public $isKeepAliveOn = false;
|
||||
public $application_uuid;
|
||||
|
||||
public Application $application;
|
||||
public $destination;
|
||||
|
||||
public CoolifyInstanceSettings $coolify_instance_settings;
|
||||
public $wildcard_domain;
|
||||
|
||||
|
||||
public function deploy()
|
||||
{
|
||||
$this->isKeepAliveOn = true;
|
||||
|
||||
$this->coolify_instance_settings = CoolifyInstanceSettings::find(1);
|
||||
$this->application = Application::where('uuid', $this->application_uuid)->first();
|
||||
$this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
|
||||
$project_wildcard_domain = data_get($this->application, 'environment.project.settings.wildcard_domain');
|
||||
$global_wildcard_domain = data_get($this->coolify_instance_settings, 'wildcard_domain');
|
||||
$this->wildcard_domain = $project_wildcard_domain ?? $global_wildcard_domain ?? null;
|
||||
|
||||
$source = $this->application->source->getMorphClass()::where('id', $this->application->source->id)->first();
|
||||
$deployment_id = new Cuid2(10);
|
||||
|
||||
$workdir = $this->get_workdir('application', $this->application->uuid, $deployment_id);
|
||||
|
||||
$command[] = "echo 'Starting deployment of {$this->application->name} ({$this->application->uuid})'";
|
||||
$command[] = 'mkdirs -p ' . $workdir;
|
||||
$command[] = "git clone -b {$this->application->git_branch} {$source->html_url}/{$this->application->git_repository}.git {$workdir}";
|
||||
|
||||
if (!file_exists($workdir) && $workdir != "/") {
|
||||
$command[] = "echo 'Removing {$workdir}'";
|
||||
$command[] = "rm -rf {$workdir}";
|
||||
}
|
||||
$this->activity = remoteProcess(implode("\n", $command), $this->destination->server->name);
|
||||
|
||||
Deployment::create([
|
||||
'uuid' => $deployment_id,
|
||||
'type_id' => $this->application->id,
|
||||
'type_type' => Application::class,
|
||||
'activity_log_id' => $this->activity->id,
|
||||
]);
|
||||
}
|
||||
public function polling()
|
||||
{
|
||||
$this->activity?->refresh();
|
||||
if (data_get($this->activity, 'properties.exitCode') !== null) {
|
||||
$this->isKeepAliveOn = false;
|
||||
}
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.demo-deploy-application');
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,15 @@ class RunCommand extends Component
|
||||
|
||||
public $command = 'ls';
|
||||
|
||||
public $server = 'testing-host';
|
||||
public $server;
|
||||
|
||||
public $servers = [];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->servers = Server::all()->pluck('name')->toArray();
|
||||
$this->server = $this->servers[0];
|
||||
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
|
||||
@@ -8,6 +8,10 @@ class Application extends BaseModel
|
||||
{
|
||||
return $this->belongsTo(Environment::class);
|
||||
}
|
||||
public function settings()
|
||||
{
|
||||
return $this->hasOne(ApplicationSetting::class);
|
||||
}
|
||||
public function destination()
|
||||
{
|
||||
return $this->morphTo();
|
||||
@@ -16,4 +20,8 @@ class Application extends BaseModel
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
public function deployments()
|
||||
{
|
||||
return $this->morphMany(Deployment::class, 'type');
|
||||
}
|
||||
}
|
||||
|
||||
9
app/Models/ApplicationSetting.php
Normal file
9
app/Models/ApplicationSetting.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ApplicationSetting extends Model
|
||||
{
|
||||
}
|
||||
11
app/Models/CoolifyInstanceSettings.php
Normal file
11
app/Models/CoolifyInstanceSettings.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CoolifyInstanceSettings extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
@@ -12,4 +12,8 @@ class Database extends BaseModel
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
public function deployments()
|
||||
{
|
||||
return $this->morphMany(Deployment::class, 'type');
|
||||
}
|
||||
}
|
||||
|
||||
24
app/Models/Deployment.php
Normal file
24
app/Models/Deployment.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Activitylog\Models\Activity;
|
||||
|
||||
class Deployment extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'uuid',
|
||||
'type_id',
|
||||
'type_type',
|
||||
'activity_log_id',
|
||||
];
|
||||
public function type()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
public function activity()
|
||||
{
|
||||
return $this->belongsTo(Activity::class, 'activity_log_id');
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,10 @@ namespace App\Models;
|
||||
|
||||
class Environment extends BaseModel
|
||||
{
|
||||
public function project()
|
||||
{
|
||||
return $this->belongsTo(Project::class);
|
||||
}
|
||||
public function applications()
|
||||
{
|
||||
return $this->hasMany(Application::class);
|
||||
|
||||
@@ -8,4 +8,8 @@ class StandaloneDocker extends BaseModel
|
||||
{
|
||||
return $this->morphMany(Application::class, 'destination');
|
||||
}
|
||||
public function server()
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
}
|
||||
|
||||
14
app/Traits/Shared.php
Normal file
14
app/Traits/Shared.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\Process;
|
||||
|
||||
trait Shared
|
||||
{
|
||||
public function get_workdir(string $type, string $resource_id, string $deployment_id)
|
||||
{
|
||||
$workdir = "/tmp/coolify/$type/{$resource_id}/{$deployment_id}/";
|
||||
return $workdir;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user