add new public repo

This commit is contained in:
Andras Bacsai
2023-04-25 14:43:35 +02:00
parent dd51b002b8
commit 6135c139da
42 changed files with 495 additions and 210 deletions

View File

@@ -11,15 +11,15 @@ class ApplicationController extends Controller
{
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$application = $environment->applications->where('uuid', request()->route('application_uuid'))->first();
if (!$application) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
return view('project.application.configuration', ['application' => $application]);
}
@@ -27,15 +27,15 @@ class ApplicationController extends Controller
{
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$application = $environment->applications->where('uuid', request()->route('application_uuid'))->first();
if (!$application) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
return view('project.application.deployments', ['application' => $application, 'deployments' => $application->deployments()]);
}
@@ -46,15 +46,15 @@ class ApplicationController extends Controller
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$application = $environment->applications->where('uuid', request()->route('application_uuid'))->first();
if (!$application) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$activity = Activity::where('properties->deployment_uuid', '=', $deployment_uuid)->first();

View File

@@ -10,7 +10,7 @@ class ProjectController extends Controller
{
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$project->load(['environments']);
if (count($project->environments) == 1) {
@@ -23,11 +23,11 @@ class ProjectController extends Controller
{
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first();
if (!$environment) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
return view('project.resources', ['project' => $project, 'environment' => $environment]);
}
@@ -36,15 +36,15 @@ class ProjectController extends Controller
{
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$application = $environment->applications->where('uuid', request()->route('application_uuid'))->first();
if (!$application) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
return view('project.application.configuration', ['application' => $application]);
}
@@ -52,15 +52,15 @@ class ProjectController extends Controller
{
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$application = $environment->applications->where('uuid', request()->route('application_uuid'))->first();
if (!$application) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
return view('project.application.deployments', ['application' => $application, 'deployments' => $application->deployments()]);
}
@@ -71,15 +71,15 @@ class ProjectController extends Controller
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$application = $environment->applications->where('uuid', request()->route('application_uuid'))->first();
if (!$application) {
return redirect()->route('home');
return redirect()->route('dashboard');
}
$activity = Activity::where('properties->deployment_uuid', '=', $deployment_uuid)->first();

View File

@@ -24,7 +24,7 @@ class Deploy extends Component
public function mount()
{
$this->parameters = Route::current()->parameters();
$this->application = Application::find($this->applicationId)->first();
$this->application = Application::where('id', $this->applicationId)->first();
$this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
}
protected function setDeploymentUuid()

View File

@@ -36,7 +36,8 @@ class General extends Component
'application.build_pack' => 'required',
'application.base_directory' => 'required',
'application.publish_directory' => 'nullable',
'application.ports_exposes' => 'nullable',
'application.ports_exposes' => 'required',
'application.ports_mappings' => 'nullable',
];
public function instantSave()
{
@@ -54,7 +55,7 @@ class General extends Component
}
public function mount()
{
$this->application = Application::find($this->applicationId)->with('destination', 'settings')->first();
$this->application = Application::where('id', $this->applicationId)->with('destination', 'settings')->firstOrFail();
$this->is_git_submodules_allowed = $this->application->settings->is_git_submodules_allowed;
$this->is_git_lfs_allowed = $this->application->settings->is_git_lfs_allowed;
$this->is_debug = $this->application->settings->is_debug;
@@ -64,7 +65,6 @@ class General extends Component
$this->is_http2 = $this->application->settings->is_http2;
$this->is_auto_deploy = $this->application->settings->is_auto_deploy;
$this->is_dual_cert = $this->application->settings->is_dual_cert;
}
public function submit()
{

View File

@@ -17,6 +17,6 @@ class Source extends Component
];
public function mount()
{
$this->application = Application::find($this->applicationId)->first();
$this->application = Application::where('id', $this->applicationId)->first();
}
}

View File

@@ -0,0 +1,90 @@
<?php
namespace App\Http\Livewire\Project\New;
use App\Http\Livewire\Application\Destination;
use App\Models\Application;
use App\Models\Git;
use App\Models\GithubApp;
use App\Models\GitlabApp;
use App\Models\Project;
use App\Models\Server;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Livewire\Component;
use Spatie\Url\Url;
class PublicGitRepository extends Component
{
public string $public_repository_url;
public int $port;
public $servers;
public $standalone_docker;
public $swarm_docker;
public $chosenServer;
public $chosenDestination;
public $github_apps;
public $gitlab_apps;
protected $rules = [
'public_repository_url' => 'required|url',
];
public function mount()
{
if (env('APP_ENV') === 'local') {
$this->public_repository_url = 'https://github.com/coollabsio/coolify-examples/tree/nodejs-fastify';
$this->port = 3000;
}
$this->servers = session('currentTeam')->load(['servers'])->servers;
}
public function chooseServer($server_id)
{
$this->chosenServer = $server_id;
$this->standalone_docker = StandaloneDocker::where('server_id', $server_id)->get();
$this->swarm_docker = SwarmDocker::where('server_id', $server_id)->get();
}
public function setDestination($destination_uuid, $destination_type)
{
$class = "App\Models\\{$destination_type}";
$instance = new $class;
$this->chosenDestination = $instance::where('uuid', $destination_uuid)->first();
}
public function submit()
{
$this->validate();
$url = Url::fromString($this->public_repository_url);
$git_host = $url->getHost();
$git_repository = $url->getSegment(1) . '/' . $url->getSegment(2);
$git_branch = $url->getSegment(4) ?? 'main';
$project = Project::create([
'name' => fake()->company(),
'description' => fake()->sentence(),
'team_id' => session('currentTeam')->id,
]);
$application_init = [
'name' => fake()->words(2, true),
'git_repository' => $git_repository,
'git_branch' => $git_branch,
'build_pack' => 'nixpacks',
'ports_exposes' => $this->port,
'environment_id' => $project->environments->first()->id,
'destination_id' => $this->chosenDestination->id,
'destination_type' => $this->chosenDestination->getMorphClass(),
];
if ($git_host == 'github.com') {
$application_init['source_id'] = GithubApp::where('name', 'Public GitHub')->first()->id;
$application_init['source_type'] = GithubApp::class;
} elseif ($git_host == 'gitlab.com') {
$application_init['source_id'] = GitlabApp::where('name', 'Public GitLab')->first()->id;
$application_init['source_type'] = GitlabApp::class;
} elseif ($git_host == 'bitbucket.org') {
// $application_init['source_id'] = GithubApp::where('name', 'Public Bitbucket')->first()->id;
// $application_init['source_type'] = GithubApp::class;
}
Application::create($application_init);
}
}

