save things
This commit is contained in:
parent
dfecf2cc60
commit
d77d32853f
@ -35,7 +35,7 @@ class Change extends Component
|
|||||||
$this->private_key->save();
|
$this->private_key->save();
|
||||||
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
|
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->addError('private_key_value', $e->getMessage());
|
return generalErrorHandlerLivewire($e, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class Deploy extends Component
|
|||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
$this->parameters = saveParameters();
|
$this->parameters = getParameters();
|
||||||
$this->application = Application::where('id', $this->applicationId)->first();
|
$this->application = Application::where('id', $this->applicationId)->first();
|
||||||
$this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
|
$this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class Add extends Component
|
|||||||
];
|
];
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
$this->parameters = saveParameters();
|
$this->parameters = getParameters();
|
||||||
}
|
}
|
||||||
public function submit()
|
public function submit()
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@ class Show extends Component
|
|||||||
];
|
];
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
$this->parameters = saveParameters();
|
$this->parameters = getParameters();
|
||||||
}
|
}
|
||||||
public function submit()
|
public function submit()
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,7 @@ class Add extends Component
|
|||||||
];
|
];
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
$this->parameters = saveParameters();
|
$this->parameters = getParameters();
|
||||||
}
|
}
|
||||||
public function submit()
|
public function submit()
|
||||||
{
|
{
|
||||||
|
@ -130,12 +130,12 @@ class GithubPrivateRepository extends Component
|
|||||||
'environment_name' => $environment->name
|
'environment_name' => $environment->name
|
||||||
]);
|
]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->emit('error', $e->getMessage());
|
return generalErrorHandlerLivewire($e, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
$this->parameters = saveParameters();
|
$this->parameters = getParameters();
|
||||||
$this->repositories = $this->branches = $this->servers = $this->destinations = collect();
|
$this->repositories = $this->branches = $this->servers = $this->destinations = collect();
|
||||||
$this->github_apps = GithubApp::private();
|
$this->github_apps = GithubApp::private();
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ class PublicGitRepository extends Component
|
|||||||
$this->public_repository_url = 'https://github.com/coollabsio/coolify-examples/tree/nodejs-fastify';
|
$this->public_repository_url = 'https://github.com/coollabsio/coolify-examples/tree/nodejs-fastify';
|
||||||
$this->port = 3000;
|
$this->port = 3000;
|
||||||
}
|
}
|
||||||
$this->parameters = saveParameters();
|
$this->parameters = getParameters();
|
||||||
$this->servers = session('currentTeam')->load(['servers'])->servers;
|
$this->servers = session('currentTeam')->load(['servers'])->servers;
|
||||||
}
|
}
|
||||||
public function chooseServer($server)
|
public function chooseServer($server)
|
||||||
|
@ -54,6 +54,7 @@ class Form extends Component
|
|||||||
$this->dockerComposeVersion = 'Not installed.';
|
$this->dockerComposeVersion = 'Not installed.';
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
return generalErrorHandlerLivewire($e, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public function delete()
|
public function delete()
|
||||||
|
@ -20,7 +20,7 @@ class PrivateKey extends Component
|
|||||||
}
|
}
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
$this->parameters = saveParameters();
|
$this->parameters = getParameters();
|
||||||
$this->private_keys = ModelsPrivateKey::where('team_id', session('currentTeam')->id)->get();
|
$this->private_keys = ModelsPrivateKey::where('team_id', session('currentTeam')->id)->get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
48
app/Http/Livewire/Source/Create.php
Normal file
48
app/Http/Livewire/Source/Create.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Livewire\Source;
|
||||||
|
|
||||||
|
use App\Models\GithubApp;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
class Create extends Component
|
||||||
|
{
|
||||||
|
public string $name;
|
||||||
|
public string|null $organization = null;
|
||||||
|
public string $api_url = 'https://api.github.com';
|
||||||
|
public string $html_url = 'https://github.com';
|
||||||
|
public string $custom_user = 'git';
|
||||||
|
public int $custom_port = 22;
|
||||||
|
public bool $is_system_wide = false;
|
||||||
|
|
||||||
|
public function mount()
|
||||||
|
{
|
||||||
|
$this->name = generateRandomName();
|
||||||
|
}
|
||||||
|
public function createGitHubApp()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->validate([
|
||||||
|
"name" => 'required|string',
|
||||||
|
"organization" => 'nullable|string',
|
||||||
|
"api_url" => 'required|string',
|
||||||
|
"html_url" => 'required|string',
|
||||||
|
"custom_user" => 'required|string',
|
||||||
|
"custom_port" => 'required|int',
|
||||||
|
"is_system_wide" => 'required|bool',
|
||||||
|
]);
|
||||||
|
GithubApp::create([
|
||||||
|
'name' => $this->name,
|
||||||
|
'organization' => $this->organization,
|
||||||
|
'api_url' => $this->api_url,
|
||||||
|
'html_url' => $this->html_url,
|
||||||
|
'custom_user' => $this->custom_user,
|
||||||
|
'custom_port' => $this->custom_port,
|
||||||
|
'is_system_wide' => $this->is_system_wide,
|
||||||
|
'team_id' => session('currentTeam')->id,
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return generalErrorHandlerLivewire($e, $this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
99
app/Http/Livewire/Source/Github/Change.php
Normal file
99
app/Http/Livewire/Source/Github/Change.php
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Livewire\Source\Github;
|
||||||
|
|
||||||
|
use App\Models\GithubApp;
|
||||||
|
use App\Models\InstanceSettings;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Livewire\Component;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class Change extends Component
|
||||||
|
{
|
||||||
|
public string $host;
|
||||||
|
public $parameters;
|
||||||
|
public GithubApp $github_app;
|
||||||
|
public bool $is_system_wide;
|
||||||
|
|
||||||
|
protected $rules = [
|
||||||
|
'github_app.name' => 'required|string',
|
||||||
|
'github_app.organization' => 'nullable|string',
|
||||||
|
'github_app.api_url' => 'required|string',
|
||||||
|
'github_app.html_url' => 'required|string',
|
||||||
|
'github_app.custom_user' => 'required|string',
|
||||||
|
'github_app.custom_port' => 'required|int',
|
||||||
|
'github_app.app_id' => 'required|int',
|
||||||
|
'github_app.installation_id' => 'required|int',
|
||||||
|
'github_app.client_id' => 'required|string',
|
||||||
|
'github_app.client_secret' => 'required|string',
|
||||||
|
'github_app.webhook_secret' => 'required|string',
|
||||||
|
'github_app.is_system_wide' => 'required|bool',
|
||||||
|
];
|
||||||
|
public function submit()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->validate();
|
||||||
|
$this->github_app->save();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return generalErrorHandlerLivewire($e, $this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function instantSave()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->github_app->is_system_wide = $this->is_system_wide;
|
||||||
|
$this->github_app->save();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return generalErrorHandlerLivewire($e, $this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function mount()
|
||||||
|
{
|
||||||
|
$this->parameters = getParameters();
|
||||||
|
$this->github_app = GithubApp::where('uuid', $this->parameters['github_app_uuid'])->first();
|
||||||
|
$this->is_system_wide = $this->github_app->is_system_wide;
|
||||||
|
}
|
||||||
|
public function createGithubApp()
|
||||||
|
{
|
||||||
|
$settings = InstanceSettings::first();
|
||||||
|
$fqdn = $settings->fqdn;
|
||||||
|
if (!$fqdn) {
|
||||||
|
$fqdn = $this->host;
|
||||||
|
}
|
||||||
|
if ($this->github_app->organization) {
|
||||||
|
$url = 'organizations/' . $this->github_app->organization . '/settings/apps/new';
|
||||||
|
} else {
|
||||||
|
$url = 'settings/apps/new';
|
||||||
|
}
|
||||||
|
$name = Str::kebab('coolify' . $this->github_app->name);
|
||||||
|
$data = [
|
||||||
|
"name" => $name,
|
||||||
|
"url" => $fqdn,
|
||||||
|
"hook_attributes" => [
|
||||||
|
"url" => "$fqdn/webhooks/github/events"
|
||||||
|
],
|
||||||
|
"redirect_url" => "$fqdn/webhooks/github",
|
||||||
|
"callback_url" => [
|
||||||
|
"$fqdn/login/github/app",
|
||||||
|
],
|
||||||
|
"public" => false,
|
||||||
|
"request_oauth_on_install" => false,
|
||||||
|
"setup_url" => "$fqdn/webhooks/github/install?source_id=" . $this->github_app->uuid,
|
||||||
|
"setup_on_update" => true,
|
||||||
|
"default_permissions" => [
|
||||||
|
"contents" => 'read',
|
||||||
|
"metadata" => 'read',
|
||||||
|
"pull_requests" => 'read',
|
||||||
|
"emails" => 'read'
|
||||||
|
],
|
||||||
|
"default_events" => ['pull_request', 'push']
|
||||||
|
];
|
||||||
|
$response = Http::asForm()->post("{$this->github_app->html_url}/{$url}?state={$this->github_app->uuid}", [
|
||||||
|
'id' => 'manifest',
|
||||||
|
'name' => 'manifest',
|
||||||
|
'data' => json_encode($data),
|
||||||
|
]);
|
||||||
|
dd($response);
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,6 @@ use Illuminate\Support\Str;
|
|||||||
|
|
||||||
class EnvironmentVariable extends Model
|
class EnvironmentVariable extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $fillable = ['key', 'value', 'is_build_time', 'application_id'];
|
protected $fillable = ['key', 'value', 'is_build_time', 'application_id'];
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
"key" => 'string',
|
"key" => 'string',
|
||||||
|
@ -4,6 +4,7 @@ namespace App\Models;
|
|||||||
|
|
||||||
class GithubApp extends BaseModel
|
class GithubApp extends BaseModel
|
||||||
{
|
{
|
||||||
|
protected $fillable = ['name', 'organization', 'api_url', 'html_url', 'custom_user', 'custom_port', 'team_id'];
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'is_public' => 'boolean',
|
'is_public' => 'boolean',
|
||||||
];
|
];
|
||||||
|
@ -20,8 +20,10 @@ if (!function_exists('generalErrorHandlerLivewire')) {
|
|||||||
if ($e instanceof QueryException) {
|
if ($e instanceof QueryException) {
|
||||||
if ($e->errorInfo[0] === '23505') {
|
if ($e->errorInfo[0] === '23505') {
|
||||||
$that->emit('error', 'Duplicate entry found.');
|
$that->emit('error', 'Duplicate entry found.');
|
||||||
} else {
|
} else if (count($e->errorInfo) === 4) {
|
||||||
$that->emit('error', $e->errorInfo[3]);
|
$that->emit('error', $e->errorInfo[3]);
|
||||||
|
} else {
|
||||||
|
$that->emit('error', $e->errorInfo[2]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$that->emit('error', $e);
|
$that->emit('error', $e);
|
||||||
@ -207,8 +209,8 @@ if (!function_exists('generate_github_token')) {
|
|||||||
return $token->json()['token'];
|
return $token->json()['token'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!function_exists('saveParameters')) {
|
if (!function_exists('getParameters')) {
|
||||||
function saveParameters()
|
function getParameters()
|
||||||
{
|
{
|
||||||
return Route::current()->parameters();
|
return Route::current()->parameters();
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@ return new class extends Migration
|
|||||||
$table->string('organization')->nullable();
|
$table->string('organization')->nullable();
|
||||||
$table->string('api_url');
|
$table->string('api_url');
|
||||||
$table->string('html_url');
|
$table->string('html_url');
|
||||||
$table->integer('custom_port')->default(22);
|
|
||||||
$table->string('custom_user')->default('git');
|
$table->string('custom_user')->default('git');
|
||||||
|
$table->integer('custom_port')->default(22);
|
||||||
|
|
||||||
$table->integer('app_id')->nullable();
|
$table->integer('app_id')->nullable();
|
||||||
$table->integer('installation_id')->nullable();
|
$table->integer('installation_id')->nullable();
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
window.location.reload();
|
window.location.reload();
|
||||||
})
|
})
|
||||||
Livewire.on('error', (message) => {
|
Livewire.on('error', (message) => {
|
||||||
alert(message);
|
console.log(message);
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@endauth
|
@endauth
|
||||||
|
@ -31,4 +31,12 @@
|
|||||||
@empty
|
@empty
|
||||||
<p>No servers found.</p>
|
<p>No servers found.</p>
|
||||||
@endforelse
|
@endforelse
|
||||||
|
<h1>GitHub Apps <a href="{{ route('source.new') }}">
|
||||||
|
<x-inputs.button>New</x-inputs.button>
|
||||||
|
</a></h1>
|
||||||
|
@forelse ($github_apps as $github_app)
|
||||||
|
<a href="{{ route('source.github.show', [$github_app->uuid]) }}">{{ data_get($github_app, 'name') }}</a>
|
||||||
|
@empty
|
||||||
|
<p>No servers found.</p>
|
||||||
|
@endforelse
|
||||||
</x-layout>
|
</x-layout>
|
||||||
|
14
resources/views/livewire/source/create.blade.php
Normal file
14
resources/views/livewire/source/create.blade.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<div>
|
||||||
|
<form class="flex flex-col gap-2 w-96" wire:submit.prevent='createGitHubApp'>
|
||||||
|
<x-inputs.input id="name" label="Name" required />
|
||||||
|
<x-inputs.input id="html_url" label="HTML Url" required />
|
||||||
|
<x-inputs.input id="api_url" label="API Url" required />
|
||||||
|
<x-inputs.input id="organization" label="Organization" />
|
||||||
|
<x-inputs.input id="custom_user" label="Custom Git User" required />
|
||||||
|
<x-inputs.input id="custom_port" label="Custom Git Port" required />
|
||||||
|
<x-inputs.input type="checkbox" id="is_system_wide" label="System Wide" />
|
||||||
|
<x-inputs.button type="submit">
|
||||||
|
Submit
|
||||||
|
</x-inputs.button>
|
||||||
|
</form>
|
||||||
|
</div>
|
30
resources/views/livewire/source/github/change.blade.php
Normal file
30
resources/views/livewire/source/github/change.blade.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<div>
|
||||||
|
<h3>Change Github App</h3>
|
||||||
|
<form wire:submit.prevent='submit'>
|
||||||
|
<x-inputs.input id="github_app.name" label="App Name" required />
|
||||||
|
<x-inputs.input noDirty type="checkbox" label="System Wide?" instantSave id="is_system_wide" />
|
||||||
|
@if ($github_app->app_id)
|
||||||
|
<x-inputs.input id="github_app.organization" label="Organization" disabled
|
||||||
|
placeholder="Personal user if empty" />
|
||||||
|
@else
|
||||||
|
<x-inputs.input id="github_app.organization" label="Organization" placeholder="Personal user if empty" />
|
||||||
|
@endif
|
||||||
|
<x-inputs.input id="github_app.api_url" label="API Url" disabled />
|
||||||
|
<x-inputs.input id="github_app.html_url" label="HTML Url" disabled />
|
||||||
|
<x-inputs.input id="github_app.custom_user" label="User" required />
|
||||||
|
<x-inputs.input type="number" id="github_app.custom_port" label="Port" required />
|
||||||
|
@if ($github_app->app_id)
|
||||||
|
<x-inputs.input type="number" id="github_app.app_id" label="App Id" disabled />
|
||||||
|
<x-inputs.input type="number" id="github_app.installation_id" label="Installation Id" disabled />
|
||||||
|
<x-inputs.input id="github_app.client_id" label="Client Id" type="password" disabled />
|
||||||
|
<x-inputs.input id="github_app.client_secret" label="Client Secret" type="password" disabled />
|
||||||
|
<x-inputs.input id="github_app.webhook_secret" label="Webhook Secret" type="password" disabled />
|
||||||
|
<x-inputs.button type="submit">Save</x-inputs.button>
|
||||||
|
@else
|
||||||
|
<div class="py-2">
|
||||||
|
<x-inputs.button type="submit">Save</x-inputs.button>
|
||||||
|
<x-inputs.button wire:click.prevent='createGithubApp'>Create GitHub Application</x-inputs.button>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</form>
|
||||||
|
</div>
|
4
resources/views/source/github/show.blade.php
Normal file
4
resources/views/source/github/show.blade.php
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<x-layout>
|
||||||
|
<h1>GitHub App</h1>
|
||||||
|
<livewire:source.github.change :host="$host" />
|
||||||
|
</x-layout>
|
4
resources/views/source/new.blade.php
Normal file
4
resources/views/source/new.blade.php
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<x-layout>
|
||||||
|
<h1>New Git App</h1>
|
||||||
|
<livewire:source.create />
|
||||||
|
</x-layout>
|
@ -8,7 +8,10 @@ use App\Models\PrivateKey;
|
|||||||
use App\Models\StandaloneDocker;
|
use App\Models\StandaloneDocker;
|
||||||
use App\Models\SwarmDocker;
|
use App\Models\SwarmDocker;
|
||||||
use App\Http\Controllers\ServerController;
|
use App\Http\Controllers\ServerController;
|
||||||
|
use App\Models\GithubApp;
|
||||||
|
use App\Models\Project;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -26,18 +29,21 @@ use Illuminate\Support\Facades\Route;
|
|||||||
|
|
||||||
Route::middleware(['auth'])->group(function () {
|
Route::middleware(['auth'])->group(function () {
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
$projects = session('currentTeam')->load(['projects'])->projects;
|
$id = session('currentTeam')->id;
|
||||||
$servers = session('currentTeam')->load(['servers'])->servers;
|
$projects = Project::where('team_id', $id)->get();
|
||||||
|
$servers = Server::where('team_id', $id)->get();
|
||||||
$destinations = $servers->map(function ($server) {
|
$destinations = $servers->map(function ($server) {
|
||||||
return $server->standaloneDockers->merge($server->swarmDockers);
|
return $server->standaloneDockers->merge($server->swarmDockers);
|
||||||
})->flatten();
|
})->flatten();
|
||||||
$private_keys = session('currentTeam')->load(['privateKeys'])->privateKeys;
|
$private_keys = PrivateKey::where('team_id', $id)->get();
|
||||||
|
$github_apps = GithubApp::private();
|
||||||
|
|
||||||
return view('dashboard', [
|
return view('dashboard', [
|
||||||
'servers' => $servers->sortBy('name'),
|
'servers' => $servers->sortBy('name'),
|
||||||
'projects' => $projects->sortBy('name'),
|
'projects' => $projects->sortBy('name'),
|
||||||
'destinations' => $destinations->sortBy('name'),
|
'destinations' => $destinations->sortBy('name'),
|
||||||
'private_keys' => $private_keys->sortBy('name'),
|
'private_keys' => $private_keys->sortBy('name'),
|
||||||
|
'github_apps' => $github_apps->sortBy('name'),
|
||||||
]);
|
]);
|
||||||
})->name('dashboard');
|
})->name('dashboard');
|
||||||
|
|
||||||
@ -75,6 +81,12 @@ Route::middleware(['auth'])->group(function () {
|
|||||||
]);
|
]);
|
||||||
})->name('private-key.show');
|
})->name('private-key.show');
|
||||||
});
|
});
|
||||||
|
Route::middleware(['auth'])->group(function () {
|
||||||
|
Route::get('/source/new', fn () => view('source.new'))->name('source.new');
|
||||||
|
Route::get('/source/github/{github_app_uuid}', function (Request $request) {
|
||||||
|
return view('source.github.show', ['host' => $request->schemeAndHttpHost()]);
|
||||||
|
})->name('source.github.show');
|
||||||
|
});
|
||||||
Route::middleware(['auth'])->group(function () {
|
Route::middleware(['auth'])->group(function () {
|
||||||
Route::get('/server/new', fn () => view('server.new'))->name('server.new');
|
Route::get('/server/new', fn () => view('server.new'))->name('server.new');
|
||||||
Route::get('/server/{server_uuid}', function () {
|
Route::get('/server/{server_uuid}', function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user