refactor a lot of things
fix: postgres_passwords could be longer feat: able to define postgresql databases from the ui
This commit is contained in:
3
bootstrap/helpers/contants.php
Normal file
3
bootstrap/helpers/contants.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
const DATABASE_TYPES = ['postgresql'];
|
||||
28
bootstrap/helpers/databases.php
Normal file
28
bootstrap/helpers/databases.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use App\Models\StandaloneDocker;
|
||||
use App\Models\StandalonePostgresql;
|
||||
use Visus\Cuid2\Cuid2;
|
||||
|
||||
function generate_database_name(string $type): string
|
||||
{
|
||||
$cuid = new Cuid2(7);
|
||||
return $type . '-database-' . $cuid;
|
||||
}
|
||||
|
||||
function create_standalone_postgresql($environment_id, $destination_uuid): StandalonePostgresql
|
||||
{
|
||||
// TODO: If another type of destination is added, this will need to be updated.
|
||||
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
|
||||
if (!$destination) {
|
||||
throw new Exception('Destination not found');
|
||||
}
|
||||
return StandalonePostgresql::create([
|
||||
'name' => generate_database_name('postgresql'),
|
||||
'postgres_password' => \Illuminate\Support\Str::password(),
|
||||
'environment_id' => $environment_id,
|
||||
'destination_id' => $destination->id,
|
||||
'destination_type' => $destination->getMorphClass(),
|
||||
]);
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@ function get_proxy_path()
|
||||
function generate_default_proxy_configuration(Server $server)
|
||||
{
|
||||
$proxy_path = get_proxy_path();
|
||||
if (isDev()) {
|
||||
if (is_dev()) {
|
||||
$proxy_path = config('coolify.dev_config_path') . '/' . $server->name . '/proxy';
|
||||
}
|
||||
$networks = collect($server->standaloneDockers)->map(function ($docker) {
|
||||
@@ -85,7 +85,7 @@ function generate_default_proxy_configuration(Server $server)
|
||||
],
|
||||
],
|
||||
];
|
||||
if (isDev()) {
|
||||
if (is_dev()) {
|
||||
$config['services']['traefik']['command'][] = "--log.level=debug";
|
||||
}
|
||||
return Yaml::dump($config, 4, 2);
|
||||
|
||||
@@ -5,37 +5,45 @@ use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Str;
|
||||
use Nubs\RandomNameGenerator\All;
|
||||
use Visus\Cuid2\Cuid2;
|
||||
|
||||
function application_configuration_dir() :string {
|
||||
function application_configuration_dir(): string
|
||||
{
|
||||
return '/data/coolify/applications';
|
||||
}
|
||||
function database_configuration_dir(): string {
|
||||
|
||||
function database_configuration_dir(): string
|
||||
{
|
||||
return '/data/coolify/databases';
|
||||
}
|
||||
function backup_dir(): string {
|
||||
|
||||
function backup_dir(): string
|
||||
{
|
||||
return '/data/coolify/backups';
|
||||
}
|
||||
function generate_readme_file(string $name, string $updated_at): string {
|
||||
return "Resource name: {$name}\nLatest Deployment Date: {$updated_at}";
|
||||
|
||||
function generate_readme_file(string $name, string $updated_at): string
|
||||
{
|
||||
return "Resource name: $name\nLatest Deployment Date: $updated_at";
|
||||
}
|
||||
|
||||
function general_error_handler(\Throwable|null $err = null, $that = null, $isJson = false, $customErrorMessage = null)
|
||||
function general_error_handler(Throwable|null $err = null, $that = null, $isJson = false, $customErrorMessage = null): mixed
|
||||
{
|
||||
try {
|
||||
ray('ERROR OCCURED: ' . $err->getMessage());
|
||||
ray('ERROR OCCURRED: ' . $err->getMessage());
|
||||
if ($err instanceof QueryException) {
|
||||
if ($err->errorInfo[0] === '23505') {
|
||||
throw new \Exception($customErrorMessage ?? 'Duplicate entry found.', '23505');
|
||||
throw new Exception($customErrorMessage ?? 'Duplicate entry found.', '23505');
|
||||
} else if (count($err->errorInfo) === 4) {
|
||||
throw new \Exception($customErrorMessage ?? $err->errorInfo[3]);
|
||||
throw new Exception($customErrorMessage ?? $err->errorInfo[3]);
|
||||
} else {
|
||||
throw new \Exception($customErrorMessage ?? $err->errorInfo[2]);
|
||||
throw new Exception($customErrorMessage ?? $err->errorInfo[2]);
|
||||
}
|
||||
} else {
|
||||
throw new \Exception($customErrorMessage ?? $err->getMessage());
|
||||
throw new Exception($customErrorMessage ?? $err->getMessage());
|
||||
}
|
||||
} catch (\Throwable $error) {
|
||||
} catch (Throwable $error) {
|
||||
if ($that) {
|
||||
return $that->emit('error', $customErrorMessage ?? $error->getMessage());
|
||||
} elseif ($isJson) {
|
||||
@@ -46,51 +54,54 @@ function general_error_handler(\Throwable|null $err = null, $that = null, $isJso
|
||||
} else {
|
||||
ray($customErrorMessage);
|
||||
ray($error);
|
||||
return $customErrorMessage ?? $error->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getRouteParameters()
|
||||
function get_route_parameters(): array
|
||||
{
|
||||
return Route::current()->parameters();
|
||||
}
|
||||
|
||||
function get_latest_version_of_coolify()
|
||||
function get_latest_version_of_coolify(): string
|
||||
{
|
||||
try {
|
||||
$response = Http::get('https://cdn.coollabs.io/coolify/versions.json');
|
||||
$versions = $response->json();
|
||||
return data_get($versions, 'coolify.v4.version');
|
||||
} catch (\Throwable $th) {
|
||||
} catch (Throwable $th) {
|
||||
//throw $th;
|
||||
ray($th->getMessage());
|
||||
return '0.0.0';
|
||||
}
|
||||
}
|
||||
|
||||
function generate_random_name()
|
||||
function generate_random_name(): string
|
||||
{
|
||||
$generator = \Nubs\RandomNameGenerator\All::create();
|
||||
$generator = All::create();
|
||||
$cuid = new Cuid2(7);
|
||||
return Str::kebab("{$generator->getName()}-{$cuid}");
|
||||
return Str::kebab("{$generator->getName()}-$cuid");
|
||||
}
|
||||
|
||||
function generate_application_name(string $git_repository, string $git_branch)
|
||||
function generate_application_name(string $git_repository, string $git_branch): string
|
||||
{
|
||||
$cuid = new Cuid2(7);
|
||||
return Str::kebab("{$git_repository}:{$git_branch}-{$cuid}");
|
||||
return Str::kebab("$git_repository:$git_branch-$cuid");
|
||||
}
|
||||
|
||||
function is_transactional_emails_active()
|
||||
function is_transactional_emails_active(): bool
|
||||
{
|
||||
return data_get(InstanceSettings::get(), 'smtp_enabled');
|
||||
}
|
||||
|
||||
function set_transanctional_email_settings()
|
||||
function set_transanctional_email_settings(): void
|
||||
{
|
||||
$settings = InstanceSettings::get();
|
||||
$password = data_get($settings, 'smtp_password');
|
||||
if ($password) $password = decrypt($password);
|
||||
if (isset($password)) {
|
||||
$password = decrypt($password);
|
||||
}
|
||||
|
||||
config()->set('mail.default', 'smtp');
|
||||
config()->set('mail.mailers.smtp', [
|
||||
@@ -105,16 +116,19 @@ function set_transanctional_email_settings()
|
||||
]);
|
||||
}
|
||||
|
||||
function base_ip()
|
||||
function base_ip(): string
|
||||
{
|
||||
if (isDev()) {
|
||||
if (is_dev()) {
|
||||
return "http://localhost";
|
||||
}
|
||||
$settings = InstanceSettings::get();
|
||||
return "http://{$settings->public_ipv4}";
|
||||
return "http://$settings->public_ipv4";
|
||||
}
|
||||
|
||||
function base_url(bool $withPort = true)
|
||||
/**
|
||||
* If fqdn is set, return it, otherwise return public ip.
|
||||
*/
|
||||
function base_url(bool $withPort = true): string
|
||||
{
|
||||
$settings = InstanceSettings::get();
|
||||
if ($settings->fqdn) {
|
||||
@@ -123,31 +137,32 @@ function base_url(bool $withPort = true)
|
||||
$port = config('app.port');
|
||||
if ($settings->public_ipv4) {
|
||||
if ($withPort) {
|
||||
if (isDev()) {
|
||||
return "http://localhost:{$port}";
|
||||
if (is_dev()) {
|
||||
return "http://localhost:$port";
|
||||
}
|
||||
return "http://{$settings->public_ipv4}:{$port}";
|
||||
return "http://$settings->public_ipv4:$port";
|
||||
}
|
||||
if (isDev()) {
|
||||
if (is_dev()) {
|
||||
return "http://localhost";
|
||||
}
|
||||
return "http://{$settings->public_ipv4}";
|
||||
return "http://$settings->public_ipv4";
|
||||
}
|
||||
if ($settings->public_ipv6) {
|
||||
if ($withPort) {
|
||||
return "http://{$settings->public_ipv6}:{$port}";
|
||||
return "http://$settings->public_ipv6:$port";
|
||||
}
|
||||
return "http://{$settings->public_ipv6}";
|
||||
return "http://$settings->public_ipv6";
|
||||
}
|
||||
return url('/');
|
||||
}
|
||||
|
||||
function isDev()
|
||||
function is_dev(): bool
|
||||
{
|
||||
return config('app.env') === 'local';
|
||||
}
|
||||
|
||||
function isCloud()
|
||||
function is_cloud(): bool
|
||||
{
|
||||
return !config('coolify.self_hosted');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user