View File

@@ -1,10 +0,0 @@
<?php
namespace App\Http\Livewire\Project;
use Livewire\Component;
class NewProject extends Component
{
}

View File

@@ -393,7 +393,7 @@ class DeployApplicationJob implements ShouldQueue
if ($this->application->source->getMorphClass() == 'App\Models\GithubApp') {
if ($this->source->is_public) {
$git_clone_command = "{$git_clone_command} {$this->source->html_url}/{$this->application->git_repository}.git {$this->workdir}";
$git_clone_command = "{$git_clone_command} {$this->source->html_url}/{$this->application->git_repository} {$this->workdir}";
$git_clone_command = $this->setGitImportSettings($git_clone_command);
return [
$this->execute_in_builder($git_clone_command)

View File

@@ -16,6 +16,20 @@ class Application extends BaseModel
});
}
protected $fillable = [
'name',
'description',
'git_repository',
'git_branch',
'build_pack',
'environment_id',
'destination_id',
'destination_type',
'source_id',
'source_type',
'ports_mappings',
'ports_exposes',
];
public function environment()
{
return $this->belongsTo(Environment::class);

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class ApplicationSetting extends Model
{
protected $fillable = [
'application_id',
'is_git_submodules_allowed',
'is_git_lfs_allowed',
];

View File

@@ -2,8 +2,21 @@
namespace App\Models;
class Environment extends BaseModel
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
class Environment extends Model
{
protected $fillable = [
'name',
'project_id',
];
protected function name(): Attribute
{
return Attribute::make(
set: fn (string $value) => strtolower($value),
);
}
public function project()
{
return $this->belongsTo(Project::class);
@@ -21,4 +34,3 @@ class Environment extends BaseModel
return $this->hasMany(Service::class);
}
}

13
app/Models/Git.php Normal file
View File

@@ -0,0 +1,13 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Git extends Model
{
public function applications()
{
return $this->morphMany(Application::class, 'source');
}
}

View File

@@ -1,7 +0,0 @@
<?php
namespace App\Models;
class GitDeployKey extends BaseModel
{
}

View File

@@ -4,6 +4,10 @@ namespace App\Models;
class GitlabApp extends BaseModel
{
public function applications()
{
return $this->morphMany(Application::class, 'source');
}
public function privateKey()
{
return $this->belongsTo(PrivateKey::class);

View File

@@ -2,10 +2,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class InstanceSettings extends Model
{
use HasFactory;
}

View File

@@ -10,15 +10,28 @@ class Project extends BaseModel
ProjectSetting::create([
'project_id' => $project->id,
]);
Environment::create([
'name' => 'Production',
'project_id' => $project->id,
]);
});
}
public function environments() {
protected $fillable = [
'name',
'description',
'team_id',
'project_id'
];
public function environments()
{
return $this->hasMany(Environment::class);
}
public function settings() {
public function settings()
{
return $this->hasOne(ProjectSetting::class);
}
public function applications() {
public function applications()
{
return $this->hasManyThrough(Application::class, Environment::class);
}
}

View File

@@ -4,4 +4,7 @@ namespace App\Models;
class ProjectSetting extends BaseModel
{
protected $fillable = [
'project_id'
];
}

View File

@@ -12,6 +12,10 @@ class Server extends BaseModel
]);
});
}
public function destinations()
{
return $this->hasMany(PrivateKey::class);
}
public function privateKey()
{
return $this->belongsTo(PrivateKey::class);

View File

@@ -0,0 +1,31 @@
<?php
namespace App\View\Components;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class FormInput extends Component
{
/**
* Create a new component instance.
*/
public function __construct(
public string $id,
public bool $required = false,
public bool $readonly = false,
public string|null $label = null,
public string|null $type = 'text',
public bool $instantSave = false,
) {
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.form-input');
}
}

View File

@@ -12,14 +12,12 @@ class Input extends Component
* Create a new component instance.
*/
public function __construct(
public string $name,
public string $id,
public bool $required = false,
public bool $readonly = false,
public string|null $label = null,
public string|null $type = 'text',
public bool $instantSave = false,
) {
//
}
/**