Skip to content

Commit

Permalink
Merge branch 'coollabsio:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
zaosoula authored Apr 27, 2024
2 parents 65de3d0 + 249f35f commit 4003dfc
Show file tree
Hide file tree
Showing 90 changed files with 972 additions and 456 deletions.
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> Always use `next` branch as destination branch for PRs, not `main`
2 changes: 1 addition & 1 deletion CONTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ Your horizon (Laravel scheduler): `localhost:8000/horizon` - Only reachable if y
Mails are caught by Mailpit: `localhost:8025`

## New Service Contribution
Check out the docs [here](https://coolify.io/docs/resources/services/add-service).
Check out the docs [here](https://coolify.io/docs/knowledge-base/add-a-service).

6 changes: 3 additions & 3 deletions app/Console/Commands/CleanupStuckedResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private function cleanup_stucked_resources()
$keydbs = StandaloneKeydb::withTrashed()->whereNotNull('deleted_at')->get();
foreach ($keydbs as $keydb) {
echo "Deleting stuck keydb: {$keydb->name}\n";
$redis->forceDelete();
$keydb->forceDelete();
}
} catch (\Throwable $e) {
echo "Error in cleaning stuck keydb: {$e->getMessage()}\n";
Expand All @@ -71,7 +71,7 @@ private function cleanup_stucked_resources()
$dragonflies = StandaloneDragonfly::withTrashed()->whereNotNull('deleted_at')->get();
foreach ($dragonflies as $dragonfly) {
echo "Deleting stuck dragonfly: {$dragonfly->name}\n";
$redis->forceDelete();
$dragonfly->forceDelete();
}
} catch (\Throwable $e) {
echo "Error in cleaning stuck dragonfly: {$e->getMessage()}\n";
Expand All @@ -80,7 +80,7 @@ private function cleanup_stucked_resources()
$clickhouses = StandaloneClickhouse::withTrashed()->whereNotNull('deleted_at')->get();
foreach ($clickhouses as $clickhouse) {
echo "Deleting stuck clickhouse: {$clickhouse->name}\n";
$redis->forceDelete();
$clickhouse->forceDelete();
}
} catch (\Throwable $e) {
echo "Error in cleaning stuck clickhouse: {$e->getMessage()}\n";
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Commands/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Init extends Command
public function handle()
{
$this->alive();
get_public_ips();
$full_cleanup = $this->option('full-cleanup');
$cleanup_deployments = $this->option('cleanup-deployments');
if ($cleanup_deployments) {
Expand Down Expand Up @@ -56,6 +57,7 @@ public function handle()
$this->cleanup_stucked_helper_containers();
$this->call('cleanup:stucked-resources');
}

private function restore_coolify_db_backup()
{
try {
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function schedule(Schedule $schedule): void
$this->instance_auto_update($schedule);
$this->check_scheduled_backups($schedule);
$this->check_resources($schedule);
// $this->pull_helper_image($schedule);
$this->pull_helper_image($schedule);
$this->check_scheduled_tasks($schedule);

$schedule->command('cleanup:database --yes')->daily();
Expand Down
63 changes: 35 additions & 28 deletions app/Jobs/ApplicationDeploymentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Sleep;
use Illuminate\Support\Str;
use RuntimeException;
Expand Down Expand Up @@ -711,30 +710,32 @@ private function check_image_locally_or_remotely()
private function save_environment_variables()
{
$envs = collect([]);
$ports = $this->application->settings->is_static ? [80] : $this->application->ports_exposes_array;
$ports = $this->application->main_port();
if ($this->pull_request_id !== 0) {
$this->env_filename = ".env-pr-$this->pull_request_id";
foreach ($this->application->environment_variables_preview as $env) {
$real_value = $env->real_value;
if ($env->version === '4.0.0-beta.239') {
$real_value = $env->real_value;
} else {
$real_value = escapeEnvVariables($env->real_value);
}
if ($env->is_literal) {
$real_value = '\'' . $real_value . '\'';
if ($env->is_literal) {
$real_value = '\'' . $real_value . '\'';
} else {
$real_value = escapeEnvVariables($env->real_value);
}
}
$envs->push($env->key . '=' . $real_value);
}
// Add PORT if not exists, use the first port as default
if ($this->application->environment_variables_preview->filter(fn ($env) => Str::of($env)->startsWith('PORT'))->isEmpty()) {
if ($this->application->environment_variables_preview->where('key', 'PORT')->isEmpty()) {
$envs->push("PORT={$ports[0]}");
}
// Add HOST if not exists
if ($this->application->environment_variables_preview->filter(fn ($env) => Str::of($env)->startsWith('HOST'))->isEmpty()) {
if ($this->application->environment_variables_preview->where('key', 'HOST')->isEmpty()) {
$envs->push("HOST=0.0.0.0");
}
if ($this->application->environment_variables_preview->filter(fn ($env) => Str::of($env)->startsWith('SOURCE_COMMIT'))->isEmpty()) {
// Add SOURCE_COMMIT if not exists
if ($this->application->environment_variables_preview->where('key', 'SOURCE_COMMIT')->isEmpty()) {
if (!is_null($this->commit)) {
$envs->push("SOURCE_COMMIT={$this->commit}");
} else {
Expand All @@ -744,30 +745,31 @@ private function save_environment_variables()
$envs = $envs->sort(function ($a, $b) {
return strpos($a, '$') === false ? -1 : 1;
});
Log::info("message", $envs->implode("\n"));
} else {
$this->env_filename = ".env";
foreach ($this->application->environment_variables as $env) {
$real_value = $env->real_value;
if ($env->version === '4.0.0-beta.239') {
$real_value = $env->real_value;
} else {
$real_value = escapeEnvVariables($env->real_value);
}
if ($env->is_literal) {
$real_value = '\'' . $real_value . '\'';
if ($env->is_literal) {
$real_value = '\'' . $real_value . '\'';
} else {
$real_value = escapeEnvVariables($env->real_value);
}
}
$envs->push($env->key . '=' . $real_value);
}
// Add PORT if not exists, use the first port as default
if ($this->application->environment_variables->filter(fn ($env) => Str::of($env)->startsWith('PORT'))->isEmpty()) {
if ($this->application->environment_variables->where('key', 'PORT')->isEmpty()) {
$envs->push("PORT={$ports[0]}");
}
// Add HOST if not exists
if ($this->application->environment_variables->filter(fn ($env) => Str::of($env)->startsWith('HOST'))->isEmpty()) {
if ($this->application->environment_variables->where('key', 'HOST')->isEmpty()) {
$envs->push("HOST=0.0.0.0");
}
if ($this->application->environment_variables->filter(fn ($env) => Str::of($env)->startsWith('SOURCE_COMMIT'))->isEmpty()) {
// Add SOURCE_COMMIT if not exists
if ($this->application->environment_variables->where('key', 'SOURCE_COMMIT')->isEmpty()) {
if (!is_null($this->commit)) {
$envs->push("SOURCE_COMMIT={$this->commit}");
} else {
Expand Down Expand Up @@ -999,10 +1001,6 @@ private function prepare_builder_image()
}
$this->application_deployment_queue->addLogEntry("Preparing container with helper image: $helperImage.");
$this->execute_remote_command(
[
"command" => "docker pull -q {$helperImage}",
"hidden" => true
],
[
"command" => "docker rm -f {$this->deployment_uuid}",
"ignore_errors" => true,
Expand Down Expand Up @@ -1218,7 +1216,7 @@ private function generate_env_variables()
private function generate_compose_file()
{
$this->create_workdir();
$ports = $this->application->settings->is_static ? [80] : $this->application->ports_exposes_array;
$ports = $this->application->main_port();
$onlyPort = null;
if (count($ports) > 0) {
$onlyPort = $ports[0];
Expand Down Expand Up @@ -1512,7 +1510,7 @@ private function generate_local_persistent_volumes_only_volume_names()
return $local_persistent_volumes_names;
}

private function generate_environment_variables($ports)
/*private function generate_environment_variables($ports)
{
$environment_variables = collect();
if ($this->pull_request_id === 0) {
Expand All @@ -1530,8 +1528,10 @@ private function generate_environment_variables($ports)
}
if ($env->is_literal) {
$real_value = escapeDollarSign($real_value);
$environment_variables->push("$env->key='$real_value'");
} else {
$environment_variables->push("$env->key=$real_value");
}
$environment_variables->push("$env->key=$real_value");
}
foreach ($this->application->nixpacks_environment_variables as $env) {
if ($env->version === '4.0.0-beta.239') {
Expand All @@ -1541,8 +1541,10 @@ private function generate_environment_variables($ports)
}
if ($env->is_literal) {
$real_value = escapeDollarSign($real_value);
$environment_variables->push("$env->key='$real_value'");
} else {
$environment_variables->push("$env->key=$real_value");
}
$environment_variables->push("$env->key=$real_value");
}
} else {
foreach ($this->application->runtime_environment_variables_preview as $env) {
Expand All @@ -1553,8 +1555,10 @@ private function generate_environment_variables($ports)
}
if ($env->is_literal) {
$real_value = escapeDollarSign($real_value);
$environment_variables->push("$env->key='$real_value'");
} else {
$environment_variables->push("$env->key=$real_value");
}
$environment_variables->push("$env->key=$real_value");
}
foreach ($this->application->nixpacks_environment_variables_preview as $env) {
if ($env->version === '4.0.0-beta.239') {
Expand All @@ -1564,8 +1568,10 @@ private function generate_environment_variables($ports)
}
if ($env->is_literal) {
$real_value = escapeDollarSign($real_value);
$environment_variables->push("$env->key='$real_value'");
} else {
$environment_variables->push("$env->key=$real_value");
}
$environment_variables->push("$env->key=$real_value");
}
}
// Add PORT if not exists, use the first port as default
Expand All @@ -1583,8 +1589,9 @@ private function generate_environment_variables($ports)
$environment_variables->push("SOURCE_COMMIT=unknown");
}
}
ray($environment_variables->all());
return $environment_variables->all();
}
}*/

private function generate_healthcheck_commands()
{
Expand Down
8 changes: 8 additions & 0 deletions app/Livewire/Project/Application/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Advanced extends Component
'application.settings.gpu_count' => 'string|required',
'application.settings.gpu_device_ids' => 'string|required',
'application.settings.gpu_options' => 'string|required',
'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();
Expand Down Expand Up @@ -54,8 +56,14 @@ public function instantSave()
$this->application->settings->is_stripprefix_enabled = $this->is_stripprefix_enabled;
$this->dispatch('resetDefaultLabels', false);
}
if ($this->application->settings->is_raw_compose_deployment_enabled) {
$this->application->parseRawCompose();
} else {
$this->application->parseCompose();
}
$this->application->settings->save();
$this->dispatch('success', 'Settings saved.');
$this->dispatch('configurationChanged');
}
public function submit() {
if ($this->application->settings->gpu_count && $this->application->settings->gpu_device_ids) {
Expand Down
10 changes: 2 additions & 8 deletions app/Livewire/Project/Application/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class General extends Component
public $parsedServiceDomains = [];

protected $listeners = [
'resetDefaultLabels'
'resetDefaultLabels',
'configurationChanged' => '$refresh'
];
protected $rules = [
'application.name' => 'required',
Expand Down Expand Up @@ -72,7 +73,6 @@ class General extends Component
'application.post_deployment_command' => 'nullable',
'application.post_deployment_command_container' => 'nullable',
'application.settings.is_static' => 'boolean|required',
'application.settings.is_raw_compose_deployment_enabled' => 'boolean|required',
'application.settings.is_build_server_enabled' => 'boolean|required',
'application.watch_paths' => 'nullable',
];
Expand Down Expand Up @@ -108,7 +108,6 @@ class General extends Component
'application.docker_compose_custom_start_command' => 'Docker compose custom start command',
'application.docker_compose_custom_build_command' => 'Docker compose custom build command',
'application.settings.is_static' => 'Is static',
'application.settings.is_raw_compose_deployment_enabled' => 'Is raw compose deployment enabled',
'application.settings.is_build_server_enabled' => 'Is build server enabled',
'application.watch_paths' => 'Watch paths',
];
Expand Down Expand Up @@ -337,11 +336,6 @@ public function submit($showToaster = true)
check_domain_usage(resource: $this->application);
}
}
if ($this->application->settings->is_raw_compose_deployment_enabled) {
$this->application->parseRawCompose();
} else {
$this->parsedServices = $this->application->parseCompose();
}
}
$this->application->custom_labels = base64_encode($this->customLabels);
$this->application->save();
Expand Down
22 changes: 0 additions & 22 deletions app/Livewire/Project/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,6 @@ class Edit extends Component
'project.name' => 'required|min:3|max:255',
'project.description' => 'nullable|string|max:255',
];
protected $listeners = ['refreshEnvs' => '$refresh', 'saveKey' => 'saveKey'];

public function saveKey($data)
{
try {
$found = $this->project->environment_variables()->where('key', $data['key'])->first();
if ($found) {
throw new \Exception('Variable already exists.');
}
$this->project->environment_variables()->create([
'key' => $data['key'],
'value' => $data['value'],
'is_multiline' => $data['is_multiline'],
'is_literal' => $data['is_literal'],
'type' => 'project',
'team_id' => currentTeam()->id,
]);
$this->project->refresh();
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function mount()
{
$projectUuid = request()->route('project_uuid');
Expand Down
23 changes: 0 additions & 23 deletions app/Livewire/Project/EnvironmentEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,6 @@ class EnvironmentEdit extends Component
'environment.name' => 'required|min:3|max:255',
'environment.description' => 'nullable|min:3|max:255',
];
protected $listeners = ['refreshEnvs' => '$refresh', 'saveKey' => 'saveKey'];

public function saveKey($data)
{
try {
$found = $this->environment->environment_variables()->where('key', $data['key'])->first();
if ($found) {
throw new \Exception('Variable already exists.');
}
$this->environment->environment_variables()->create([
'key' => $data['key'],
'value' => $data['value'],
'is_multiline' => $data['is_multiline'],
'is_literal' => $data['is_literal'],
'type' => 'environment',
'team_id' => currentTeam()->id,
]);
$this->environment->refresh();
} catch (\Throwable $e) {
return handleError($e, $this);
}
}

public function mount()
{
$this->parameters = get_route_parameters();
Expand Down
6 changes: 3 additions & 3 deletions app/Livewire/Project/Shared/EnvironmentVariable/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public function mount()
public function checkEnvs()
{
$this->isDisabled = false;
// if (str($this->env->key)->startsWith('SERVICE_FQDN') || str($this->env->key)->startsWith('SERVICE_URL')) {
// $this->isDisabled = true;
// }
if (str($this->env->key)->startsWith('SERVICE_FQDN') || str($this->env->key)->startsWith('SERVICE_URL')) {
$this->isDisabled = true;
}
if ($this->env->is_shown_once) {
$this->isLocked = true;
}
Expand Down
19 changes: 19 additions & 0 deletions app/Livewire/SharedVariables/Environment/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Livewire\SharedVariables\Environment;

use App\Models\Project;
use Illuminate\Support\Collection;
use Livewire\Component;

class Index extends Component
{
public Collection $projects;
public function mount() {
$this->projects = Project::ownedByCurrentTeam()->get();
}
public function render()
{
return view('livewire.shared-variables.environment.index');
}
}
Loading

0 comments on commit 4003dfc

Please sign in to comment.