Fix styling

This commit is contained in:
Thijmen
2024-06-10 20:43:34 +00:00
committed by github-actions[bot]
parent 41fb6a1fc9
commit d86274cc37
429 changed files with 5307 additions and 2831 deletions

View File

@@ -8,11 +8,14 @@ use Livewire\Component;
class AddEmpty extends Component
{
public string $name = '';
public string $description = '';
protected $rules = [
'name' => 'required|string|min:3',
'description' => 'nullable|string',
];
protected $validationAttributes = [
'name' => 'Project Name',
'description' => 'Project Description',
@@ -27,6 +30,7 @@ class AddEmpty extends Component
'description' => $this->description,
'team_id' => currentTeam()->id,
]);
return redirect()->route('project.show', $project->uuid);
} catch (\Throwable $e) {
return handleError($e, $this);

View File

@@ -9,11 +9,15 @@ use Livewire\Component;
class AddEnvironment extends Component
{
public Project $project;
public string $name = '';
public string $description = '';
protected $rules = [
'name' => 'required|string|min:3',
];
protected $validationAttributes = [
'name' => 'Environment Name',
];

View File

@@ -8,9 +8,13 @@ use Livewire\Component;
class Advanced extends Component
{
public Application $application;
public bool $is_force_https_enabled;
public bool $is_gzip_enabled;
public bool $is_stripprefix_enabled;
protected $rules = [
'application.settings.is_git_submodules_enabled' => 'boolean|required',
'application.settings.is_git_lfs_enabled' => 'boolean|required',
@@ -31,18 +35,21 @@ class Advanced extends Component
'application.settings.is_raw_compose_deployment_enabled' => 'boolean|required',
'application.settings.connect_to_docker_network' => 'boolean|required',
];
public function mount()
{
$this->is_force_https_enabled = $this->application->isForceHttpsEnabled();
$this->is_gzip_enabled = $this->application->isGzipEnabled();
$this->is_stripprefix_enabled = $this->application->isStripprefixEnabled();
}
public function instantSave()
{
if ($this->application->isLogDrainEnabled()) {
if (!$this->application->destination->server->isLogDrainEnabled()) {
if (! $this->application->destination->server->isLogDrainEnabled()) {
$this->application->settings->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on this server.');
return;
}
}
@@ -67,6 +74,7 @@ class Advanced extends Component
$this->dispatch('success', 'Settings saved.');
$this->dispatch('configurationChanged');
}
public function submit()
{
if ($this->application->settings->gpu_count && $this->application->settings->gpu_device_ids) {
@@ -74,11 +82,13 @@ class Advanced extends Component
$this->application->settings->gpu_count = null;
$this->application->settings->gpu_device_ids = null;
$this->application->settings->save();
return;
}
$this->application->settings->save();
$this->dispatch('success', 'Settings saved.');
}
public function saveCustomName()
{
if (isset($this->application->settings->custom_internal_name)) {
@@ -89,6 +99,7 @@ class Advanced extends Component
$this->application->settings->save();
$this->dispatch('success', 'Custom name saved.');
}
public function render()
{
return view('livewire.project.application.advanced');

View File

@@ -9,21 +9,23 @@ use Livewire\Component;
class Configuration extends Component
{
public Application $application;
public $servers;
protected $listeners = ['buildPackUpdated' => '$refresh'];
public function mount()
{
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
if (! $project) {
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
if (! $environment) {
return redirect()->route('dashboard');
}
$application = $environment->applications->where('uuid', request()->route('application_uuid'))->first();
if (!$application) {
if (! $application) {
return redirect()->route('dashboard');
}
$this->application = $application;
@@ -33,6 +35,7 @@ class Configuration extends Component
return $server->id != $mainServer->id;
});
}
public function render()
{
return view('livewire.project.application.configuration');

View File

@@ -9,27 +9,37 @@ use Livewire\Component;
class Index extends Component
{
public Application $application;
public ?Collection $deployments;
public int $deployments_count = 0;
public string $current_url;
public int $skip = 0;
public int $default_take = 40;
public bool $show_next = false;
public bool $show_prev = false;
public ?string $pull_request_id = null;
protected $queryString = ['pull_request_id'];
public function mount()
{
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
if (! $project) {
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
if (! $environment) {
return redirect()->route('dashboard');
}
$application = $environment->applications->where('uuid', request()->route('application_uuid'))->first();
if (!$application) {
if (! $application) {
return redirect()->route('dashboard');
}
['deployments' => $deployments, 'count' => $count] = $application->deployments(0, 40);
@@ -40,12 +50,14 @@ class Index extends Component
$this->show_pull_request_only();
$this->show_more();
}
private function show_pull_request_only()
{
if ($this->pull_request_id) {
$this->deployments = $this->deployments->where('pull_request_id', $this->pull_request_id);
}
}
private function show_more()
{
if ($this->deployments->count() !== 0) {
@@ -53,6 +65,7 @@ class Index extends Component
if ($this->deployments->count() < $this->default_take) {
$this->show_next = false;
}
return;
}
}
@@ -61,6 +74,7 @@ class Index extends Component
{
$this->load_deployments();
}
public function previous_page(?int $take = null)
{
if ($take) {
@@ -73,6 +87,7 @@ class Index extends Component
}
$this->load_deployments();
}
public function next_page(?int $take = null)
{
if ($take) {
@@ -81,6 +96,7 @@ class Index extends Component
$this->show_prev = true;
$this->load_deployments();
}
public function load_deployments()
{
['deployments' => $deployments, 'count' => $count] = $this->application->deployments($this->skip, $this->default_take);
@@ -89,6 +105,7 @@ class Index extends Component
$this->show_pull_request_only();
$this->show_more();
}
public function render()
{
return view('livewire.project.application.deployment.index');

View File

@@ -9,24 +9,29 @@ use Livewire\Component;
class Show extends Component
{
public Application $application;
public ApplicationDeploymentQueue $application_deployment_queue;
public string $deployment_uuid;
public $isKeepAliveOn = true;
protected $listeners = ['refreshQueue'];
public function mount() {
public function mount()
{
$deploymentUuid = request()->route('deployment_uuid');
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
if (! $project) {
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
if (! $environment) {
return redirect()->route('dashboard');
}
$application = $environment->applications->where('uuid', request()->route('application_uuid'))->first();
if (!$application) {
if (! $application) {
return redirect()->route('dashboard');
}
// $activity = Activity::where('properties->type_uuid', '=', $deploymentUuid)->first();
@@ -38,7 +43,7 @@ class Show extends Component
// ]);
// }
$application_deployment_queue = ApplicationDeploymentQueue::where('deployment_uuid', $deploymentUuid)->first();
if (!$application_deployment_queue) {
if (! $application_deployment_queue) {
return redirect()->route('project.application.deployment.index', [
'project_uuid' => $project->uuid,
'environment_name' => $environment->name,
@@ -63,6 +68,7 @@ class Show extends Component
$this->isKeepAliveOn = false;
}
}
public function render()
{
return view('livewire.project.application.deployment.show');

View File

@@ -12,10 +12,15 @@ use Livewire\Component;
class DeploymentNavbar extends Component
{
public ApplicationDeploymentQueue $application_deployment_queue;
public Application $application;
public Server $server;
public bool $is_debug_enabled = false;
protected $listeners = ['deploymentFinished'];
public function mount()
{
$this->application = Application::find($this->application_deployment_queue->application_id);
@@ -30,20 +35,23 @@ class DeploymentNavbar extends Component
public function show_debug()
{
$this->application->settings->is_debug_enabled = !$this->application->settings->is_debug_enabled;
$this->application->settings->is_debug_enabled = ! $this->application->settings->is_debug_enabled;
$this->application->settings->save();
$this->is_debug_enabled = $this->application->settings->is_debug_enabled;
$this->dispatch('refreshQueue');
}
public function force_start()
{
try {
force_start_deployment($this->application_deployment_queue);
} catch (\Throwable $e) {
ray($e);
return handleError($e, $this);
}
}
public function cancel()
{
try {
@@ -55,7 +63,7 @@ class DeploymentNavbar extends Component
$new_log_entry = [
'command' => $kill_command,
'output' => "Deployment cancelled by user.",
'output' => 'Deployment cancelled by user.',
'type' => 'stderr',
'order' => count($previous_logs) + 1,
'timestamp' => Carbon::now('UTC'),
@@ -69,6 +77,7 @@ class DeploymentNavbar extends Component
instant_remote_process([$kill_command], $server);
} catch (\Throwable $e) {
ray($e);
return handleError($e, $this);
} finally {
$this->application_deployment_queue->update([

View File

@@ -14,30 +14,44 @@ class General extends Component
public string $applicationId;
public Application $application;
public Collection $services;
public string $name;
public ?string $fqdn = null;
public string $git_repository;
public string $git_branch;
public ?string $git_commit_sha = null;
public string $build_pack;
public ?string $ports_exposes = null;
public bool $is_container_label_escape_enabled = true;
public $customLabels;
public bool $labelsChanged = false;
public bool $initLoadingCompose = false;
public ?string $initialDockerComposeLocation = null;
public ?string $initialDockerComposePrLocation = null;
public null|Collection $parsedServices;
public ?Collection $parsedServices;
public $parsedServiceDomains = [];
protected $listeners = [
'resetDefaultLabels',
'configurationChanged' => '$refresh'
'configurationChanged' => '$refresh',
];
protected $rules = [
'application.name' => 'required',
'application.description' => 'nullable',
@@ -78,6 +92,7 @@ class General extends Component
'application.settings.is_container_label_escape_enabled' => 'boolean|required',
'application.watch_paths' => 'nullable',
];
protected $validationAttributes = [
'application.name' => 'name',
'application.description' => 'description',
@@ -114,12 +129,14 @@ class General extends Component
'application.settings.is_container_label_escape_enabled' => 'Is container label escape enabled',
'application.watch_paths' => 'Watch paths',
];
public function mount()
{
try {
$this->parsedServices = $this->application->parseCompose();
if (is_null($this->parsedServices) || empty($this->parsedServices)) {
$this->dispatch('error', "Failed to parse your docker-compose file. Please check the syntax and try again.");
$this->dispatch('error', 'Failed to parse your docker-compose file. Please check the syntax and try again.');
return;
}
} catch (\Throwable $e) {
@@ -133,13 +150,13 @@ class General extends Component
$this->ports_exposes = $this->application->ports_exposes;
$this->is_container_label_escape_enabled = $this->application->settings->is_container_label_escape_enabled;
$this->customLabels = $this->application->parseContainerLabels();
if (!$this->customLabels && $this->application->destination->server->proxyType() !== 'NONE') {
$this->customLabels = str(implode("|", generateLabelsApplication($this->application)))->replace("|", "\n");
if (! $this->customLabels && $this->application->destination->server->proxyType() !== 'NONE') {
$this->customLabels = str(implode('|', generateLabelsApplication($this->application)))->replace('|', "\n");
$this->application->custom_labels = base64_encode($this->customLabels);
$this->application->save();
}
$this->initialDockerComposeLocation = $this->application->docker_compose_location;
if ($this->application->build_pack === 'dockercompose' && !$this->application->docker_compose_raw) {
if ($this->application->build_pack === 'dockercompose' && ! $this->application->docker_compose_raw) {
$this->initLoadingCompose = true;
$this->dispatch('info', 'Loading docker compose file.');
}
@@ -148,6 +165,7 @@ class General extends Component
$this->dispatch('configurationChanged');
}
}
public function instantSave()
{
$this->application->settings->save();
@@ -157,6 +175,7 @@ class General extends Component
$this->resetDefaultLabels(false);
}
}
public function loadComposeFile($isInit = false)
{
try {
@@ -165,7 +184,8 @@ class General extends Component
}
['parsedServices' => $this->parsedServices, 'initialDockerComposeLocation' => $this->initialDockerComposeLocation, 'initialDockerComposePrLocation' => $this->initialDockerComposePrLocation] = $this->application->loadComposeFile($isInit);
if (is_null($this->parsedServices)) {
$this->dispatch('error', "Failed to parse your docker-compose file. Please check the syntax and try again.");
$this->dispatch('error', 'Failed to parse your docker-compose file. Please check the syntax and try again.');
return;
}
$compose = $this->application->parseCompose();
@@ -184,13 +204,13 @@ class General extends Component
[
'mount_path' => $target,
'resource_id' => $this->application->id,
'resource_type' => get_class($this->application)
'resource_type' => get_class($this->application),
],
[
'fs_path' => $source,
'mount_path' => $target,
'resource_id' => $this->application->id,
'resource_type' => get_class($this->application)
'resource_type' => get_class($this->application),
]
);
}
@@ -203,11 +223,13 @@ class General extends Component
$this->application->docker_compose_location = $this->initialDockerComposeLocation;
$this->application->docker_compose_pr_location = $this->initialDockerComposePrLocation;
$this->application->save();
return handleError($e, $this);
} finally {
$this->initLoadingCompose = false;
}
}
public function generateDomain(string $serviceName)
{
$uuid = new Cuid2(7);
@@ -219,14 +241,17 @@ class General extends Component
if ($this->application->build_pack === 'dockercompose') {
$this->loadComposeFile();
}
return $domain;
}
public function updatedApplicationBaseDirectory()
{
if ($this->application->build_pack === 'dockercompose') {
$this->loadComposeFile();
}
}
public function updatedApplicationFqdn()
{
$this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
@@ -237,6 +262,7 @@ class General extends Component
$this->application->fqdn = $this->application->fqdn->unique()->implode(',');
$this->resetDefaultLabels();
}
public function updatedApplicationBuildPack()
{
if ($this->application->build_pack !== 'nixpacks') {
@@ -257,6 +283,7 @@ class General extends Component
$this->submit();
$this->dispatch('buildPackUpdated');
}
public function getWildcardDomain()
{
$server = data_get($this->application, 'destination.server');
@@ -268,9 +295,10 @@ class General extends Component
$this->dispatch('success', 'Wildcard domain generated.');
}
}
public function resetDefaultLabels()
{
$this->customLabels = str(implode("|", generateLabelsApplication($this->application)))->replace("|", "\n");
$this->customLabels = str(implode('|', generateLabelsApplication($this->application)))->replace('|', "\n");
$this->ports_exposes = $this->application->ports_exposes;
$this->is_container_label_escape_enabled = $this->application->settings->is_container_label_escape_enabled;
$this->application->custom_labels = base64_encode($this->customLabels);
@@ -286,8 +314,8 @@ class General extends Component
$domains = str($this->application->fqdn)->trim()->explode(',');
if ($this->application->additional_servers->count() === 0) {
foreach ($domains as $domain) {
if (!validate_dns_entry($domain, $this->application->destination->server)) {
$showToaster && $this->dispatch('error', "Validating DNS failed.", "Make sure you have added the DNS records correctly.<br><br>$domain->{$this->application->destination->server->ip}<br><br>Check this <a target='_blank' class='underline dark:text-white' href='https://coolify.io/docs/knowledge-base/dns-configuration'>documentation</a> for further help.");
if (! validate_dns_entry($domain, $this->application->destination->server)) {
$showToaster && $this->dispatch('error', 'Validating DNS failed.', "Make sure you have added the DNS records correctly.<br><br>$domain->{$this->application->destination->server->ip}<br><br>Check this <a target='_blank' class='underline dark:text-white' href='https://coolify.io/docs/knowledge-base/dns-configuration'>documentation</a> for further help.");
}
}
}
@@ -295,6 +323,7 @@ class General extends Component
$this->application->fqdn = $domains->implode(',');
}
}
public function submit($showToaster = true)
{
try {
@@ -309,8 +338,8 @@ class General extends Component
$this->application->save();
if (!$this->customLabels && $this->application->destination->server->proxyType() !== 'NONE') {
$this->customLabels = str(implode("|", generateLabelsApplication($this->application)))->replace("|", "\n");
if (! $this->customLabels && $this->application->destination->server->proxyType() !== 'NONE') {
$this->customLabels = str(implode('|', generateLabelsApplication($this->application)))->replace('|', "\n");
$this->application->custom_labels = base64_encode($this->customLabels);
$this->application->save();
}
@@ -336,7 +365,7 @@ class General extends Component
}
if (data_get($this->application, 'dockerfile')) {
$port = get_port_from_dockerfile($this->application->dockerfile);
if ($port && !$this->application->ports_exposes) {
if ($port && ! $this->application->ports_exposes) {
$this->application->ports_exposes = $port;
}
}
@@ -351,8 +380,8 @@ class General extends Component
foreach ($this->parsedServiceDomains as $serviceName => $service) {
$domain = data_get($service, 'domain');
if ($domain) {
if (!validate_dns_entry($domain, $this->application->destination->server)) {
$showToaster && $this->dispatch('error', "Validating DNS failed.", "Make sure you have added the DNS records correctly.<br><br>$domain->{$this->application->destination->server->ip}<br><br>Check this <a target='_blank' class='underline dark:text-white' href='https://coolify.io/docs/knowledge-base/dns-configuration'>documentation</a> for further help.");
if (! validate_dns_entry($domain, $this->application->destination->server)) {
$showToaster && $this->dispatch('error', 'Validating DNS failed.', "Make sure you have added the DNS records correctly.<br><br>$domain->{$this->application->destination->server->ip}<br><br>Check this <a target='_blank' class='underline dark:text-white' href='https://coolify.io/docs/knowledge-base/dns-configuration'>documentation</a> for further help.");
}
check_domain_usage(resource: $this->application);
}

View File

@@ -14,25 +14,31 @@ use Visus\Cuid2\Cuid2;
class Heading extends Component
{
public Application $application;
public ?string $lastDeploymentInfo = null;
public ?string $lastDeploymentLink = null;
public array $parameters;
protected string $deploymentUuid;
public function getListeners()
{
$teamId = auth()->user()->currentTeam()->id;
return [
"echo-private:team.{$teamId},ApplicationStatusChanged" => 'check_status',
"compose_loaded" => '$refresh',
"update_links" => '$refresh',
'compose_loaded' => '$refresh',
'update_links' => '$refresh',
];
}
public function mount()
{
$this->parameters = get_route_parameters();
$lastDeployment = $this->application->get_last_successful_deployment();
$this->lastDeploymentInfo = data_get_str($lastDeployment, 'commit')->limit(7) . ' ' . data_get($lastDeployment, 'commit_message');
$this->lastDeploymentInfo = data_get_str($lastDeployment, 'commit')->limit(7).' '.data_get($lastDeployment, 'commit_message');
$this->lastDeploymentLink = $this->application->gitCommitLink(data_get($lastDeployment, 'commit'));
}
@@ -45,7 +51,9 @@ class Heading extends Component
dispatch(new ServerStatusJob($this->application->destination->server));
}
if ($showNotification) $this->dispatch('success', "Success", "Application status updated.");
if ($showNotification) {
$this->dispatch('success', 'Success', 'Application status updated.');
}
// Removed because it caused flickering
// $this->dispatch('configurationChanged');
}
@@ -59,18 +67,22 @@ class Heading extends Component
{
if ($this->application->build_pack === 'dockercompose' && is_null($this->application->docker_compose_raw)) {
$this->dispatch('error', 'Failed to deploy', 'Please load a Compose file first.');
return;
}
if ($this->application->destination->server->isSwarm() && str($this->application->docker_registry_image_name)->isEmpty()) {
$this->dispatch('error', 'Failed to deploy.', 'To deploy to a Swarm cluster you must set a Docker image name first.');
return;
}
if (data_get($this->application, 'settings.is_build_server_enabled') && str($this->application->docker_registry_image_name)->isEmpty()) {
$this->dispatch('error', 'Failed to deploy.', 'To use a build server, you must first set a Docker image.<br>More information here: <a target="_blank" class="underline" href="https://coolify.io/docs/knowledge-base/server/build-server">documentation</a>');
return;
}
if ($this->application->additional_servers->count() > 0 && str($this->application->docker_registry_image_name)->isEmpty()) {
$this->dispatch('error', 'Failed to deploy.', 'Before deploying to multiple servers, you must first set a Docker image in the General tab.<br>More information here: <a target="_blank" class="underline" href="https://coolify.io/docs/knowledge-base/server/multiple-servers">documentation</a>');
return;
}
$this->setDeploymentUuid();
@@ -79,6 +91,7 @@ class Heading extends Component
deployment_uuid: $this->deploymentUuid,
force_rebuild: $force_rebuild,
);
return redirect()->route('project.application.deployment.show', [
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
@@ -100,16 +113,18 @@ class Heading extends Component
$this->application->save();
if ($this->application->additional_servers->count() > 0) {
$this->application->additional_servers->each(function ($server) {
$server->pivot->status = "exited:unhealthy";
$server->pivot->status = 'exited:unhealthy';
$server->pivot->save();
});
}
ApplicationStatusChanged::dispatch(data_get($this->application, 'environment.project.team.id'));
}
public function restart()
{
if ($this->application->additional_servers->count() > 0 && str($this->application->docker_registry_image_name)->isEmpty()) {
$this->dispatch('error', 'Failed to deploy', 'Before deploying to multiple servers, you must first set a Docker image in the General tab.<br>More information here: <a target="_blank" class="underline" href="https://coolify.io/docs/knowledge-base/server/multiple-servers">documentation</a>');
return;
}
$this->setDeploymentUuid();
@@ -118,6 +133,7 @@ class Heading extends Component
deployment_uuid: $this->deploymentUuid,
restart_only: true,
);
return redirect()->route('project.application.deployment.show', [
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],

View File

@@ -10,10 +10,13 @@ use Spatie\Url\Url;
class Form extends Component
{
public Application $application;
public string $preview_url_template;
protected $rules = [
'application.preview_url_template' => 'required',
];
protected $validationAttributes = [
'application.preview_url_template' => 'preview url template',
];

View File

@@ -13,14 +13,19 @@ use Visus\Cuid2\Cuid2;
class Previews extends Component
{
public Application $application;
public string $deployment_uuid;
public array $parameters;
public Collection $pull_requests;
public int $rate_limit_remaining;
protected $rules = [
'application.previews.*.fqdn' => 'string|nullable',
];
public function mount()
{
$this->pull_requests = collect();
@@ -35,9 +40,11 @@ class Previews extends Component
$this->pull_requests = $data->sortBy('number')->values();
} catch (\Throwable $e) {
$this->rate_limit_remaining = 0;
return handleError($e, $this);
}
}
public function save_preview($preview_id)
{
try {
@@ -47,14 +54,14 @@ class Previews extends Component
$preview->fqdn = str($preview->fqdn)->replaceEnd(',', '')->trim();
$preview->fqdn = str($preview->fqdn)->replaceStart(',', '')->trim();
$preview->fqdn = str($preview->fqdn)->trim()->lower();
if (!validate_dns_entry($preview->fqdn, $this->application->destination->server)) {
$this->dispatch('error', "Validating DNS failed.", "Make sure you have added the DNS records correctly.<br><br>$preview->fqdn->{$this->application->destination->server->ip}<br><br>Check this <a target='_blank' class='underline dark:text-white' href='https://coolify.io/docs/knowledge-base/dns-configuration'>documentation</a> for further help.");
if (! validate_dns_entry($preview->fqdn, $this->application->destination->server)) {
$this->dispatch('error', 'Validating DNS failed.', "Make sure you have added the DNS records correctly.<br><br>$preview->fqdn->{$this->application->destination->server->ip}<br><br>Check this <a target='_blank' class='underline dark:text-white' href='https://coolify.io/docs/knowledge-base/dns-configuration'>documentation</a> for further help.");
$success = false;
}
check_domain_usage(resource: $this->application, domain: $preview->fqdn);
}
if (!$preview) {
if (! $preview) {
throw new \Exception('Preview not found');
}
$success && $preview->save();
@@ -63,11 +70,13 @@ class Previews extends Component
return handleError($e, $this);
}
}
public function generate_preview($preview_id)
{
$preview = $this->application->previews->find($preview_id);
if (!$preview) {
if (! $preview) {
$this->dispatch('error', 'Preview not found.');
return;
}
$fqdn = generateFqdn($this->application->destination->server, $this->application->uuid);
@@ -85,13 +94,14 @@ class Previews extends Component
$preview->save();
$this->dispatch('success', 'Domain generated.');
}
public function add(int $pull_request_id, string|null $pull_request_html_url = null)
public function add(int $pull_request_id, ?string $pull_request_html_url = null)
{
try {
if ($this->application->build_pack === 'dockercompose') {
$this->setDeploymentUuid();
$found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
if (!$found && !is_null($pull_request_html_url)) {
if (! $found && ! is_null($pull_request_html_url)) {
$found = ApplicationPreview::create([
'application_id' => $this->application->id,
'pull_request_id' => $pull_request_id,
@@ -104,7 +114,7 @@ class Previews extends Component
} else {
$this->setDeploymentUuid();
$found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
if (!$found && !is_null($pull_request_html_url)) {
if (! $found && ! is_null($pull_request_html_url)) {
$found = ApplicationPreview::create([
'application_id' => $this->application->id,
'pull_request_id' => $pull_request_id,
@@ -120,16 +130,17 @@ class Previews extends Component
return handleError($e, $this);
}
}
public function deploy(int $pull_request_id, string|null $pull_request_html_url = null)
public function deploy(int $pull_request_id, ?string $pull_request_html_url = null)
{
try {
$this->setDeploymentUuid();
$found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first();
if (!$found && !is_null($pull_request_html_url)) {
if (! $found && ! is_null($pull_request_html_url)) {
ApplicationPreview::create([
'application_id' => $this->application->id,
'pull_request_id' => $pull_request_id,
'pull_request_html_url' => $pull_request_html_url
'pull_request_html_url' => $pull_request_html_url,
]);
}
queue_application_deployment(
@@ -139,6 +150,7 @@ class Previews extends Component
pull_request_id: $pull_request_id,
git_type: $found->git_type ?? null,
);
return redirect()->route('project.application.deployment.show', [
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],

View File

@@ -10,12 +10,16 @@ use Visus\Cuid2\Cuid2;
class PreviewsCompose extends Component
{
public $service;
public $serviceName;
public ApplicationPreview $preview;
public function render()
{
return view('livewire.project.application.previews-compose');
}
public function save()
{
$domain = data_get($this->service, 'domain');
@@ -27,6 +31,7 @@ class PreviewsCompose extends Component
$this->dispatch('update_links');
$this->dispatch('success', 'Domain saved.');
}
public function generate()
{
$domains = collect(json_decode($this->preview->application->docker_compose_domains)) ?? collect();

View File

@@ -10,14 +10,18 @@ use Visus\Cuid2\Cuid2;
class Rollback extends Component
{
public Application $application;
public $images = [];
public string|null $current;
public ?string $current;
public array $parameters;
public function mount()
{
$this->parameters = get_route_parameters();
}
public function rollbackImage($commit)
{
$deployment_uuid = new Cuid2(7);
@@ -29,6 +33,7 @@ class Rollback extends Component
rollback: true,
force_rebuild: false,
);
return redirect()->route('project.application.deployment.show', [
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
@@ -45,7 +50,7 @@ class Rollback extends Component
$output = instant_remote_process([
"docker inspect --format='{{.Config.Image}}' {$this->application->uuid}",
], $this->application->destination->server, throwError: false);
$current_tag = Str::of($output)->trim()->explode(":");
$current_tag = Str::of($output)->trim()->explode(':');
$this->current = data_get($current_tag, 1);
$output = instant_remote_process([
@@ -58,6 +63,7 @@ class Rollback extends Component
if ($item[1] === $this->current) {
// $is_current = true;
}
return [
'tag' => $item[1],
'created_at' => $item[2],
@@ -66,6 +72,7 @@ class Rollback extends Component
})->toArray();
}
$showToast && $this->dispatch('success', 'Images loaded.');
return [];
} catch (\Throwable $e) {
return handleError($e, $this);

View File

@@ -9,13 +9,17 @@ use Livewire\Component;
class Source extends Component
{
public $applicationId;
public Application $application;
public $private_keys;
protected $rules = [
'application.git_repository' => 'required',
'application.git_branch' => 'required',
'application.git_commit_sha' => 'nullable',
];
protected $validationAttributes = [
'application.git_repository' => 'repository',
'application.git_branch' => 'branch',
@@ -45,7 +49,7 @@ class Source extends Component
public function submit()
{
$this->validate();
if (!$this->application->git_commit_sha) {
if (! $this->application->git_commit_sha) {
$this->application->git_commit_sha = 'HEAD';
}
$this->application->save();

View File

@@ -8,6 +8,7 @@ use Livewire\Component;
class Swarm extends Component
{
public Application $application;
public string $swarm_placement_constraints = '';
protected $rules = [
@@ -15,12 +16,16 @@ class Swarm extends Component
'application.swarm_placement_constraints' => 'nullable',
'application.settings.is_swarm_only_worker_nodes' => 'required',
];
public function mount() {
public function mount()
{
if ($this->application->swarm_placement_constraints) {
$this->swarm_placement_constraints = base64_decode($this->application->swarm_placement_constraints);
}
}
public function instantSave() {
public function instantSave()
{
try {
$this->validate();
$this->application->settings->save();
@@ -29,7 +34,9 @@ class Swarm extends Component
return handleError($e, $this);
}
}
public function submit() {
public function submit()
{
try {
$this->validate();
if ($this->swarm_placement_constraints) {
@@ -44,6 +51,7 @@ class Swarm extends Component
return handleError($e, $this);
}
}
public function render()
{
return view('livewire.project.application.swarm');

View File

@@ -11,17 +11,27 @@ use Visus\Cuid2\Cuid2;
class CloneMe extends Component
{
public string $project_uuid;
public string $environment_name;
public int $project_id;
public Project $project;
public $environments;
public $servers;
public ?Environment $environment = null;
public ?int $selectedServer = null;
public ?int $selectedDestination = null;
public ?Server $server = null;
public $resources = [];
public string $newName = '';
protected $messages = [
@@ -29,6 +39,7 @@ class CloneMe extends Component
'selectedDestination' => 'Please select a server & destination.',
'newName' => 'Please enter a name for the new project or environment.',
];
public function mount($project_uuid)
{
$this->project_uuid = $project_uuid;
@@ -36,7 +47,7 @@ class CloneMe extends Component
$this->environment = $this->project->environments->where('name', $this->environment_name)->first();
$this->project_id = $this->project->id;
$this->servers = currentTeam()->servers;
$this->newName = str($this->project->name . '-clone-' . (string)new Cuid2(7))->slug();
$this->newName = str($this->project->name.'-clone-'.(string) new Cuid2(7))->slug();
}
public function render()
@@ -50,6 +61,7 @@ class CloneMe extends Component
$this->selectedServer = null;
$this->selectedDestination = null;
$this->server = null;
return;
}
$this->selectedServer = $server_id;
@@ -72,7 +84,7 @@ class CloneMe extends Component
$project = Project::create([
'name' => $this->newName,
'team_id' => currentTeam()->id,
'description' => $this->project->description . ' (clone)',
'description' => $this->project->description.' (clone)',
]);
if ($this->environment->name !== 'production') {
$project->environments()->create([
@@ -94,7 +106,7 @@ class CloneMe extends Component
$databases = $this->environment->databases();
$services = $this->environment->services;
foreach ($applications as $application) {
$uuid = (string)new Cuid2(7);
$uuid = (string) new Cuid2(7);
$newApplication = $application->replicate()->fill([
'uuid' => $uuid,
'fqdn' => generateFqdn($this->server, $uuid),
@@ -114,14 +126,14 @@ class CloneMe extends Component
$persistentVolumes = $application->persistentStorages()->get();
foreach ($persistentVolumes as $volume) {
$newPersistentVolume = $volume->replicate()->fill([
'name' => $newApplication->uuid . '-' . str($volume->name)->afterLast('-'),
'name' => $newApplication->uuid.'-'.str($volume->name)->afterLast('-'),
'resource_id' => $newApplication->id,
]);
$newPersistentVolume->save();
}
}
foreach ($databases as $database) {
$uuid = (string)new Cuid2(7);
$uuid = (string) new Cuid2(7);
$newDatabase = $database->replicate()->fill([
'uuid' => $uuid,
'status' => 'exited',
@@ -135,21 +147,21 @@ class CloneMe extends Component
$payload = [];
if ($database->type() === 'standalone-postgresql') {
$payload['standalone_postgresql_id'] = $newDatabase->id;
} else if ($database->type() === 'standalone-redis') {
} elseif ($database->type() === 'standalone-redis') {
$payload['standalone_redis_id'] = $newDatabase->id;
} else if ($database->type() === 'standalone-mongodb') {
} elseif ($database->type() === 'standalone-mongodb') {
$payload['standalone_mongodb_id'] = $newDatabase->id;
} else if ($database->type() === 'standalone-mysql') {
} elseif ($database->type() === 'standalone-mysql') {
$payload['standalone_mysql_id'] = $newDatabase->id;
} else if ($database->type() === 'standalone-mariadb') {
} elseif ($database->type() === 'standalone-mariadb') {
$payload['standalone_mariadb_id'] = $newDatabase->id;
}
$newEnvironmentVariable = $environmentVarible->replicate()->fill($payload);
$newEnvironmentVariable = $environmentVarible->replicate()->fill($payload);
$newEnvironmentVariable->save();
}
}
foreach ($services as $service) {
$uuid = (string)new Cuid2(7);
$uuid = (string) new Cuid2(7);
$newService = $service->replicate()->fill([
'uuid' => $uuid,
'environment_id' => $environment->id,
@@ -168,6 +180,7 @@ class CloneMe extends Component
}
$newService->parse();
}
return redirect()->route('project.resource.index', [
'project_uuid' => $project->uuid,
'environment_name' => $environment->name,

View File

@@ -8,26 +8,30 @@ use Livewire\Component;
class Execution extends Component
{
public $database;
public ?ScheduledDatabaseBackup $backup;
public $executions;
public $s3s;
public function mount()
{
$backup_uuid = request()->route('backup_uuid');
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
if (! $project) {
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
if (! $environment) {
return redirect()->route('dashboard');
}
$database = $environment->databases()->where('uuid', request()->route('database_uuid'))->first();
if (!$database) {
if (! $database) {
return redirect()->route('dashboard');
}
$backup = $database->scheduledBackups->where('uuid', $backup_uuid)->first();
if (!$backup) {
if (! $backup) {
return redirect()->route('dashboard');
}
$executions = collect($backup->executions)->sortByDesc('created_at');
@@ -36,6 +40,7 @@ class Execution extends Component
$this->executions = $executions;
$this->s3s = currentTeam()->s3s;
}
public function render()
{
return view('livewire.project.database.backup.execution');

View File

@@ -7,25 +7,26 @@ use Livewire\Component;
class Index extends Component
{
public $database;
public function mount()
{
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
if (! $project) {
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
if (! $environment) {
return redirect()->route('dashboard');
}
$database = $environment->databases()->where('uuid', request()->route('database_uuid'))->first();
if (!$database) {
if (! $database) {
return redirect()->route('dashboard');
}
// No backups
if (
$database->getMorphClass() === 'App\Models\StandaloneRedis' ||
$database->getMorphClass() === 'App\Models\StandaloneKeydb' ||
$database->getMorphClass() === 'App\Models\StandaloneDragonfly'||
$database->getMorphClass() === 'App\Models\StandaloneDragonfly' ||
$database->getMorphClass() === 'App\Models\StandaloneClickhouse'
) {
return redirect()->route('project.database.configuration', [
@@ -36,6 +37,7 @@ class Index extends Component
}
$this->database = $database;
}
public function render()
{
return view('livewire.project.database.backup.index');

View File

@@ -9,8 +9,11 @@ use Spatie\Url\Url;
class BackupEdit extends Component
{
public ?ScheduledDatabaseBackup $backup;
public $s3s;
public ?string $status = null;
public array $parameters;
protected $rules = [
@@ -21,6 +24,7 @@ class BackupEdit extends Component
'backup.s3_storage_id' => 'nullable|integer',
'backup.databases_to_backup' => 'nullable',
];
protected $validationAttributes = [
'backup.enabled' => 'Enabled',
'backup.frequency' => 'Frequency',
@@ -29,6 +33,7 @@ class BackupEdit extends Component
'backup.s3_storage_id' => 'S3 Storage',
'backup.databases_to_backup' => 'Databases to Backup',
];
protected $messages = [
'backup.s3_storage_id' => 'Select a S3 Storage',
];
@@ -50,7 +55,8 @@ class BackupEdit extends Component
$url = Url::fromString($previousUrl);
$url = $url->withoutQueryParameter('selectedBackupId');
$url = $url->withFragment('backups');
$url = $url->getPath() . "#{$url->getFragment()}";
$url = $url->getPath()."#{$url->getFragment()}";
return redirect($url);
} else {
return redirect()->route('project.database.backup.index', $this->parameters);
@@ -74,11 +80,11 @@ class BackupEdit extends Component
private function custom_validate()
{
if (!is_numeric($this->backup->s3_storage_id)) {
if (! is_numeric($this->backup->s3_storage_id)) {
$this->backup->s3_storage_id = null;
}
$isValid = validate_cron_expression($this->backup->frequency);
if (!$isValid) {
if (! $isValid) {
throw new \Exception('Invalid Cron / Human expression');
}
$this->validate();

View File

@@ -8,14 +8,18 @@ use Livewire\Component;
class BackupExecutions extends Component
{
public ?ScheduledDatabaseBackup $backup = null;
public $executions = [];
public $setDeletableBackup;
public function getListeners()
{
$userId = auth()->user()->id;
return [
"echo-private:team.{$userId},BackupCreated" => 'refreshBackupExecutions',
"deleteBackup"
'deleteBackup',
];
}
@@ -27,11 +31,13 @@ class BackupExecutions extends Component
$this->dispatch('success', 'Failed backups cleaned up.');
}
}
public function deleteBackup($exeuctionId)
{
$execution = $this->backup->executions()->where('id', $exeuctionId)->first();
if (is_null($execution)) {
$this->dispatch('error', 'Backup execution not found.');
return;
}
if ($execution->scheduledDatabaseBackup->database->getMorphClass() === 'App\Models\ServiceDatabase') {
@@ -43,10 +49,12 @@ class BackupExecutions extends Component
$this->dispatch('success', 'Backup deleted.');
$this->refreshBackupExecutions();
}
public function download_file($exeuctionId)
{
return redirect()->route('download.backup', $exeuctionId);
}
public function refreshBackupExecutions(): void
{
if ($this->backup) {

View File

@@ -8,6 +8,7 @@ use Livewire\Component;
class BackupNow extends Component
{
public $backup;
public function backup_now()
{
dispatch(new DatabaseBackupJob(

View File

@@ -12,8 +12,11 @@ use Livewire\Component;
class General extends Component
{
public Server $server;
public StandaloneClickhouse $database;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $listeners = ['refresh'];
@@ -29,6 +32,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -39,19 +43,23 @@ class General extends Component
'database.is_public' => 'Is Public',
'database.public_port' => 'Public Port',
];
public function mount()
{
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced() {
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -61,18 +69,21 @@ class General extends Component
return handleError($e, $this);
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -85,7 +96,8 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
@@ -95,7 +107,6 @@ class General extends Component
$this->database->refresh();
}
public function submit()
{
try {

View File

@@ -7,18 +7,19 @@ use Livewire\Component;
class Configuration extends Component
{
public $database;
public function mount()
{
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
if (! $project) {
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
if (! $environment) {
return redirect()->route('dashboard');
}
$database = $environment->databases()->where('uuid', request()->route('database_uuid'))->first();
if (!$database) {
if (! $database) {
return redirect()->route('dashboard');
}
$this->database = $database;
@@ -27,6 +28,7 @@ class Configuration extends Component
$this->dispatch('configurationChanged');
}
}
public function render()
{
return view('livewire.project.database.configuration');

View File

@@ -9,20 +9,27 @@ use Livewire\Component;
class CreateScheduledBackup extends Component
{
public $database;
public $frequency;
public bool $enabled = true;
public bool $save_s3 = false;
public $s3_storage_id;
public Collection $s3s;
protected $rules = [
'frequency' => 'required|string',
'save_s3' => 'required|boolean',
];
protected $validationAttributes = [
'frequency' => 'Backup Frequency',
'save_s3' => 'Save to S3',
];
public function mount()
{
$this->s3s = currentTeam()->s3s;
@@ -36,8 +43,9 @@ class CreateScheduledBackup extends Component
try {
$this->validate();
$isValid = validate_cron_expression($this->frequency);
if (!$isValid) {
if (! $isValid) {
$this->dispatch('error', 'Invalid Cron / Human expression.');
return;
}
$payload = [
@@ -51,9 +59,9 @@ class CreateScheduledBackup extends Component
];
if ($this->database->type() === 'standalone-postgresql') {
$payload['databases_to_backup'] = $this->database->postgres_db;
} else if ($this->database->type() === 'standalone-mysql') {
} elseif ($this->database->type() === 'standalone-mysql') {
$payload['databases_to_backup'] = $this->database->mysql_database;
} else if ($this->database->type() === 'standalone-mariadb') {
} elseif ($this->database->type() === 'standalone-mariadb') {
$payload['databases_to_backup'] = $this->database->mariadb_database;
}

View File

@@ -14,8 +14,11 @@ class General extends Component
protected $listeners = ['refresh'];
public Server $server;
public StandaloneDragonfly $database;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $rules = [
@@ -28,6 +31,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -37,19 +41,23 @@ class General extends Component
'database.is_public' => 'Is Public',
'database.public_port' => 'Public Port',
];
public function mount()
{
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced() {
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -59,6 +67,7 @@ class General extends Component
return handleError($e, $this);
}
}
public function submit()
{
try {
@@ -75,18 +84,21 @@ class General extends Component
}
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -99,16 +111,17 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
public function refresh(): void
{
$this->database->refresh();
}
public function render()
{
return view('livewire.project.database.dragonfly.general');

View File

@@ -18,11 +18,13 @@ use Livewire\Component;
class Heading extends Component
{
public $database;
public array $parameters;
public function getListeners()
{
$userId = auth()->user()->id;
return [
"echo-private:user.{$userId},DatabaseStatusChanged" => 'activityFinished',
];
@@ -48,7 +50,9 @@ class Heading extends Component
GetContainersStatus::run($this->database->destination->server);
// dispatch_sync(new ContainerStatusJob($this->database->destination->server));
$this->database->refresh();
if ($showNotification) $this->dispatch('success', 'Database status updated.');
if ($showNotification) {
$this->dispatch('success', 'Database status updated.');
}
}
public function mount()
@@ -69,25 +73,25 @@ class Heading extends Component
if ($this->database->type() === 'standalone-postgresql') {
$activity = StartPostgresql::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
} else if ($this->database->type() === 'standalone-redis') {
} elseif ($this->database->type() === 'standalone-redis') {
$activity = StartRedis::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
} else if ($this->database->type() === 'standalone-mongodb') {
} elseif ($this->database->type() === 'standalone-mongodb') {
$activity = StartMongodb::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
} else if ($this->database->type() === 'standalone-mysql') {
} elseif ($this->database->type() === 'standalone-mysql') {
$activity = StartMysql::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
} else if ($this->database->type() === 'standalone-mariadb') {
} elseif ($this->database->type() === 'standalone-mariadb') {
$activity = StartMariadb::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
} else if ($this->database->type() === 'standalone-keydb') {
} elseif ($this->database->type() === 'standalone-keydb') {
$activity = StartKeydb::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
} else if ($this->database->type() === 'standalone-dragonfly') {
} elseif ($this->database->type() === 'standalone-dragonfly') {
$activity = StartDragonfly::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
} else if ($this->database->type() === 'standalone-clickhouse') {
} elseif ($this->database->type() === 'standalone-clickhouse') {
$activity = StartClickhouse::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
}

View File

@@ -2,40 +2,57 @@
namespace App\Livewire\Project\Database;
use Livewire\Component;
use App\Models\Server;
use Illuminate\Support\Facades\Storage;
use Livewire\Component;
class Import extends Component
{
public bool $unsupported = false;
public $resource;
public $parameters;
public $containers;
public bool $scpInProgress = false;
public bool $importRunning = false;
public ?string $filename = null;
public ?string $filesize = null;
public bool $isUploading = false;
public int $progress = 0;
public bool $error = false;
public Server $server;
public string $container;
public array $importCommands = [];
public string $postgresqlRestoreCommand = 'pg_restore -U $POSTGRES_USER -d $POSTGRES_DB';
public string $mysqlRestoreCommand = 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE';
public string $mariadbRestoreCommand = 'mariadb -u $MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE';
public string $mongodbRestoreCommand = 'mongorestore --authenticationDatabase=admin --username $MONGO_INITDB_ROOT_USERNAME --password $MONGO_INITDB_ROOT_PASSWORD --uri mongodb://localhost:27017 --gzip --archive=';
public function getListeners()
{
$userId = auth()->user()->id;
return [
"echo-private:user.{$userId},DatabaseStatusChanged" => '$refresh',
];
}
public function mount()
{
$this->parameters = get_route_parameters();
@@ -45,7 +62,7 @@ class Import extends Component
public function getContainers()
{
$this->containers = collect();
if (!data_get($this->parameters, 'database_uuid')) {
if (! data_get($this->parameters, 'database_uuid')) {
abort(404);
}
$resource = getResourceByUuid($this->parameters['database_uuid'], data_get(auth()->user()->currentTeam(), 'id'));
@@ -74,16 +91,18 @@ class Import extends Component
if ($this->filename == '') {
$this->dispatch('error', 'Please select a file to import.');
return;
}
try {
$uploadedFilename = "upload/{$this->resource->uuid}/restore";
$path = Storage::path($uploadedFilename);
if (!Storage::exists($uploadedFilename)) {
if (! Storage::exists($uploadedFilename)) {
$this->dispatch('error', 'The file does not exist or has been deleted.');
return;
}
$tmpPath = '/tmp/' . basename($uploadedFilename);
$tmpPath = '/tmp/'.basename($uploadedFilename);
instant_scp($path, $tmpPath, $this->server);
Storage::delete($uploadedFilename);
$this->importCommands[] = "docker cp {$tmpPath} {$this->container}:{$tmpPath}";
@@ -110,7 +129,7 @@ class Import extends Component
$this->importCommands[] = "docker exec {$this->container} sh -c 'rm {$tmpPath}'";
$this->importCommands[] = "docker exec {$this->container} sh -c 'echo \"Import finished with exit code $?\"'";
if (!empty($this->importCommands)) {
if (! empty($this->importCommands)) {
$activity = remote_process($this->importCommands, $this->server, ignore_errors: true);
$this->dispatch('activityMonitor', $activity->id);
}

View File

@@ -8,14 +8,18 @@ use Livewire\Component;
class InitScript extends Component
{
public array $script;
public int $index;
public string|null $filename;
public string|null $content;
public ?string $filename;
public ?string $content;
protected $rules = [
'filename' => 'required|string',
'content' => 'required|string',
];
protected $validationAttributes = [
'filename' => 'Filename',
'content' => 'Content',

View File

@@ -14,8 +14,11 @@ class General extends Component
protected $listeners = ['refresh'];
public Server $server;
public StandaloneKeydb $database;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $rules = [
@@ -29,6 +32,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -39,20 +43,24 @@ class General extends Component
'database.is_public' => 'Is Public',
'database.public_port' => 'Public Port',
];
public function mount()
{
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced() {
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -62,11 +70,12 @@ class General extends Component
return handleError($e, $this);
}
}
public function submit()
{
try {
$this->validate();
if ($this->database->keydb_conf === "") {
if ($this->database->keydb_conf === '') {
$this->database->keydb_conf = null;
}
$this->database->save();
@@ -81,18 +90,21 @@ class General extends Component
}
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -105,10 +117,12 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
public function refresh(): void
{
$this->database->refresh();

View File

@@ -14,8 +14,11 @@ class General extends Component
protected $listeners = ['refresh'];
public Server $server;
public StandaloneMariadb $database;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $rules = [
@@ -32,6 +35,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -52,14 +56,17 @@ class General extends Component
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced() {
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -69,6 +76,7 @@ class General extends Component
return handleError($e, $this);
}
}
public function submit()
{
try {
@@ -88,18 +96,21 @@ class General extends Component
}
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -112,10 +123,12 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
public function refresh(): void
{
$this->database->refresh();

View File

@@ -14,8 +14,11 @@ class General extends Component
protected $listeners = ['refresh'];
public Server $server;
public StandaloneMongodb $database;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $rules = [
@@ -31,6 +34,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -50,15 +54,17 @@ class General extends Component
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -68,6 +74,7 @@ class General extends Component
return handleError($e, $this);
}
}
public function submit()
{
try {
@@ -90,18 +97,21 @@ class General extends Component
}
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -114,10 +124,12 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
public function refresh(): void
{
$this->database->refresh();

View File

@@ -14,8 +14,11 @@ class General extends Component
protected $listeners = ['refresh'];
public StandaloneMysql $database;
public Server $server;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $rules = [
@@ -32,6 +35,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -52,14 +56,16 @@ class General extends Component
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -69,6 +75,7 @@ class General extends Component
return handleError($e, $this);
}
}
public function submit()
{
try {
@@ -88,18 +95,21 @@ class General extends Component
}
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -112,10 +122,12 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
public function refresh(): void
{
$this->database->refresh();

View File

@@ -14,10 +14,15 @@ use function Aws\filter;
class General extends Component
{
public StandalonePostgresql $database;
public Server $server;
public string $new_filename;
public string $new_content;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $listeners = ['refresh', 'save_init_script', 'delete_init_script'];
@@ -38,6 +43,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -53,20 +59,23 @@ class General extends Component
'database.is_public' => 'Is Public',
'database.public_port' => 'Public Port',
];
public function mount()
{
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -76,18 +85,21 @@ class General extends Component
return handleError($e, $this);
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -100,10 +112,12 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
public function save_init_script($script)
{
$this->database->init_scripts = filter($this->database->init_scripts, fn ($s) => $s['filename'] !== $script['filename']);
@@ -121,6 +135,7 @@ class General extends Component
$this->database->save();
$this->refresh();
$this->dispatch('success', 'Init script deleted.');
return;
}
}
@@ -139,9 +154,10 @@ class General extends Component
$found = collect($this->database->init_scripts)->firstWhere('filename', $this->new_filename);
if ($found) {
$this->dispatch('error', 'Filename already exists.');
return;
}
if (!isset($this->database->init_scripts)) {
if (! isset($this->database->init_scripts)) {
$this->database->init_scripts = [];
}
$this->database->init_scripts = array_merge($this->database->init_scripts, [
@@ -149,7 +165,7 @@ class General extends Component
'index' => count($this->database->init_scripts),
'filename' => $this->new_filename,
'content' => $this->new_content,
]
],
]);
$this->database->save();
$this->dispatch('success', 'Init script added.');

View File

@@ -14,8 +14,11 @@ class General extends Component
protected $listeners = ['refresh'];
public Server $server;
public StandaloneRedis $database;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $rules = [
@@ -29,6 +32,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -39,20 +43,24 @@ class General extends Component
'database.is_public' => 'Is Public',
'database.public_port' => 'Public Port',
];
public function mount()
{
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced() {
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -62,11 +70,12 @@ class General extends Component
return handleError($e, $this);
}
}
public function submit()
{
try {
$this->validate();
if ($this->database->redis_conf === "") {
if ($this->database->redis_conf === '') {
$this->database->redis_conf = null;
}
$this->database->save();
@@ -75,18 +84,21 @@ class General extends Component
return handleError($e, $this);
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -99,10 +111,12 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
public function refresh(): void
{
$this->database->refresh();

View File

@@ -8,12 +8,19 @@ use Livewire\Component;
class ScheduledBackups extends Component
{
public $database;
public $parameters;
public $type;
public ?ScheduledDatabaseBackup $selectedBackup;
public $selectedBackupId;
public $s3s;
protected $listeners = ['refreshScheduledBackups'];
protected $queryString = ['selectedBackupId'];
public function mount(): void
@@ -29,13 +36,16 @@ class ScheduledBackups extends Component
}
$this->s3s = currentTeam()->s3s;
}
public function setSelectedBackup($backupId) {
public function setSelectedBackup($backupId)
{
$this->selectedBackupId = $backupId;
$this->selectedBackup = $this->database->scheduledBackups->find($this->selectedBackupId);
if (is_null($this->selectedBackup)) {
$this->selectedBackupId = null;
}
}
public function delete($scheduled_backup_id): void
{
$this->database->scheduledBackups->find($scheduled_backup_id)->delete();

View File

@@ -8,7 +8,9 @@ use Livewire\Component;
class DeleteEnvironment extends Component
{
public array $parameters;
public int $environment_id;
public bool $disabled = false;
public function mount()
@@ -24,8 +26,10 @@ class DeleteEnvironment extends Component
$environment = Environment::findOrFail($this->environment_id);
if ($environment->isEmpty()) {
$environment->delete();
return redirect()->route('project.show', ['project_uuid' => $this->parameters['project_uuid']]);
}
return $this->dispatch('error', 'Environment has defined resources, please delete them first.');
}
}

View File

@@ -8,7 +8,9 @@ use Livewire\Component;
class DeleteProject extends Component
{
public array $parameters;
public int $project_id;
public bool $disabled = false;
public function mount()
@@ -26,6 +28,7 @@ class DeleteProject extends Component
return $this->dispatch('error', 'Project has resources defined, please delete them first.');
}
$project->delete();
return redirect()->route('project.index');
}
}

View File

@@ -8,16 +8,18 @@ use Livewire\Component;
class Edit extends Component
{
public Project $project;
protected $rules = [
'project.name' => 'required|min:3|max:255',
'project.description' => 'nullable|string|max:255',
];
public function mount()
{
$projectUuid = request()->route('project_uuid');
$teamId = currentTeam()->id;
$project = Project::where('team_id', $teamId)->where('uuid', $projectUuid)->first();
if (!$project) {
if (! $project) {
return redirect()->route('dashboard');
}
$this->project = $project;

View File

@@ -9,13 +9,18 @@ use Livewire\Component;
class EnvironmentEdit extends Component
{
public Project $project;
public Application $application;
public $environment;
public array $parameters;
protected $rules = [
'environment.name' => 'required|min:3|max:255',
'environment.description' => 'nullable|min:3|max:255',
];
public function mount()
{
$this->parameters = get_route_parameters();
@@ -28,11 +33,13 @@ class EnvironmentEdit extends Component
$this->validate();
try {
$this->environment->save();
return redirect()->route('project.environment.edit', ['project_uuid' => $this->project->uuid, 'environment_name' => $this->environment->name]);
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function render()
{
return view('livewire.project.environment-edit');

View File

@@ -10,13 +10,18 @@ use Livewire\Component;
class Index extends Component
{
public $projects;
public $servers;
public $private_keys;
public function mount() {
public function mount()
{
$this->private_keys = PrivateKey::ownedByCurrentTeam()->get();
$this->projects = Project::ownedByCurrentTeam()->get();
$this->servers = Server::ownedByCurrentTeam()->count();
}
public function render()
{
return view('livewire.project.index');

View File

@@ -5,16 +5,20 @@ namespace App\Livewire\Project\New;
use App\Models\EnvironmentVariable;
use App\Models\Project;
use App\Models\Service;
use Livewire\Component;
use Illuminate\Support\Str;
use Livewire\Component;
use Symfony\Component\Yaml\Yaml;
class DockerCompose extends Component
{
public string $dockerComposeRaw = '';
public string $envFile = '';
public array $parameters;
public array $query;
public function mount()
{
$this->parameters = get_route_parameters();
@@ -37,12 +41,13 @@ class DockerCompose extends Component
';
}
}
public function submit()
{
$server_id = $this->query['server_id'];
try {
$this->validate([
'dockerComposeRaw' => 'required'
'dockerComposeRaw' => 'required',
]);
$this->dockerComposeRaw = Yaml::dump(Yaml::parse($this->dockerComposeRaw), 10, 2, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK);
@@ -54,7 +59,7 @@ class DockerCompose extends Component
$project = Project::where('uuid', $this->parameters['project_uuid'])->first();
$environment = $project->load(['environments'])->environments->where('name', $this->parameters['environment_name'])->first();
$service = Service::create([
'name' => 'service' . Str::random(10),
'name' => 'service'.Str::random(10),
'docker_compose_raw' => $this->dockerComposeRaw,
'environment_id' => $environment->id,
'server_id' => (int) $server_id,

View File

@@ -6,24 +6,28 @@ use App\Models\Application;
use App\Models\Project;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Illuminate\Support\Str;
use Livewire\Component;
use Visus\Cuid2\Cuid2;
use Illuminate\Support\Str;
class DockerImage extends Component
{
public string $dockerImage = '';
public array $parameters;
public array $query;
public function mount()
{
$this->parameters = get_route_parameters();
$this->query = request()->query();
}
public function submit()
{
$this->validate([
'dockerImage' => 'required'
'dockerImage' => 'required',
]);
$image = Str::of($this->dockerImage)->before(':');
if (Str::of($this->dockerImage)->contains(':')) {
@@ -33,21 +37,21 @@ class DockerImage extends Component
}
$destination_uuid = $this->query['destination'];
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
if (!$destination) {
if (! $destination) {
$destination = SwarmDocker::where('uuid', $destination_uuid)->first();
}
if (!$destination) {
if (! $destination) {
throw new \Exception('Destination not found. What?!');
}
$destination_class = $destination->getMorphClass();
$project = Project::where('uuid', $this->parameters['project_uuid'])->first();
$environment = $project->load(['environments'])->environments->where('name', $this->parameters['environment_name'])->first();
ray($image,$tag);
ray($image, $tag);
$application = Application::create([
'name' => 'docker-image-' . new Cuid2(7),
'name' => 'docker-image-'.new Cuid2(7),
'repository_project_id' => 0,
'git_repository' => "coollabsio/coolify",
'git_repository' => 'coollabsio/coolify',
'git_branch' => 'main',
'build_pack' => 'dockerimage',
'ports_exposes' => 80,
@@ -61,15 +65,17 @@ class DockerImage extends Component
$fqdn = generateFqdn($destination->server, $application->uuid);
$application->update([
'name' => 'docker-image-' . $application->uuid,
'fqdn' => $fqdn
'name' => 'docker-image-'.$application->uuid,
'fqdn' => $fqdn,
]);
return redirect()->route('project.application.configuration', [
'application_uuid' => $application->uuid,
'environment_name' => $environment->name,
'project_uuid' => $project->uuid,
]);
}
public function render()
{
return view('livewire.project.new.docker-image');

View File

@@ -13,6 +13,7 @@ class EmptyProject extends Component
'name' => generate_random_name(),
'team_id' => currentTeam()->id,
]);
return redirect()->route('project.show', ['project_uuid' => $project->uuid, 'environment_name' => 'production']);
}
}

View File

@@ -14,32 +14,50 @@ use Livewire\Component;
class GithubPrivateRepository extends Component
{
public $current_step = 'github_apps';
public $github_apps;
public GithubApp $github_app;
public $parameters;
public $currentRoute;
public $query;
public $type;
public int $selected_repository_id;
public int $selected_github_app_id;
public string $selected_repository_owner;
public string $selected_repository_repo;
public string $selected_branch_name = 'main';
public string $token;
public $repositories;
public int $total_repositories_count = 0;
public $branches;
public int $total_branches_count = 0;
public int $port = 3000;
public bool $is_static = false;
public string|null $publish_directory = null;
protected int $page = 1;
public $build_pack = 'nixpacks';
public bool $show_is_static = true;
public $repositories;
public int $total_repositories_count = 0;
public $branches;
public int $total_branches_count = 0;
public int $port = 3000;
public bool $is_static = false;
public ?string $publish_directory = null;
protected int $page = 1;
public $build_pack = 'nixpacks';
public bool $show_is_static = true;
public function mount()
{
@@ -49,12 +67,13 @@ class GithubPrivateRepository extends Component
$this->repositories = $this->branches = collect();
$this->github_apps = GithubApp::private();
}
public function updatedBuildPack()
{
if ($this->build_pack === 'nixpacks') {
$this->show_is_static = true;
$this->port = 3000;
} else if ($this->build_pack === 'static') {
} elseif ($this->build_pack === 'static') {
$this->show_is_static = false;
$this->is_static = false;
$this->port = 80;
@@ -63,6 +82,7 @@ class GithubPrivateRepository extends Component
$this->is_static = false;
}
}
public function loadRepositories($github_app_id)
{
$this->repositories = collect();
@@ -117,7 +137,7 @@ class GithubPrivateRepository extends Component
protected function loadBranchByPage()
{
ray('Loading page ' . $this->page);
ray('Loading page '.$this->page);
$response = Http::withToken($this->token)->get("{$this->github_app->api_url}/repos/{$this->selected_repository_owner}/{$this->selected_repository_repo}/branches?per_page=100&page={$this->page}");
$json = $response->json();
if ($response->status() !== 200) {
@@ -133,20 +153,19 @@ class GithubPrivateRepository extends Component
try {
$destination_uuid = $this->query['destination'];
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
if (!$destination) {
if (! $destination) {
$destination = SwarmDocker::where('uuid', $destination_uuid)->first();
}
if (!$destination) {
if (! $destination) {
throw new \Exception('Destination not found. What?!');
}
$destination_class = $destination->getMorphClass();
$project = Project::where('uuid', $this->parameters['project_uuid'])->first();
$environment = $project->load(['environments'])->environments->where('name', $this->parameters['environment_name'])->first();
$application = Application::create([
'name' => generate_application_name($this->selected_repository_owner . '/' . $this->selected_repository_repo, $this->selected_branch_name),
'name' => generate_application_name($this->selected_repository_owner.'/'.$this->selected_repository_repo, $this->selected_branch_name),
'repository_project_id' => $this->selected_repository_id,
'git_repository' => "{$this->selected_repository_owner}/{$this->selected_repository_repo}",
'git_branch' => $this->selected_branch_name,
@@ -157,7 +176,7 @@ class GithubPrivateRepository extends Component
'destination_id' => $destination->id,
'destination_type' => $destination_class,
'source_id' => $this->github_app->id,
'source_type' => $this->github_app->getMorphClass()
'source_type' => $this->github_app->getMorphClass(),
]);
$application->settings->is_static = $this->is_static;
$application->settings->save();
@@ -168,7 +187,7 @@ class GithubPrivateRepository extends Component
$fqdn = generateFqdn($destination->server, $application->uuid);
$application->fqdn = $fqdn;
$application->name = generate_application_name($this->selected_repository_owner . '/' . $this->selected_repository_repo, $this->selected_branch_name, $application->uuid);
$application->name = generate_application_name($this->selected_repository_owner.'/'.$this->selected_repository_repo, $this->selected_branch_name, $application->uuid);
$application->save();
return redirect()->route('project.application.configuration', [

View File

@@ -9,34 +9,44 @@ use App\Models\PrivateKey;
use App\Models\Project;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Livewire\Component;
use Spatie\Url\Url;
use Illuminate\Support\Str;
class GithubPrivateRepositoryDeployKey extends Component
{
public $current_step = 'private_keys';
public $parameters;
public $query;
public $private_keys = [];
public int $private_key_id;
public int $port = 3000;
public string $type;
public bool $is_static = false;
public null|string $publish_directory = null;
public ?string $publish_directory = null;
public string $repository_url;
public string $branch;
public $build_pack = 'nixpacks';
public bool $show_is_static = true;
private object $repository_url_parsed;
private GithubApp|GitlabApp|string $git_source = 'other';
private ?string $git_host = null;
private string $git_repository;
protected $rules = [
@@ -47,6 +57,7 @@ class GithubPrivateRepositoryDeployKey extends Component
'publish_directory' => 'nullable|string',
'build_pack' => 'required|string',
];
protected $validationAttributes = [
'repository_url' => 'Repository',
'branch' => 'Branch',
@@ -56,7 +67,6 @@ class GithubPrivateRepositoryDeployKey extends Component
'build_pack' => 'Build pack',
];
public function mount()
{
if (isDev()) {
@@ -76,7 +86,7 @@ class GithubPrivateRepositoryDeployKey extends Component
if ($this->build_pack === 'nixpacks') {
$this->show_is_static = true;
$this->port = 3000;
} else if ($this->build_pack === 'static') {
} elseif ($this->build_pack === 'static') {
$this->show_is_static = false;
$this->is_static = false;
$this->port = 80;
@@ -85,6 +95,7 @@ class GithubPrivateRepositoryDeployKey extends Component
$this->is_static = false;
}
}
public function instantSave()
{
if ($this->is_static) {
@@ -108,10 +119,10 @@ class GithubPrivateRepositoryDeployKey extends Component
try {
$destination_uuid = $this->query['destination'];
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
if (!$destination) {
if (! $destination) {
$destination = SwarmDocker::where('uuid', $destination_uuid)->first();
}
if (!$destination) {
if (! $destination) {
throw new \Exception('Destination not found. What?!');
}
$destination_class = $destination->getMorphClass();
@@ -146,7 +157,7 @@ class GithubPrivateRepositoryDeployKey extends Component
'destination_type' => $destination_class,
'private_key_id' => $this->private_key_id,
'source_id' => $this->git_source->id,
'source_type' => $this->git_source->getMorphClass()
'source_type' => $this->git_source->getMorphClass(),
];
}
if ($this->build_pack === 'dockerfile' || $this->build_pack === 'dockerimage') {
@@ -175,15 +186,16 @@ class GithubPrivateRepositoryDeployKey extends Component
{
$this->repository_url_parsed = Url::fromString($this->repository_url);
$this->git_host = $this->repository_url_parsed->getHost();
$this->git_repository = $this->repository_url_parsed->getSegment(1) . '/' . $this->repository_url_parsed->getSegment(2);
$this->git_repository = $this->repository_url_parsed->getSegment(1).'/'.$this->repository_url_parsed->getSegment(2);
if ($this->git_host == 'github.com') {
$this->git_source = GithubApp::where('name', 'Public GitHub')->first();
return;
}
if (Str::of($this->repository_url)->startsWith('http')) {
$this->git_host = $this->repository_url_parsed->getHost();
$this->git_repository = $this->repository_url_parsed->getSegment(1) . '/' . $this->repository_url_parsed->getSegment(2);
$this->git_repository = $this->repository_url_parsed->getSegment(1).'/'.$this->repository_url_parsed->getSegment(2);
$this->git_repository = Str::finish("git@$this->git_host:$this->git_repository", '.git');
} else {
$this->git_repository = $this->repository_url;

View File

@@ -16,22 +16,39 @@ use Spatie\Url\Url;
class PublicGitRepository extends Component
{
public string $repository_url;
public int $port = 3000;
public string $type;
public $parameters;
public $query;
public bool $branch_found = false;
public string $selected_branch = 'main';
public bool $is_static = false;
public string|null $publish_directory = null;
public ?string $publish_directory = null;
public string $git_branch = 'main';
public int $rate_limit_remaining = 0;
public $rate_limit_reset = 0;
private object $repository_url_parsed;
public GithubApp|GitlabApp|string $git_source = 'other';
public string $git_host;
public string $git_repository;
public $build_pack = 'nixpacks';
public bool $show_is_static = true;
public bool $new_compose_services = false;
@@ -43,6 +60,7 @@ class PublicGitRepository extends Component
'publish_directory' => 'nullable|string',
'build_pack' => 'required|string',
];
protected $validationAttributes = [
'repository_url' => 'repository',
'port' => 'port',
@@ -60,12 +78,13 @@ class PublicGitRepository extends Component
$this->parameters = get_route_parameters();
$this->query = request()->query();
}
public function updatedBuildPack()
{
if ($this->build_pack === 'nixpacks') {
$this->show_is_static = true;
$this->port = 3000;
} else if ($this->build_pack === 'static') {
} elseif ($this->build_pack === 'static') {
$this->show_is_static = false;
$this->is_static = false;
$this->port = 80;
@@ -74,6 +93,7 @@ class PublicGitRepository extends Component
$this->is_static = false;
}
}
public function instantSave()
{
if ($this->is_static) {
@@ -85,26 +105,28 @@ class PublicGitRepository extends Component
}
$this->dispatch('success', 'Application settings updated!');
}
public function load_any_git()
{
$this->branch_found = true;
}
public function load_branch()
{
try {
if (str($this->repository_url)->startsWith('git@')) {
$github_instance = str($this->repository_url)->after('git@')->before(':');
$repository = str($this->repository_url)->after(':')->before('.git');
$this->repository_url = 'https://' . str($github_instance) . '/' . $repository;
$this->repository_url = 'https://'.str($github_instance).'/'.$repository;
}
if (
(str($this->repository_url)->startsWith('https://') ||
str($this->repository_url)->startsWith('http://')) &&
!str($this->repository_url)->endsWith('.git') &&
(!str($this->repository_url)->contains('github.com') ||
!str($this->repository_url)->contains('git.sr.ht'))
! str($this->repository_url)->endsWith('.git') &&
(! str($this->repository_url)->contains('github.com') ||
! str($this->repository_url)->contains('git.sr.ht'))
) {
$this->repository_url = $this->repository_url . '.git';
$this->repository_url = $this->repository_url.'.git';
}
if (str($this->repository_url)->contains('github.com')) {
$this->repository_url = str($this->repository_url)->before('.git')->value();
@@ -119,7 +141,7 @@ class PublicGitRepository extends Component
$this->selected_branch = $this->git_branch;
} catch (\Throwable $e) {
ray($e->getMessage());
if (!$this->branch_found && $this->git_branch == 'main') {
if (! $this->branch_found && $this->git_branch == 'main') {
try {
$this->git_branch = 'master';
$this->get_branch();
@@ -136,11 +158,12 @@ class PublicGitRepository extends Component
{
$this->repository_url_parsed = Url::fromString($this->repository_url);
$this->git_host = $this->repository_url_parsed->getHost();
$this->git_repository = $this->repository_url_parsed->getSegment(1) . '/' . $this->repository_url_parsed->getSegment(2);
$this->git_repository = $this->repository_url_parsed->getSegment(1).'/'.$this->repository_url_parsed->getSegment(2);
$this->git_branch = $this->repository_url_parsed->getSegment(4) ?? 'main';
if ($this->git_host == 'github.com') {
$this->git_source = GithubApp::where('name', 'Public GitHub')->first();
return;
}
$this->git_repository = $this->repository_url;
@@ -151,11 +174,12 @@ class PublicGitRepository extends Component
{
if ($this->git_source === 'other') {
$this->branch_found = true;
return;
}
if ($this->git_source->getMorphClass() === 'App\Models\GithubApp') {
['rate_limit_remaining' => $this->rate_limit_remaining, 'rate_limit_reset' => $this->rate_limit_reset] = githubApi(source: $this->git_source, endpoint: "/repos/{$this->git_repository}/branches/{$this->git_branch}");
$this->rate_limit_reset = Carbon::parse((int)$this->rate_limit_reset)->format('Y-M-d H:i:s');
$this->rate_limit_reset = Carbon::parse((int) $this->rate_limit_reset)->format('Y-M-d H:i:s');
$this->branch_found = true;
}
}
@@ -169,10 +193,10 @@ class PublicGitRepository extends Component
$environment_name = $this->parameters['environment_name'];
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
if (!$destination) {
if (! $destination) {
$destination = SwarmDocker::where('uuid', $destination_uuid)->first();
}
if (!$destination) {
if (! $destination) {
throw new \Exception('Destination not found. What?!');
}
$destination_class = $destination->getMorphClass();
@@ -180,10 +204,10 @@ class PublicGitRepository extends Component
$project = Project::where('uuid', $project_uuid)->first();
$environment = $project->load(['environments'])->environments->where('name', $environment_name)->first();
if ($this->build_pack === 'dockercompose' && isDev() && $this->new_compose_services ) {
if ($this->build_pack === 'dockercompose' && isDev() && $this->new_compose_services) {
$server = $destination->server;
$new_service = [
'name' => 'service' . str()->random(10),
$new_service = [
'name' => 'service'.str()->random(10),
'docker_compose_raw' => 'coolify',
'environment_id' => $environment->id,
'server_id' => $server->id,
@@ -198,11 +222,13 @@ class PublicGitRepository extends Component
$new_service['source_type'] = $this->git_source->getMorphClass();
}
$service = Service::create($new_service);
return redirect()->route('project.service.configuration', [
'service_uuid' => $service->uuid,
'environment_name' => $environment->name,
'project_uuid' => $project->uuid,
]);
return;
}
if ($this->git_source === 'other') {

View File

@@ -4,37 +4,54 @@ namespace App\Livewire\Project\New;
use App\Models\Project;
use App\Models\Server;
use Countable;
use Illuminate\Support\Collection;
use Livewire\Component;
class Select extends Component
{
public $current_step = 'type';
public ?Server $server = null;
public string $type;
public string $server_id;
public string $destination_uuid;
public Collection|null|Server $allServers;
public Collection|null|Server $servers;
public ?Collection $standaloneDockers;
public ?Collection $swarmDockers;
public array $parameters;
public Collection|array $services = [];
public Collection|array $allServices = [];
public bool $isDatabase = false;
public bool $includeSwarm = true;
public bool $loadingServices = true;
public bool $loading = false;
public $environments = [];
public ?string $selectedEnvironment = null;
public ?string $existingPostgresqlUrl = null;
public ?string $search = null;
protected $queryString = [
'server_id',
'search'
'search',
];
public function mount()
@@ -47,6 +64,7 @@ class Select extends Component
$this->environments = Project::whereUuid($projectUuid)->first()->environments;
$this->selectedEnvironment = data_get($this->parameters, 'environment_name');
}
public function render()
{
return view('livewire.project.new.select');
@@ -74,17 +92,20 @@ class Select extends Component
{
$this->loadServices();
}
public function loadServices(bool $force = false)
{
try {
$this->loadingServices = true;
if (count($this->allServices) > 0 && !$force) {
if (!$this->search) {
if (count($this->allServices) > 0 && ! $force) {
if (! $this->search) {
$this->services = $this->allServices;
return;
}
$this->services = $this->allServices->filter(function ($service, $key) {
$tags = collect(data_get($service, 'tags', []));
return str_contains(strtolower($key), strtolower($this->search)) || $tags->contains(function ($tag) {
return str_contains(strtolower($tag), strtolower($this->search));
});
@@ -102,6 +123,7 @@ class Select extends Component
$this->loadingServices = false;
}
}
public function instantSave()
{
if ($this->includeSwarm) {
@@ -114,9 +136,12 @@ class Select extends Component
}
}
}
public function setType(string $type)
{
if ($this->loading) return;
if ($this->loading) {
return;
}
$this->loading = true;
$this->type = $type;
switch ($type) {
@@ -146,15 +171,16 @@ class Select extends Component
$this->servers = $this->allServers;
}
}
if ($type === "existing-postgresql") {
if ($type === 'existing-postgresql') {
$this->current_step = $type;
return;
}
// if (count($this->servers) === 1) {
// $server = $this->servers->first();
// $this->setServer($server);
// }
if (!is_null($this->server)) {
if (! is_null($this->server)) {
$foundServer = $this->servers->where('id', $this->server->id)->first();
if ($foundServer) {
return $this->setServer($foundServer);
@@ -175,6 +201,7 @@ class Select extends Component
public function setDestination(string $destination_uuid)
{
$this->destination_uuid = $destination_uuid;
return redirect()->route('project.resource.create', [
'project_uuid' => $this->parameters['project_uuid'],
'environment_name' => $this->parameters['environment_name'],

View File

@@ -13,8 +13,11 @@ use Visus\Cuid2\Cuid2;
class SimpleDockerfile extends Component
{
public string $dockerfile = '';
public array $parameters;
public array $query;
public function mount()
{
$this->parameters = get_route_parameters();
@@ -26,17 +29,18 @@ CMD ["nginx", "-g", "daemon off;"]
';
}
}
public function submit()
{
$this->validate([
'dockerfile' => 'required'
'dockerfile' => 'required',
]);
$destination_uuid = $this->query['destination'];
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
if (!$destination) {
if (! $destination) {
$destination = SwarmDocker::where('uuid', $destination_uuid)->first();
}
if (!$destination) {
if (! $destination) {
throw new \Exception('Destination not found. What?!');
}
$destination_class = $destination->getMorphClass();
@@ -45,13 +49,13 @@ CMD ["nginx", "-g", "daemon off;"]
$environment = $project->load(['environments'])->environments->where('name', $this->parameters['environment_name'])->first();
$port = get_port_from_dockerfile($this->dockerfile);
if (!$port) {
if (! $port) {
$port = 80;
}
$application = Application::create([
'name' => 'dockerfile-' . new Cuid2(7),
'name' => 'dockerfile-'.new Cuid2(7),
'repository_project_id' => 0,
'git_repository' => "coollabsio/coolify",
'git_repository' => 'coollabsio/coolify',
'git_branch' => 'main',
'build_pack' => 'dockerfile',
'dockerfile' => $this->dockerfile,
@@ -61,13 +65,13 @@ CMD ["nginx", "-g", "daemon off;"]
'destination_type' => $destination_class,
'health_check_enabled' => false,
'source_id' => 0,
'source_type' => GithubApp::class
'source_type' => GithubApp::class,
]);
$fqdn = generateFqdn($destination->server, $application->uuid);
$application->update([
'name' => 'dockerfile-' . $application->uuid,
'fqdn' => $fqdn
'name' => 'dockerfile-'.$application->uuid,
'fqdn' => $fqdn,
]);
$application->parseHealthcheckFromDockerfile(dockerfile: collect(str($this->dockerfile)->trim()->explode("\n")), isInit: true);

View File

@@ -10,7 +10,9 @@ use Livewire\Component;
class Create extends Component
{
public $type;
public $project;
public function mount()
{
$type = str(request()->query('type'));
@@ -18,54 +20,55 @@ class Create extends Component
$server_id = request()->query('server_id');
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
if (! $project) {
return redirect()->route('dashboard');
}
$this->project = $project;
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first();
if (!$environment) {
if (! $environment) {
return redirect()->route('dashboard');
}
if (isset($type) && isset($destination_uuid) && isset($server_id)) {
$services = get_service_templates();
if (in_array($type, DATABASE_TYPES)) {
if ($type->value() === "postgresql") {
if ($type->value() === 'postgresql') {
$database = create_standalone_postgresql($environment->id, $destination_uuid);
} else if ($type->value() === 'redis') {
} elseif ($type->value() === 'redis') {
$database = create_standalone_redis($environment->id, $destination_uuid);
} else if ($type->value() === 'mongodb') {
} elseif ($type->value() === 'mongodb') {
$database = create_standalone_mongodb($environment->id, $destination_uuid);
} else if ($type->value() === 'mysql') {
} elseif ($type->value() === 'mysql') {
$database = create_standalone_mysql($environment->id, $destination_uuid);
} else if ($type->value() === 'mariadb') {
} elseif ($type->value() === 'mariadb') {
$database = create_standalone_mariadb($environment->id, $destination_uuid);
} else if ($type->value() === 'keydb') {
} elseif ($type->value() === 'keydb') {
$database = create_standalone_keydb($environment->id, $destination_uuid);
} else if ($type->value() === 'dragonfly') {
} elseif ($type->value() === 'dragonfly') {
$database = create_standalone_dragonfly($environment->id, $destination_uuid);
} else if ($type->value() === 'clickhouse') {
} elseif ($type->value() === 'clickhouse') {
$database = create_standalone_clickhouse($environment->id, $destination_uuid);
}
return redirect()->route('project.database.configuration', [
'project_uuid' => $project->uuid,
'environment_name' => $environment->name,
'database_uuid' => $database->uuid,
]);
}
if ($type->startsWith('one-click-service-') && !is_null((int)$server_id)) {
if ($type->startsWith('one-click-service-') && ! is_null((int) $server_id)) {
$oneClickServiceName = $type->after('one-click-service-')->value();
$oneClickService = data_get($services, "$oneClickServiceName.compose");
$oneClickDotEnvs = data_get($services, "$oneClickServiceName.envs", null);
if ($oneClickDotEnvs) {
$oneClickDotEnvs = str(base64_decode($oneClickDotEnvs))->split('/\r\n|\r|\n/')->filter(function ($value) {
return !empty($value);
return ! empty($value);
});
}
if ($oneClickService) {
$destination = StandaloneDocker::whereUuid($destination_uuid)->first();
$service_payload = [
'name' => "$oneClickServiceName-" . str()->random(10),
'name' => "$oneClickServiceName-".str()->random(10),
'docker_compose_raw' => base64_decode($oneClickService),
'environment_id' => $environment->id,
'service_type' => $oneClickServiceName,
@@ -77,7 +80,7 @@ class Create extends Component
data_set($service_payload, 'connect_to_docker_network', true);
}
$service = Service::create($service_payload);
$service->name = "$oneClickServiceName-" . $service->uuid;
$service->name = "$oneClickServiceName-".$service->uuid;
$service->save();
if ($oneClickDotEnvs?->count() > 0) {
$oneClickDotEnvs->each(function ($value) use ($service) {
@@ -98,6 +101,7 @@ class Create extends Component
});
}
$service->parse(isNew: true);
return redirect()->route('project.service.configuration', [
'service_uuid' => $service->uuid,
'environment_name' => $environment->name,
@@ -108,6 +112,7 @@ class Create extends Component
$this->type = $type->value();
}
}
public function render()
{
return view('livewire.project.resource.create');

View File

@@ -9,25 +9,37 @@ use Livewire\Component;
class Index extends Component
{
public Project $project;
public Environment $environment;
public $applications = [];
public $postgresqls = [];
public $redis = [];
public $mongodbs = [];
public $mysqls = [];
public $mariadbs = [];
public $keydbs = [];
public $dragonflies = [];
public $clickhouses = [];
public $services = [];
public function mount()
{
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
if (! $project) {
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first();
if (!$environment) {
if (! $environment) {
return redirect()->route('dashboard');
}
$this->project = $project;
@@ -39,9 +51,10 @@ class Index extends Component
$application->hrefLink = route('project.application.configuration', [
'project_uuid' => data_get($application, 'environment.project.uuid'),
'environment_name' => data_get($application, 'environment.name'),
'application_uuid' => data_get($application, 'uuid')
'application_uuid' => data_get($application, 'uuid'),
]);
}
return $application;
});
$this->postgresqls = $this->environment->postgresqls->load(['tags'])->sortBy('name');
@@ -50,9 +63,10 @@ class Index extends Component
$postgresql->hrefLink = route('project.database.configuration', [
'project_uuid' => data_get($postgresql, 'environment.project.uuid'),
'environment_name' => data_get($postgresql, 'environment.name'),
'database_uuid' => data_get($postgresql, 'uuid')
'database_uuid' => data_get($postgresql, 'uuid'),
]);
}
return $postgresql;
});
$this->redis = $this->environment->redis->load(['tags'])->sortBy('name');
@@ -61,9 +75,10 @@ class Index extends Component
$redis->hrefLink = route('project.database.configuration', [
'project_uuid' => data_get($redis, 'environment.project.uuid'),
'environment_name' => data_get($redis, 'environment.name'),
'database_uuid' => data_get($redis, 'uuid')
'database_uuid' => data_get($redis, 'uuid'),
]);
}
return $redis;
});
$this->mongodbs = $this->environment->mongodbs->load(['tags'])->sortBy('name');
@@ -72,9 +87,10 @@ class Index extends Component
$mongodb->hrefLink = route('project.database.configuration', [
'project_uuid' => data_get($mongodb, 'environment.project.uuid'),
'environment_name' => data_get($mongodb, 'environment.name'),
'database_uuid' => data_get($mongodb, 'uuid')
'database_uuid' => data_get($mongodb, 'uuid'),
]);
}
return $mongodb;
});
$this->mysqls = $this->environment->mysqls->load(['tags'])->sortBy('name');
@@ -83,9 +99,10 @@ class Index extends Component
$mysql->hrefLink = route('project.database.configuration', [
'project_uuid' => data_get($mysql, 'environment.project.uuid'),
'environment_name' => data_get($mysql, 'environment.name'),
'database_uuid' => data_get($mysql, 'uuid')
'database_uuid' => data_get($mysql, 'uuid'),
]);
}
return $mysql;
});
$this->mariadbs = $this->environment->mariadbs->load(['tags'])->sortBy('name');
@@ -94,9 +111,10 @@ class Index extends Component
$mariadb->hrefLink = route('project.database.configuration', [
'project_uuid' => data_get($mariadb, 'environment.project.uuid'),
'environment_name' => data_get($mariadb, 'environment.name'),
'database_uuid' => data_get($mariadb, 'uuid')
'database_uuid' => data_get($mariadb, 'uuid'),
]);
}
return $mariadb;
});
$this->keydbs = $this->environment->keydbs->load(['tags'])->sortBy('name');
@@ -105,9 +123,10 @@ class Index extends Component
$keydb->hrefLink = route('project.database.configuration', [
'project_uuid' => data_get($keydb, 'environment.project.uuid'),
'environment_name' => data_get($keydb, 'environment.name'),
'database_uuid' => data_get($keydb, 'uuid')
'database_uuid' => data_get($keydb, 'uuid'),
]);
}
return $keydb;
});
$this->dragonflies = $this->environment->dragonflies->load(['tags'])->sortBy('name');
@@ -116,9 +135,10 @@ class Index extends Component
$dragonfly->hrefLink = route('project.database.configuration', [
'project_uuid' => data_get($dragonfly, 'environment.project.uuid'),
'environment_name' => data_get($dragonfly, 'environment.name'),
'database_uuid' => data_get($dragonfly, 'uuid')
'database_uuid' => data_get($dragonfly, 'uuid'),
]);
}
return $dragonfly;
});
$this->clickhouses = $this->environment->clickhouses->load(['tags'])->sortBy('name');
@@ -127,9 +147,10 @@ class Index extends Component
$clickhouse->hrefLink = route('project.database.configuration', [
'project_uuid' => data_get($clickhouse, 'environment.project.uuid'),
'environment_name' => data_get($clickhouse, 'environment.name'),
'database_uuid' => data_get($clickhouse, 'uuid')
'database_uuid' => data_get($clickhouse, 'uuid'),
]);
}
return $clickhouse;
});
$this->services = $this->environment->services->load(['tags'])->sortBy('name');
@@ -138,13 +159,15 @@ class Index extends Component
$service->hrefLink = route('project.service.configuration', [
'project_uuid' => data_get($service, 'environment.project.uuid'),
'environment_name' => data_get($service, 'environment.name'),
'service_uuid' => data_get($service, 'uuid')
'service_uuid' => data_get($service, 'uuid'),
]);
$service->status = $service->status();
}
return $service;
});
}
public function render()
{
return view('livewire.project.resource.index');

View File

@@ -9,34 +9,43 @@ use Livewire\Component;
class Configuration extends Component
{
public ?Service $service = null;
public $applications;
public $databases;
public array $parameters;
public array $query;
public function getListeners()
{
$userId = auth()->user()->id;
return [
"echo-private:user.{$userId},ServiceStatusChanged" => 'check_status',
"check_status",
"refresh" => '$refresh',
'check_status',
'refresh' => '$refresh',
];
}
public function render()
{
return view('livewire.project.service.configuration');
}
public function mount()
{
$this->parameters = get_route_parameters();
$this->query = request()->query();
$this->service = Service::whereUuid($this->parameters['service_uuid'])->first();
if (!$this->service) {
if (! $this->service) {
return redirect()->route('dashboard');
}
$this->applications = $this->service->applications->sort();
$this->databases = $this->service->databases->sort();
}
public function restartApplication($id)
{
try {
@@ -49,6 +58,7 @@ class Configuration extends Component
return handleError($e, $this);
}
}
public function restartDatabase($id)
{
try {
@@ -61,6 +71,7 @@ class Configuration extends Component
return handleError($e, $this);
}
}
public function check_status()
{
try {

View File

@@ -10,10 +10,13 @@ use Livewire\Component;
class Database extends Component
{
public ServiceDatabase $database;
public ?string $db_url_public = null;
public $fileStorages;
protected $listeners = ["refreshFileStorages"];
protected $listeners = ['refreshFileStorages'];
protected $rules = [
'database.human_name' => 'nullable',
'database.description' => 'nullable',
@@ -23,10 +26,12 @@ class Database extends Component
'database.is_public' => 'required|boolean',
'database.is_log_drain_enabled' => 'required|boolean',
];
public function render()
{
return view('livewire.project.service.database');
}
public function mount()
{
if ($this->database->is_public) {
@@ -34,31 +39,37 @@ class Database extends Component
}
$this->refreshFileStorages();
}
public function instantSaveExclude()
{
$this->submit();
}
public function instantSaveLogDrain()
{
if (!$this->database->service->destination->server->isLogDrainEnabled()) {
if (! $this->database->service->destination->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->submit();
$this->dispatch('success', 'You need to restart the service for the changes to take effect.');
}
public function instantSave()
{
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -71,10 +82,12 @@ class Database extends Component
}
$this->submit();
}
public function refreshFileStorages()
{
$this->fileStorages = $this->database->fileStorages()->get();
}
public function submit()
{
try {

View File

@@ -8,12 +8,15 @@ use Livewire\Component;
class EditCompose extends Component
{
public Service $service;
public $serviceId;
protected $rules = [
'service.docker_compose_raw' => 'required',
'service.docker_compose' => 'required',
'service.is_container_label_escape_enabled' => 'required',
];
public function mount()
{
$this->service = Service::find($this->serviceId);
@@ -21,17 +24,19 @@ class EditCompose extends Component
public function saveEditedCompose()
{
$this->dispatch('info', "Saving new docker compose...");
$this->dispatch('info', 'Saving new docker compose...');
$this->dispatch('saveCompose', $this->service->docker_compose_raw);
}
public function instantSave()
{
$this->validate([
'service.is_container_label_escape_enabled' => 'required',
]);
$this->service->save(['is_container_label_escape_enabled' => $this->service->is_container_label_escape_enabled]);
$this->dispatch('success', "Service updated successfully");
$this->dispatch('success', 'Service updated successfully');
}
public function render()
{
return view('livewire.project.service.edit-compose');

View File

@@ -8,14 +8,19 @@ use Livewire\Component;
class EditDomain extends Component
{
public $applicationId;
public ServiceApplication $application;
protected $rules = [
'application.fqdn' => 'nullable',
'application.required_fqdn' => 'required|boolean',
];
public function mount() {
public function mount()
{
$this->application = ServiceApplication::find($this->applicationId);
}
public function updatedApplicationFqdn()
{
$this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
@@ -26,6 +31,7 @@ class EditDomain extends Component
$this->application->fqdn = $this->application->fqdn->unique()->implode(',');
$this->application->save();
}
public function submit()
{
try {
@@ -46,6 +52,7 @@ class EditDomain extends Component
$this->dispatch('configurationChanged');
}
}
public function render()
{
return view('livewire.project.service.edit-domain');

View File

@@ -14,14 +14,17 @@ use App\Models\StandaloneMongodb;
use App\Models\StandaloneMysql;
use App\Models\StandalonePostgresql;
use App\Models\StandaloneRedis;
use Livewire\Component;
use Illuminate\Support\Str;
use Livewire\Component;
class FileStorage extends Component
{
public LocalFileVolume $fileStorage;
public ServiceApplication|StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|ServiceDatabase|Application $resource;
public string $fs_path;
public ?string $workdir = null;
protected $rules = [
@@ -30,6 +33,7 @@ class FileStorage extends Component
'fileStorage.mount_path' => 'required',
'fileStorage.content' => 'nullable',
];
public function mount()
{
$this->resource = $this->fileStorage->service;
@@ -41,7 +45,9 @@ class FileStorage extends Component
$this->fs_path = $this->fileStorage->fs_path;
}
}
public function convertToDirectory() {
public function convertToDirectory()
{
try {
$this->fileStorage->deleteStorageOnServer();
$this->fileStorage->is_directory = true;
@@ -54,7 +60,9 @@ class FileStorage extends Component
$this->dispatch('refresh_storages');
}
}
public function convertToFile() {
public function convertToFile()
{
try {
$this->fileStorage->deleteStorageOnServer();
$this->fileStorage->is_directory = false;
@@ -67,7 +75,9 @@ class FileStorage extends Component
$this->dispatch('refresh_storages');
}
}
public function delete() {
public function delete()
{
try {
$this->fileStorage->deleteStorageOnServer();
$this->fileStorage->delete();
@@ -78,6 +88,7 @@ class FileStorage extends Component
$this->dispatch('refresh_storages');
}
}
public function submit()
{
$original = $this->fileStorage->getOriginal();
@@ -92,13 +103,16 @@ class FileStorage extends Component
} catch (\Throwable $e) {
$this->fileStorage->setRawAttributes($original);
$this->fileStorage->save();
return handleError($e, $this);
}
}
public function instantSave()
{
$this->submit();
}
public function render()
{
return view('livewire.project.service.file-storage');

View File

@@ -11,11 +11,17 @@ use Livewire\Component;
class Index extends Component
{
public ?Service $service = null;
public ?ServiceApplication $serviceApplication = null;
public ?ServiceDatabase $serviceDatabase = null;
public array $parameters;
public array $query;
public Collection $services;
public $s3s;
protected $listeners = ['generateDockerCompose'];
@@ -27,7 +33,7 @@ class Index extends Component
$this->parameters = get_route_parameters();
$this->query = request()->query();
$this->service = Service::whereUuid($this->parameters['service_uuid'])->first();
if (!$this->service) {
if (! $this->service) {
return redirect()->route('dashboard');
}
$service = $this->service->applications()->whereUuid($this->parameters['stack_service_uuid'])->first();
@@ -39,15 +45,17 @@ class Index extends Component
$this->serviceDatabase->getFilesFromServer();
}
$this->s3s = currentTeam()->s3s;
} catch(\Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function generateDockerCompose()
{
$this->service->parse();
}
public function render()
{
return view('livewire.project.service.index');

View File

@@ -2,9 +2,9 @@
namespace App\Livewire\Project\Service;
use App\Actions\Shared\PullImage;
use App\Actions\Service\StartService;
use App\Actions\Service\StopService;
use App\Actions\Shared\PullImage;
use App\Events\ServiceStatusChanged;
use App\Models\Service;
use Livewire\Component;
@@ -13,8 +13,11 @@ use Spatie\Activitylog\Models\Activity;
class Navbar extends Component
{
public Service $service;
public array $parameters;
public array $query;
public $isDeploymentProgress = false;
public function mount()
@@ -25,13 +28,16 @@ class Navbar extends Component
$this->dispatch('configurationChanged');
}
}
public function getListeners()
{
$userId = auth()->user()->id;
return [
"echo-private:user.{$userId},ServiceStatusChanged" => 'serviceStarted',
];
}
public function serviceStarted()
{
$this->dispatch('success', 'Service status changed.');
@@ -48,10 +54,12 @@ class Navbar extends Component
$this->dispatch('check_status');
$this->dispatch('success', 'Service status updated.');
}
public function render()
{
return view('livewire.project.service.navbar');
}
public function checkDeployments()
{
$activity = Activity::where('properties->type_uuid', $this->service->uuid)->latest()->first();
@@ -62,17 +70,20 @@ class Navbar extends Component
$this->isDeploymentProgress = false;
}
}
public function start()
{
$this->checkDeployments();
if ($this->isDeploymentProgress) {
$this->dispatch('error', 'There is a deployment in progress.');
return;
}
$this->service->parse();
$activity = StartService::run($this->service);
$this->dispatch('activityMonitor', $activity->id);
}
public function stop(bool $forceCleanup = false)
{
StopService::run($this->service);
@@ -83,11 +94,13 @@ class Navbar extends Component
}
ServiceStatusChanged::dispatch();
}
public function restart()
{
$this->checkDeployments();
if ($this->isDeploymentProgress) {
$this->dispatch('error', 'There is a deployment in progress.');
return;
}
PullImage::run($this->service);

View File

@@ -8,7 +8,9 @@ use Livewire\Component;
class ServiceApplicationView extends Component
{
public ServiceApplication $application;
public $parameters;
protected $rules = [
'application.human_name' => 'nullable',
'application.description' => 'nullable',
@@ -20,10 +22,12 @@ class ServiceApplicationView extends Component
'application.is_gzip_enabled' => 'nullable|boolean',
'application.is_stripprefix_enabled' => 'nullable|boolean',
];
public function render()
{
return view('livewire.project.service.service-application-view');
}
public function updatedApplicationFqdn()
{
$this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
@@ -34,34 +38,41 @@ class ServiceApplicationView extends Component
$this->application->fqdn = $this->application->fqdn->unique()->implode(',');
$this->application->save();
}
public function instantSave()
{
$this->submit();
}
public function instantSaveAdvanced()
{
if (!$this->application->service->destination->server->isLogDrainEnabled()) {
if (! $this->application->service->destination->server->isLogDrainEnabled()) {
$this->application->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->application->save();
$this->dispatch('success', 'You need to restart the service for the changes to take effect.');
}
public function delete()
{
try {
$this->application->delete();
$this->dispatch('success', 'Application deleted.');
return redirect()->route('project.service.configuration', $this->parameters);
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function mount()
{
$this->parameters = get_route_parameters();
}
public function submit()
{
try {

View File

@@ -9,8 +9,11 @@ use Livewire\Component;
class StackForm extends Component
{
public Service $service;
public Collection $fields;
protected $listeners = ["saveCompose"];
protected $listeners = ['saveCompose'];
public $rules = [
'service.docker_compose_raw' => 'required',
'service.docker_compose' => 'required',
@@ -18,7 +21,9 @@ class StackForm extends Component
'service.description' => 'nullable',
'service.connect_to_docker_network' => 'nullable',
];
public $validationAttributes = [];
public function mount()
{
$this->fields = collect([]);
@@ -30,12 +35,12 @@ class StackForm extends Component
$rules = data_get($field, 'rules', 'nullable');
$isPassword = data_get($field, 'isPassword');
$this->fields->put($key, [
"serviceName" => $serviceName,
"key" => $key,
"name" => $fieldKey,
"value" => $value,
"isPassword" => $isPassword,
"rules" => $rules
'serviceName' => $serviceName,
'key' => $key,
'name' => $fieldKey,
'value' => $value,
'isPassword' => $isPassword,
'rules' => $rules,
]);
$this->rules["fields.$key.value"] = $rules;
@@ -44,11 +49,13 @@ class StackForm extends Component
}
$this->fields = $this->fields->sortBy('name');
}
public function saveCompose($raw)
{
$this->service->docker_compose_raw = $raw;
$this->submit();
}
public function instantSave()
{
$this->service->save();
@@ -82,6 +89,7 @@ class StackForm extends Component
}
}
}
public function render()
{
return view('livewire.project.service.stack-form');

View File

@@ -8,6 +8,7 @@ use Livewire\Component;
class Storage extends Component
{
public $resource;
public function getListeners()
{
return [
@@ -15,6 +16,7 @@ class Storage extends Component
'refresh_storages' => '$refresh',
];
}
public function addNewVolume($data)
{
try {
@@ -33,6 +35,7 @@ class Storage extends Component
return handleError($e, $this);
}
}
public function render()
{
return view('livewire.project.service.storage');

View File

@@ -17,16 +17,21 @@ use Livewire\Component;
class ConfigurationChecker extends Component
{
public bool $isConfigurationChanged = false;
public Application|Service|StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $resource;
protected $listeners = ['configurationChanged'];
public function mount()
{
$this->configurationChanged();
}
public function render()
{
return view('livewire.project.shared.configuration-checker');
}
public function configurationChanged()
{
$this->isConfigurationChanged = $this->resource->isConfigurationChanged();

View File

@@ -9,9 +9,13 @@ use Visus\Cuid2\Cuid2;
class Danger extends Component
{
public $resource;
public $projectUuid;
public $environmentName;
public bool $delete_configurations = true;
public ?string $modalId = null;
public function mount()
@@ -21,15 +25,17 @@ class Danger extends Component
$this->projectUuid = data_get($parameters, 'project_uuid');
$this->environmentName = data_get($parameters, 'environment_name');
}
public function delete()
{
try {
// $this->authorize('delete', $this->resource);
$this->resource->delete();
DeleteResourceJob::dispatch($this->resource, $this->delete_configurations);
return redirect()->route('project.resource.index', [
'project_uuid' => $this->projectUuid,
'environment_name' => $this->environmentName
'environment_name' => $this->environmentName,
]);
} catch (\Throwable $e) {
return handleError($e, $this);

View File

@@ -14,19 +14,23 @@ use Visus\Cuid2\Cuid2;
class Destination extends Component
{
public $resource;
public $networks = [];
public function getListeners()
{
$teamId = auth()->user()->currentTeam()->id;
return [
"echo-private:team.{$teamId},ApplicationStatusChanged" => 'loadData',
];
}
public function mount()
{
$this->loadData();
}
public function loadData()
{
$all_networks = collect([]);
@@ -48,16 +52,19 @@ class Destination extends Component
});
}
}
public function stop(int $server_id)
{
$server = Server::find($server_id);
StopApplicationOneServer::run($this->resource, $server);
$this->refreshServers();
}
public function redeploy(int $network_id, int $server_id)
{
if ($this->resource->additional_servers->count() > 0 && str($this->resource->docker_registry_image_name)->isEmpty()) {
$this->dispatch('error', 'Failed to deploy.', 'Before deploying to multiple servers, you must first set a Docker image in the General tab.<br>More information here: <a target="_blank" class="underline" href="https://coolify.io/docs/knowledge-base/server/multiple-servers">documentation</a>');
return;
}
$deployment_uuid = new Cuid2(7);
@@ -71,6 +78,7 @@ class Destination extends Component
only_this_server: true,
no_questions_asked: true,
);
return redirect()->route('project.application.deployment.show', [
'project_uuid' => data_get($this->resource, 'environment.project.uuid'),
'application_uuid' => data_get($this->resource, 'uuid'),
@@ -78,6 +86,7 @@ class Destination extends Component
'environment_name' => data_get($this->resource, 'environment.name'),
]);
}
public function promote(int $network_id, int $server_id)
{
$main_destination = $this->resource->destination;
@@ -89,6 +98,7 @@ class Destination extends Component
$this->resource->additional_networks()->attach($main_destination->id, ['server_id' => $main_destination->server->id]);
$this->refreshServers();
}
public function refreshServers()
{
GetContainersStatus::run($this->resource->destination->server);
@@ -97,16 +107,19 @@ class Destination extends Component
$this->dispatch('refresh');
ApplicationStatusChanged::dispatch(data_get($this->resource, 'environment.project.team.id'));
}
public function addServer(int $network_id, int $server_id)
{
$this->resource->additional_networks()->attach($network_id, ['server_id' => $server_id]);
$this->loadData();
ApplicationStatusChanged::dispatch(data_get($this->resource, 'environment.project.team.id'));
}
public function removeServer(int $network_id, int $server_id)
{
if ($this->resource->destination->server->id == $server_id && $this->resource->destination->id == $network_id) {
$this->dispatch('error', 'You cannot remove this destination server.', 'You are trying to remove the main server.');
return;
}
$server = Server::find($server_id);

View File

@@ -7,15 +7,23 @@ use Livewire\Component;
class Add extends Component
{
public $parameters;
public bool $shared = false;
public bool $is_preview = false;
public string $key;
public ?string $value = null;
public bool $is_build_time = false;
public bool $is_multiline = false;
public bool $is_literal = false;
protected $listeners = ['clearAddEnv' => 'clear'];
protected $rules = [
'key' => 'required|string',
'value' => 'nullable',
@@ -23,6 +31,7 @@ class Add extends Component
'is_multiline' => 'required|boolean',
'is_literal' => 'required|boolean',
];
protected $validationAttributes = [
'key' => 'key',
'value' => 'value',
@@ -40,9 +49,10 @@ class Add extends Component
{
$this->validate();
if (str($this->value)->startsWith('{{') && str($this->value)->endsWith('}}')) {
$type = str($this->value)->after("{{")->before(".")->value;
if (!collect(SHARED_VARIABLE_TYPES)->contains($type)) {
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
$type = str($this->value)->after('{{')->before('.')->value;
if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
$this->dispatch('error', 'Invalid shared variable type.', 'Valid types are: team, project, environment.');
return;
}
}

View File

@@ -9,16 +9,24 @@ use Visus\Cuid2\Cuid2;
class All extends Component
{
public $resource;
public string $resourceClass;
public bool $showPreview = false;
public ?string $modalId = null;
public ?string $variables = null;
public ?string $variablesPreview = null;
public string $view = 'normal';
protected $listeners = [
'refreshEnvs',
'saveKey' => 'submit',
];
protected $rules = [
'resource.settings.is_env_sorting_enabled' => 'required|boolean',
];
@@ -27,8 +35,8 @@ class All extends Component
{
$this->resourceClass = get_class($this->resource);
$resourceWithPreviews = ['App\Models\Application'];
$simpleDockerfile = !is_null(data_get($this->resource, 'dockerfile'));
if (str($this->resourceClass)->contains($resourceWithPreviews) && !$simpleDockerfile) {
$simpleDockerfile = ! is_null(data_get($this->resource, 'dockerfile'));
if (str($this->resourceClass)->contains($resourceWithPreviews) && ! $simpleDockerfile) {
$this->showPreview = true;
}
$this->modalId = new Cuid2(7);
@@ -49,6 +57,7 @@ class All extends Component
}
$this->getDevView();
}
public function instantSave()
{
if ($this->resourceClass === 'App\Models\Application' && data_get($this->resource, 'build_pack') !== 'dockercompose') {
@@ -57,6 +66,7 @@ class All extends Component
$this->sortMe();
}
}
public function getDevView()
{
$this->variables = $this->resource->environment_variables->map(function ($item) {
@@ -66,6 +76,7 @@ class All extends Component
if ($item->is_multiline) {
return "$item->key=(multiline, edit in normal view)";
}
return "$item->key=$item->value";
})->join('
');
@@ -77,11 +88,13 @@ class All extends Component
if ($item->is_multiline) {
return "$item->key=(multiline, edit in normal view)";
}
return "$item->key=$item->value";
})->join('
');
}
}
public function switch()
{
if ($this->view === 'normal') {
@@ -91,6 +104,7 @@ class All extends Component
}
$this->sortMe();
}
public function saveVariables($isPreview)
{
if ($isPreview) {
@@ -113,22 +127,25 @@ class All extends Component
}
$found->value = $variable;
if (str($found->value)->startsWith('{{') && str($found->value)->endsWith('}}')) {
$type = str($found->value)->after("{{")->before(".")->value;
if (!collect(SHARED_VARIABLE_TYPES)->contains($type)) {
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
$type = str($found->value)->after('{{')->before('.')->value;
if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
$this->dispatch('error', 'Invalid shared variable type.', 'Valid types are: team, project, environment.');
return;
}
}
$found->save();
continue;
} else {
$environment = new EnvironmentVariable();
$environment->key = $key;
$environment->value = $variable;
if (str($environment->value)->startsWith('{{') && str($environment->value)->endsWith('}}')) {
$type = str($environment->value)->after("{{")->before(".")->value;
if (!collect(SHARED_VARIABLE_TYPES)->contains($type)) {
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
$type = str($environment->value)->after('{{')->before('.')->value;
if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
$this->dispatch('error', 'Invalid shared variable type.', 'Valid types are: team, project, environment.');
return;
}
}
@@ -177,6 +194,7 @@ class All extends Component
}
$this->refreshEnvs();
}
public function refreshEnvs()
{
$this->resource->refresh();
@@ -189,6 +207,7 @@ class All extends Component
$found = $this->resource->environment_variables()->where('key', $data['key'])->first();
if ($found) {
$this->dispatch('error', 'Environment variable already exists.');
return;
}
$environment = new EnvironmentVariable();

View File

@@ -10,14 +10,21 @@ use Visus\Cuid2\Cuid2;
class Show extends Component
{
public $parameters;
public ModelsEnvironmentVariable|SharedEnvironmentVariable $env;
public ?string $modalId = null;
public bool $isDisabled = false;
public bool $isLocked = false;
public bool $isSharedVariable = false;
public string $type;
protected $listeners = [
"compose_loaded" => '$refresh',
'compose_loaded' => '$refresh',
];
protected $rules = [
@@ -29,6 +36,7 @@ class Show extends Component
'env.is_shown_once' => 'required|boolean',
'env.real_value' => 'nullable',
];
protected $validationAttributes = [
'env.key' => 'Key',
'env.value' => 'Value',
@@ -47,6 +55,7 @@ class Show extends Component
$this->parameters = get_route_parameters();
$this->checkEnvs();
}
public function checkEnvs()
{
$this->isDisabled = false;
@@ -57,6 +66,7 @@ class Show extends Component
$this->isLocked = true;
}
}
public function serialize()
{
data_forget($this->env, 'real_value');
@@ -64,6 +74,7 @@ class Show extends Component
data_forget($this->env, 'is_build_time');
}
}
public function lock()
{
$this->env->is_shown_once = true;
@@ -72,10 +83,12 @@ class Show extends Component
$this->checkEnvs();
$this->dispatch('refreshEnvs');
}
public function instantSave()
{
$this->submit();
}
public function submit()
{
try {
@@ -89,9 +102,10 @@ class Show extends Component
$this->validate();
}
if (str($this->env->value)->startsWith('{{') && str($this->env->value)->endsWith('}}')) {
$type = str($this->env->value)->after("{{")->before(".")->value;
if (!collect(SHARED_VARIABLE_TYPES)->contains($type)) {
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
$type = str($this->env->value)->after('{{')->before('.')->value;
if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
$this->dispatch('error', 'Invalid shared variable type.', 'Valid types are: team, project, environment.');
return;
}
}

View File

@@ -11,13 +11,21 @@ use Livewire\Component;
class ExecuteContainerCommand extends Component
{
public string $command;
public string $container;
public Collection $containers;
public $parameters;
public $resource;
public string $type;
public string $workDir = '';
public Server $server;
public Collection $servers;
protected $rules = [
@@ -43,9 +51,9 @@ class ExecuteContainerCommand extends Component
$this->servers = $this->servers->push($server);
}
}
} else if (data_get($this->parameters, 'database_uuid')) {
} elseif (data_get($this->parameters, 'database_uuid')) {
$this->type = 'database';
$resource = getResourceByUuid($this->parameters['database_uuid'], data_get(auth()->user()->currentTeam(),'id'));
$resource = getResourceByUuid($this->parameters['database_uuid'], data_get(auth()->user()->currentTeam(), 'id'));
if (is_null($resource)) {
abort(404);
}
@@ -55,14 +63,14 @@ class ExecuteContainerCommand extends Component
}
$this->container = $this->resource->uuid;
$this->containers->push($this->container);
} else if (data_get($this->parameters, 'service_uuid')) {
} elseif (data_get($this->parameters, 'service_uuid')) {
$this->type = 'service';
$this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail();
$this->resource->applications()->get()->each(function ($application) {
$this->containers->push(data_get($application, 'name') . '-' . data_get($this->resource, 'uuid'));
$this->containers->push(data_get($application, 'name').'-'.data_get($this->resource, 'uuid'));
});
$this->resource->databases()->get()->each(function ($database) {
$this->containers->push(data_get($database, 'name') . '-' . data_get($this->resource, 'uuid'));
$this->containers->push(data_get($database, 'name').'-'.data_get($this->resource, 'uuid'));
});
if ($this->resource->server->isFunctional()) {
$this->servers = $this->servers->push($this->resource->server);
@@ -72,6 +80,7 @@ class ExecuteContainerCommand extends Component
$this->container = $this->containers->first();
}
}
public function loadContainers()
{
foreach ($this->servers as $server) {
@@ -79,8 +88,8 @@ class ExecuteContainerCommand extends Component
if ($server->isSwarm()) {
$containers = collect([
[
'Names' => $this->resource->uuid . '_' . $this->resource->uuid,
]
'Names' => $this->resource->uuid.'_'.$this->resource->uuid,
],
]);
} else {
$containers = getCurrentApplicationContainerStatus($server, $this->resource->id, includePullrequests: true);
@@ -122,8 +131,8 @@ class ExecuteContainerCommand extends Component
if ($server->isForceDisabled()) {
throw new \RuntimeException('Server is disabled.');
}
$cmd = "sh -c 'if [ -f ~/.profile ]; then . ~/.profile; fi; " . str_replace("'", "'\''", $this->command) . "'";
if (!empty($this->workDir)) {
$cmd = "sh -c 'if [ -f ~/.profile ]; then . ~/.profile; fi; ".str_replace("'", "'\''", $this->command)."'";
if (! empty($this->workDir)) {
$exec = "docker exec -w {$this->workDir} {$container_name} {$cmd}";
} else {
$exec = "docker exec {$container_name} {$cmd}";
@@ -134,6 +143,7 @@ class ExecuteContainerCommand extends Component
return handleError($e, $this);
}
}
public function render()
{
return view('livewire.project.shared.execute-container-command');

View File

@@ -21,19 +21,28 @@ use Livewire\Component;
class GetLogs extends Component
{
public string $outputs = '';
public string $errors = '';
public Application|Service|StandalonePostgresql|StandaloneRedis|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|null $resource = null;
public ServiceApplication|ServiceDatabase|null $servicesubtype = null;
public Server $server;
public ?string $container = null;
public ?string $pull_request = null;
public ?bool $streamLogs = false;
public ?bool $showTimeStamps = true;
public int $numberOfLines = 100;
public function mount()
{
if (!is_null($this->resource)) {
if (! is_null($this->resource)) {
if ($this->resource->getMorphClass() === 'App\Models\Application') {
$this->showTimeStamps = $this->resource->settings->is_include_timestamps;
} else {
@@ -45,18 +54,20 @@ class GetLogs extends Component
}
if ($this->resource?->getMorphClass() === 'App\Models\Application') {
if (str($this->container)->contains('-pr-')) {
$this->pull_request = "Pull Request: " . str($this->container)->afterLast('-pr-')->beforeLast('_')->value();
$this->pull_request = 'Pull Request: '.str($this->container)->afterLast('-pr-')->beforeLast('_')->value();
}
}
}
}
public function doSomethingWithThisChunkOfOutput($output)
{
$this->outputs .= removeAnsiColors($output);
}
public function instantSave()
{
if (!is_null($this->resource)) {
if (! is_null($this->resource)) {
if ($this->resource->getMorphClass() === 'App\Models\Application') {
$this->resource->settings->is_include_timestamps = $this->showTimeStamps;
$this->resource->settings->save();
@@ -77,13 +88,16 @@ class GetLogs extends Component
}
}
}
public function getLogs($refresh = false)
{
if (!$this->server->isFunctional()) {
if (! $this->server->isFunctional()) {
return;
}
if (!$refresh && ($this->resource?->getMorphClass() === 'App\Models\Service' || str($this->container)->contains('-pr-'))) return;
if (!$this->numberOfLines) {
if (! $refresh && ($this->resource?->getMorphClass() === 'App\Models\Service' || str($this->container)->contains('-pr-'))) {
return;
}
if (! $this->numberOfLines) {
$this->numberOfLines = 1000;
}
if ($this->container) {
@@ -130,11 +144,13 @@ class GetLogs extends Component
$this->outputs = str($this->outputs)->split('/\n/')->sort(function ($a, $b) {
$a = explode(' ', $a);
$b = explode(' ', $b);
return $a[0] <=> $b[0];
})->join("\n");
}
}
}
public function render()
{
return view('livewire.project.shared.get-logs');

View File

@@ -6,8 +6,8 @@ use Livewire\Component;
class HealthChecks extends Component
{
public $resource;
protected $rules = [
'resource.health_check_enabled' => 'boolean',
'resource.health_check_path' => 'string',
@@ -24,11 +24,13 @@ class HealthChecks extends Component
'resource.custom_healthcheck_found' => 'boolean',
];
public function instantSave()
{
$this->resource->save();
$this->dispatch('success', 'Health check updated.');
}
public function submit()
{
try {
@@ -39,6 +41,7 @@ class HealthChecks extends Component
return handleError($e, $this);
}
}
public function render()
{
return view('livewire.project.shared.health-checks');

View File

@@ -3,7 +3,6 @@
namespace App\Livewire\Project\Shared;
use App\Models\Application;
use App\Models\Server;
use App\Models\Service;
use App\Models\StandaloneClickhouse;
use App\Models\StandaloneDragonfly;
@@ -19,27 +18,37 @@ use Livewire\Component;
class Logs extends Component
{
public ?string $type = null;
public Application|Service|StandalonePostgresql|StandaloneRedis|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $resource;
public Collection $servers;
public Collection $containers;
public $container = [];
public $parameters;
public $query;
public $status;
public $serviceSubType;
public $cpu;
public function loadContainers($server_id)
{
try {
$server = $this->servers->firstWhere('id', $server_id);
if (!$server->isFunctional()) {
if (! $server->isFunctional()) {
return;
}
if ($server->isSwarm()) {
$containers = collect([
[
'Names' => $this->resource->uuid . '_' . $this->resource->uuid,
]
'Names' => $this->resource->uuid.'_'.$this->resource->uuid,
],
]);
} else {
$containers = getCurrentApplicationContainerStatus($server, $this->resource->id, includePullrequests: true);
@@ -49,6 +58,7 @@ class Logs extends Component
return handleError($e, $this);
}
}
public function loadMetrics()
{
return;
@@ -57,6 +67,7 @@ class Logs extends Component
$this->cpu = $server->getMetrics();
}
}
public function mount()
{
try {
@@ -76,7 +87,7 @@ class Logs extends Component
$this->servers = $this->servers->push($server);
}
}
} else if (data_get($this->parameters, 'database_uuid')) {
} elseif (data_get($this->parameters, 'database_uuid')) {
$this->type = 'database';
$resource = getResourceByUuid($this->parameters['database_uuid'], data_get(auth()->user()->currentTeam(), 'id'));
if (is_null($resource)) {
@@ -89,21 +100,21 @@ class Logs extends Component
}
$this->container = $this->resource->uuid;
$this->containers->push($this->container);
} else if (data_get($this->parameters, 'service_uuid')) {
} elseif (data_get($this->parameters, 'service_uuid')) {
$this->type = 'service';
$this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail();
$this->resource->applications()->get()->each(function ($application) {
$this->containers->push(data_get($application, 'name') . '-' . data_get($this->resource, 'uuid'));
$this->containers->push(data_get($application, 'name').'-'.data_get($this->resource, 'uuid'));
});
$this->resource->databases()->get()->each(function ($database) {
$this->containers->push(data_get($database, 'name') . '-' . data_get($this->resource, 'uuid'));
$this->containers->push(data_get($database, 'name').'-'.data_get($this->resource, 'uuid'));
});
if ($this->resource->server->isFunctional()) {
$this->servers = $this->servers->push($this->resource->server);
}
}
$this->containers = $this->containers->sort();
if (data_get($this->query,'pull_request_id')) {
if (data_get($this->query, 'pull_request_id')) {
$this->containers = $this->containers->filter(function ($container) {
return str_contains($container, $this->query['pull_request_id']);
});

View File

@@ -7,6 +7,7 @@ use Livewire\Component;
class ResourceLimits extends Component
{
public $resource;
protected $rules = [
'resource.limits_memory' => 'required|string',
'resource.limits_memory_swap' => 'required|string',
@@ -16,6 +17,7 @@ class ResourceLimits extends Component
'resource.limits_cpuset' => 'nullable',
'resource.limits_cpu_shares' => 'nullable',
];
protected $validationAttributes = [
'resource.limits_memory' => 'memory',
'resource.limits_memory_swap' => 'swap',
@@ -29,22 +31,22 @@ class ResourceLimits extends Component
public function submit()
{
try {
if (!$this->resource->limits_memory) {
$this->resource->limits_memory = "0";
if (! $this->resource->limits_memory) {
$this->resource->limits_memory = '0';
}
if (!$this->resource->limits_memory_swap) {
$this->resource->limits_memory_swap = "0";
if (! $this->resource->limits_memory_swap) {
$this->resource->limits_memory_swap = '0';
}
if (is_null($this->resource->limits_memory_swappiness)) {
$this->resource->limits_memory_swappiness = "60";
$this->resource->limits_memory_swappiness = '60';
}
if (!$this->resource->limits_memory_reservation) {
$this->resource->limits_memory_reservation = "0";
if (! $this->resource->limits_memory_reservation) {
$this->resource->limits_memory_reservation = '0';
}
if (!$this->resource->limits_cpus) {
$this->resource->limits_cpus = "0";
if (! $this->resource->limits_cpus) {
$this->resource->limits_cpus = '0';
}
if ($this->resource->limits_cpuset === "") {
if ($this->resource->limits_cpuset === '') {
$this->resource->limits_cpuset = null;
}
if (is_null($this->resource->limits_cpu_shares)) {

View File

@@ -12,9 +12,13 @@ use Visus\Cuid2\Cuid2;
class ResourceOperations extends Component
{
public $resource;
public $projectUuid;
public $environmentName;
public $projects;
public $servers;
public function mount()
@@ -25,28 +29,29 @@ class ResourceOperations extends Component
$this->projects = Project::ownedByCurrentTeam()->get();
$this->servers = currentTeam()->servers;
}
public function cloneTo($destination_id)
{
$new_destination = StandaloneDocker::find($destination_id);
if (!$new_destination) {
if (! $new_destination) {
$new_destination = SwarmDocker::find($destination_id);
}
if (!$new_destination) {
if (! $new_destination) {
return $this->addError('destination_id', 'Destination not found.');
}
$uuid = (string)new Cuid2(7);
$uuid = (string) new Cuid2(7);
$server = $new_destination->server;
if ($this->resource->getMorphClass() === 'App\Models\Application') {
$new_resource = $this->resource->replicate()->fill([
'uuid' => $uuid,
'name' => $this->resource->name . '-clone-' . $uuid,
'name' => $this->resource->name.'-clone-'.$uuid,
'fqdn' => generateFqdn($server, $uuid),
'status' => 'exited',
'destination_id' => $new_destination->id,
]);
$new_resource->save();
if ($new_resource->destination->server->proxyType() !== 'NONE') {
$customLabels = str(implode("|", generateLabelsApplication($new_resource)))->replace("|", "\n");
$customLabels = str(implode('|', generateLabelsApplication($new_resource)))->replace('|', "\n");
$new_resource->custom_labels = base64_encode($customLabels);
$new_resource->save();
}
@@ -60,7 +65,7 @@ class ResourceOperations extends Component
$persistentVolumes = $this->resource->persistentStorages()->get();
foreach ($persistentVolumes as $volume) {
$newPersistentVolume = $volume->replicate()->fill([
'name' => $new_resource->uuid . '-' . str($volume->name)->afterLast('-'),
'name' => $new_resource->uuid.'-'.str($volume->name)->afterLast('-'),
'resource_id' => $new_resource->id,
]);
$newPersistentVolume->save();
@@ -69,9 +74,10 @@ class ResourceOperations extends Component
'project_uuid' => $this->projectUuid,
'environment_name' => $this->environmentName,
'application_uuid' => $new_resource->uuid,
]) . "#resource-operations";
]).'#resource-operations';
return redirect()->to($route);
} else if (
} elseif (
$this->resource->getMorphClass() === 'App\Models\StandalonePostgresql' ||
$this->resource->getMorphClass() === 'App\Models\StandaloneMongodb' ||
$this->resource->getMorphClass() === 'App\Models\StandaloneMysql' ||
@@ -81,10 +87,10 @@ class ResourceOperations extends Component
$this->resource->getMorphClass() === 'App\Models\StandaloneDragonfly' ||
$this->resource->getMorphClass() === 'App\Models\StandaloneClickhouse'
) {
$uuid = (string)new Cuid2(7);
$uuid = (string) new Cuid2(7);
$new_resource = $this->resource->replicate()->fill([
'uuid' => $uuid,
'name' => $this->resource->name . '-clone-' . $uuid,
'name' => $this->resource->name.'-clone-'.$uuid,
'status' => 'exited',
'started_at' => null,
'destination_id' => $new_destination->id,
@@ -95,29 +101,30 @@ class ResourceOperations extends Component
$payload = [];
if ($this->resource->type() === 'standalone-postgresql') {
$payload['standalone_postgresql_id'] = $new_resource->id;
} else if ($this->resource->type() === 'standalone-redis') {
} elseif ($this->resource->type() === 'standalone-redis') {
$payload['standalone_redis_id'] = $new_resource->id;
} else if ($this->resource->type() === 'standalone-mongodb') {
} elseif ($this->resource->type() === 'standalone-mongodb') {
$payload['standalone_mongodb_id'] = $new_resource->id;
} else if ($this->resource->type() === 'standalone-mysql') {
} elseif ($this->resource->type() === 'standalone-mysql') {
$payload['standalone_mysql_id'] = $new_resource->id;
} else if ($this->resource->type() === 'standalone-mariadb') {
} elseif ($this->resource->type() === 'standalone-mariadb') {
$payload['standalone_mariadb_id'] = $new_resource->id;
}
$newEnvironmentVariable = $environmentVarible->replicate()->fill($payload);
$newEnvironmentVariable = $environmentVarible->replicate()->fill($payload);
$newEnvironmentVariable->save();
}
$route = route('project.database.configuration', [
'project_uuid' => $this->projectUuid,
'environment_name' => $this->environmentName,
'database_uuid' => $new_resource->uuid,
]) . "#resource-operations";
]).'#resource-operations';
return redirect()->to($route);
} else if ($this->resource->type() === 'service') {
$uuid = (string)new Cuid2(7);
} elseif ($this->resource->type() === 'service') {
$uuid = (string) new Cuid2(7);
$new_resource = $this->resource->replicate()->fill([
'uuid' => $uuid,
'name' => $this->resource->name . '-clone-' . $uuid,
'name' => $this->resource->name.'-clone-'.$uuid,
'destination_id' => $new_destination->id,
]);
$new_resource->save();
@@ -136,44 +143,50 @@ class ResourceOperations extends Component
'project_uuid' => $this->projectUuid,
'environment_name' => $this->environmentName,
'service_uuid' => $new_resource->uuid,
]) . "#resource-operations";
]).'#resource-operations';
return redirect()->to($route);
}
return;
}
public function moveTo($environment_id)
{
try {
$new_environment = Environment::findOrFail($environment_id);
$this->resource->update([
'environment_id' => $environment_id
'environment_id' => $environment_id,
]);
if ($this->resource->type() === 'application') {
$route = route('project.application.configuration', [
'project_uuid' => $new_environment->project->uuid,
'environment_name' => $new_environment->name,
'application_uuid' => $this->resource->uuid,
]) . "#resource-operations";
]).'#resource-operations';
return redirect()->to($route);
} else if (str($this->resource->type())->startsWith('standalone-')) {
} elseif (str($this->resource->type())->startsWith('standalone-')) {
$route = route('project.database.configuration', [
'project_uuid' => $new_environment->project->uuid,
'environment_name' => $new_environment->name,
'database_uuid' => $this->resource->uuid,
]) . "#resource-operations";
]).'#resource-operations';
return redirect()->to($route);
} else if ($this->resource->type() === 'service') {
} elseif ($this->resource->type() === 'service') {
$route = route('project.service.configuration', [
'project_uuid' => $new_environment->project->uuid,
'environment_name' => $new_environment->name,
'service_uuid' => $this->resource->uuid,
]) . "#resource-operations";
]).'#resource-operations';
return redirect()->to($route);
}
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function render()
{
return view('livewire.project.shared.resource-operations');

View File

@@ -8,20 +8,28 @@ use Livewire\Component;
class Add extends Component
{
public $parameters;
public string $type;
public Collection $containerNames;
public string $name;
public string $command;
public string $frequency;
public ?string $container = '';
protected $listeners = ['clearScheduledTask' => 'clear'];
protected $rules = [
'name' => 'required|string',
'command' => 'required|string',
'frequency' => 'required|string',
'container' => 'nullable|string',
];
protected $validationAttributes = [
'name' => 'name',
'command' => 'command',
@@ -42,8 +50,9 @@ class Add extends Component
try {
$this->validate();
$isValid = validate_cron_expression($this->frequency);
if (!$isValid) {
if (! $isValid) {
$this->dispatch('error', 'Invalid Cron / Human expression.');
return;
}
if (empty($this->container) || $this->container == 'null') {

View File

@@ -9,9 +9,13 @@ use Livewire\Component;
class All extends Component
{
public $resource;
public Collection $containerNames;
public ?string $variables = null;
public array $parameters;
protected $listeners = ['refreshTasks', 'saveScheduledTask' => 'submit'];
public function mount()
@@ -23,13 +27,14 @@ class All extends Component
} elseif ($this->resource->type() == 'application') {
if ($this->resource->build_pack === 'dockercompose') {
$parsed = $this->resource->parseCompose();
$containers = collect(data_get($parsed,'services'))->keys();
$containers = collect(data_get($parsed, 'services'))->keys();
$this->containerNames = $containers;
} else {
$this->containerNames = collect([]);
}
}
}
public function refreshTasks()
{
$this->resource->refresh();

View File

@@ -2,17 +2,18 @@
namespace App\Livewire\Project\Shared\ScheduledTask;
use Illuminate\Support\Facades\Storage;
use Livewire\Component;
class Executions extends Component
{
public $executions = [];
public $selectedKey;
public function getListeners()
{
return [
"selectTask",
'selectTask',
];
}
@@ -20,6 +21,7 @@ class Executions extends Component
{
if ($key == $this->selectedKey) {
$this->selectedKey = null;
return;
}
$this->selectedKey = $key;

View File

@@ -2,18 +2,22 @@
namespace App\Livewire\Project\Shared\ScheduledTask;
use App\Models\ScheduledTask as ModelsScheduledTask;
use Livewire\Component;
use App\Models\Application;
use App\Models\ScheduledTask as ModelsScheduledTask;
use App\Models\Service;
use Livewire\Component;
use Visus\Cuid2\Cuid2;
class Show extends Component
{
public $parameters;
public Application|Service $resource;
public ModelsScheduledTask $task;
public ?string $modalId = null;
public string $type;
protected $rules = [
@@ -23,6 +27,7 @@ class Show extends Component
'task.frequency' => 'required|string',
'task.container' => 'nullable|string',
];
protected $validationAttributes = [
'name' => 'name',
'command' => 'command',
@@ -37,7 +42,7 @@ class Show extends Component
if (data_get($this->parameters, 'application_uuid')) {
$this->type = 'application';
$this->resource = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail();
} else if (data_get($this->parameters, 'service_uuid')) {
} elseif (data_get($this->parameters, 'service_uuid')) {
$this->type = 'service';
$this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail();
}
@@ -53,6 +58,7 @@ class Show extends Component
$this->dispatch('success', 'Scheduled task updated.');
$this->dispatch('refreshTasks');
}
public function submit()
{
$this->validate();

View File

@@ -9,15 +9,25 @@ use Livewire\Component;
class Add extends Component
{
public $resource;
public $uuid;
public $parameters;
public $isSwarm = false;
public string $name;
public string $mount_path;
public ?string $host_path = null;
public string $file_storage_path;
public ?string $file_storage_content = null;
public string $file_storage_directory_source;
public string $file_storage_directory_destination;
public $rules = [
@@ -44,13 +54,13 @@ class Add extends Component
public function mount()
{
$this->file_storage_directory_source = application_configuration_dir() . "/{$this->resource->uuid}";
$this->file_storage_directory_source = application_configuration_dir()."/{$this->resource->uuid}";
$this->uuid = $this->resource->uuid;
$this->parameters = get_route_parameters();
if (data_get($this->parameters, 'application_uuid')) {
$applicationUuid = $this->parameters['application_uuid'];
$application = Application::where('uuid', $applicationUuid)->first();
if (!$application) {
if (! $application) {
abort(404);
}
if ($application->destination->server->isSwarm()) {
@@ -59,6 +69,7 @@ class Add extends Component
}
}
}
public function submitFileStorage()
{
try {
@@ -69,7 +80,7 @@ class Add extends Component
$this->file_storage_path = trim($this->file_storage_path);
$this->file_storage_path = str($this->file_storage_path)->start('/')->value();
if ($this->resource->getMorphClass() === 'App\Models\Application') {
$fs_path = application_configuration_dir() . '/' . $this->resource->uuid . $this->file_storage_path;
$fs_path = application_configuration_dir().'/'.$this->resource->uuid.$this->file_storage_path;
}
LocalFileVolume::create(
[
@@ -78,7 +89,7 @@ class Add extends Component
'content' => $this->file_storage_content,
'is_directory' => false,
'resource_id' => $this->resource->id,
'resource_type' => get_class($this->resource)
'resource_type' => get_class($this->resource),
],
);
$this->dispatch('refresh_storages');
@@ -87,6 +98,7 @@ class Add extends Component
}
}
public function submitFileStorageDirectory()
{
try {
@@ -104,7 +116,7 @@ class Add extends Component
'mount_path' => $this->file_storage_directory_destination,
'is_directory' => true,
'resource_id' => $this->resource->id,
'resource_type' => get_class($this->resource)
'resource_type' => get_class($this->resource),
],
);
$this->dispatch('refresh_storages');
@@ -113,6 +125,7 @@ class Add extends Component
}
}
public function submitPersistentVolume()
{
try {
@@ -121,7 +134,7 @@ class Add extends Component
'mount_path' => 'required|string',
'host_path' => 'string|nullable',
]);
$name = $this->uuid . '-' . $this->name;
$name = $this->uuid.'-'.$this->name;
$this->dispatch('addNewVolume', [
'name' => $name,
'mount_path' => $this->mount_path,

View File

@@ -7,5 +7,6 @@ use Livewire\Component;
class All extends Component
{
public $resource;
protected $listeners = ['refresh_storages' => '$refresh'];
}

View File

@@ -9,10 +9,15 @@ use Visus\Cuid2\Cuid2;
class Show extends Component
{
public LocalPersistentVolume $storage;
public bool $isReadOnly = false;
public ?string $modalId = null;
public bool $isFirst = true;
public bool $isService = false;
public ?string $startedAt = null;
protected $rules = [
@@ -20,6 +25,7 @@ class Show extends Component
'storage.mount_path' => 'required|string',
'storage.host_path' => 'string|nullable',
];
protected $validationAttributes = [
'name' => 'name',
'mount_path' => 'mount',

View File

@@ -8,27 +8,35 @@ use Livewire\Component;
class Tags extends Component
{
public $resource = null;
public ?string $new_tag = null;
public $tags = [];
protected $listeners = [
'refresh' => '$refresh',
];
protected $rules = [
'resource.tags.*.name' => 'required|string|min:2',
'new_tag' => 'required|string|min:2'
'new_tag' => 'required|string|min:2',
];
protected $validationAttributes = [
'new_tag' => 'tag'
'new_tag' => 'tag',
];
public function mount()
{
$this->tags = Tag::ownedByCurrentTeam()->get();
}
public function addTag(string $id, string $name)
{
try {
if ($this->resource->tags()->where('id', $id)->exists()) {
$this->dispatch('error', 'Duplicate tags.', "Tag <span class='dark:text-warning'>$name</span> already added.");
return;
}
$this->resource->tags()->syncWithoutDetaching($id);
@@ -37,13 +45,14 @@ class Tags extends Component
return handleError($e, $this);
}
}
public function deleteTag(string $id)
{
try {
$this->resource->tags()->detach($id);
$found_more_tags = Tag::where(['id' => $id, 'team_id' => currentTeam()->id])->first();
if ($found_more_tags->applications()->count() == 0 && $found_more_tags->services()->count() == 0){
if ($found_more_tags->applications()->count() == 0 && $found_more_tags->services()->count() == 0) {
$found_more_tags->delete();
}
$this->refresh();
@@ -51,29 +60,32 @@ class Tags extends Component
return handleError($e, $this);
}
}
public function refresh()
{
$this->resource->load(['tags']);
$this->tags = Tag::ownedByCurrentTeam()->get();
$this->new_tag = null;
}
public function submit()
{
try {
$this->validate([
'new_tag' => 'required|string|min:2'
'new_tag' => 'required|string|min:2',
]);
$tags = str($this->new_tag)->trim()->explode(' ');
foreach ($tags as $tag) {
if ($this->resource->tags()->where('name', $tag)->exists()) {
$this->dispatch('error', 'Duplicate tags.', "Tag <span class='dark:text-warning'>$tag</span> already added.");
continue;
}
$found = Tag::where(['name' => $tag, 'team_id' => currentTeam()->id])->first();
if (!$found) {
if (! $found) {
$found = Tag::create([
'name' => $tag,
'team_id' => currentTeam()->id
'team_id' => currentTeam()->id,
]);
}
$this->resource->tags()->syncWithoutDetaching($found->id);
@@ -83,6 +95,7 @@ class Tags extends Component
return handleError($e, $this);
}
}
public function render()
{
return view('livewire.project.shared.tags');

View File

@@ -7,27 +7,35 @@ use Livewire\Component;
class Webhooks extends Component
{
public $resource;
public ?string $deploywebhook = null;
public ?string $githubManualWebhook = null;
public ?string $gitlabManualWebhook = null;
public ?string $bitbucketManualWebhook = null;
public ?string $giteaManualWebhook = null;
protected $rules = [
'resource.manual_webhook_secret_github' => 'nullable|string',
'resource.manual_webhook_secret_gitlab' => 'nullable|string',
'resource.manual_webhook_secret_bitbucket' => 'nullable|string',
'resource.manual_webhook_secret_gitea' => 'nullable|string',
];
public function saveSecret()
{
try {
$this->validate();
$this->resource->save();
$this->dispatch('success','Secret Saved.');
$this->dispatch('success', 'Secret Saved.');
} catch (\Exception $e) {
return handleError($e, $this);
}
}
public function mount()
{
$this->deploywebhook = generateDeployWebhook($this->resource);
@@ -36,6 +44,7 @@ class Webhooks extends Component
$this->bitbucketManualWebhook = generateGitManualWebhook($this->resource, 'bitbucket');
$this->giteaManualWebhook = generateGitManualWebhook($this->resource, 'gitea');
}
public function render()
{
return view('livewire.project.shared.webhooks');

View File

@@ -8,17 +8,20 @@ use Livewire\Component;
class Show extends Component
{
public Project $project;
public function mount() {
public function mount()
{
$projectUuid = request()->route('project_uuid');
$teamId = currentTeam()->id;
$project = Project::where('team_id', $teamId)->where('uuid', $projectUuid)->first();
if (!$project) {
if (! $project) {
return redirect()->route('dashboard');
}
$project->load(['environments']);
$this->project = $project;
}
public function render()
{
return view('livewire.project.show');