An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
wip: services
Andras Bacsai6b75ff7de48c
diff --git a/app/Actions/Proxy/StartProxy.php b/app/Actions/Proxy/StartProxy.phpindex 944480ef21..edb84dd014 100644--- a/app/Actions/Proxy/StartProxy.php+++ b/app/Actions/Proxy/StartProxy.php@@ -14,15 +14,10 @@ class StartProxyuse AsAction;public function handle(Server $server, bool $async = true): Activity|string{- $proxyType = data_get($server,'proxy.type');+ $proxyType = $server->proxyType();if ($proxyType === 'none') {return 'OK';}- if (is_null($proxyType)) {- $server->proxy->type = ProxyTypes::TRAEFIK_V2->value;- $server->proxy->status = ProxyStatus::EXITED->value;- $server->save();- }$proxy_path = get_proxy_path();$networks = collect($server->standaloneDockers)->map(function ($docker) {return $docker['network'];diff --git a/app/Actions/Service/StartService.php b/app/Actions/Service/StartService.phpnew file mode 100644index 0000000000..1ce7b6470e--- /dev/null+++ b/app/Actions/Service/StartService.php@@ -0,0 +1,30 @@+<?php++namespace App\Actions\Service;++use Lorisleiva\Actions\Concerns\AsAction;+use App\Models\Service;++class StartService+{+ use AsAction;+ public function handle(Service $service)+ {+ $workdir = service_configuration_dir() . "/{$service->uuid}";+ $commands[] = "echo 'Starting service {$service->name} on {$service->server->name}'";+ $commands[] = "mkdir -p $workdir";+ $commands[] = "cd $workdir";++ $docker_compose_base64 = base64_encode($service->docker_compose);+ $commands[] = "echo $docker_compose_base64 | base64 -d > docker-compose.yml";+ $envs = $service->environment_variables()->get();+ foreach ($envs as $env) {+ $commands[] = "echo '{$env->key}={$env->value}' >> .env";+ }+ $commands[] = "docker compose pull";+ $commands[] = "docker compose up -d";+ $commands[] = "docker network connect $service->uuid coolify-proxy";+ $activity = remote_process($commands, $service->server);+ return $activity;+ }+}diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.phpindex f5ecf1fe1e..affc4bcab4 100644--- a/app/Http/Livewire/Project/Application/General.php+++ b/app/Http/Livewire/Project/Application/General.php@@ -34,7 +34,6 @@ class General extends Componentpublic bool $is_auto_deploy_enabled;public bool $is_force_https_enabled;- public array $service_configurations = [];protected $rules = ['application.name' => 'required',@@ -55,9 +54,6 @@ class General extends Component'application.dockerfile' => 'nullable','application.dockercompose_raw' => 'nullable','application.dockercompose' => 'nullable',- 'application.service_configurations.*' => 'nullable',- 'service_configurations.*.fqdn' => 'nullable|url',- 'service_configurations.*.port' => 'integer',];protected $validationAttributes = ['application.name' => 'name',@@ -78,8 +74,6 @@ class General extends Component'application.dockerfile' => 'Dockerfile','application.dockercompose_raw' => 'Docker Compose (raw)','application.dockercompose' => 'Docker Compose',- 'service_configurations.*.fqdn' => 'FQDN',- 'service_configurations.*.port' => 'Port',];@@ -115,7 +109,6 @@ class General extends Componentpublic function mount(){- $this->services = $this->application->services();$this->is_static = $this->application->settings->is_static;$this->is_git_submodules_enabled = $this->application->settings->is_git_submodules_enabled;$this->is_git_lfs_enabled = $this->application->settings->is_git_lfs_enabled;@@ -124,9 +117,6 @@ class General extends Component$this->is_auto_deploy_enabled = $this->application->settings->is_auto_deploy_enabled;$this->is_force_https_enabled = $this->application->settings->is_force_https_enabled;$this->checkWildCardDomain();- if (data_get($this->application, 'service_configurations')) {- $this->service_configurations = $this->application->service_configurations;- }}public function generateGlobalRandomDomain()@@ -156,7 +146,6 @@ class General extends Componentpublic function submit(){try {- $this->application->service_configurations = $this->service_configurations;$this->validate();if (data_get($this->application, 'fqdn')) {$domains = Str::of($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {diff --git a/app/Http/Livewire/Project/New/DockerCompose.php b/app/Http/Livewire/Project/New/DockerCompose.phpindex d74cdb3686..00faa48635 100644--- a/app/Http/Livewire/Project/New/DockerCompose.php+++ b/app/Http/Livewire/Project/New/DockerCompose.php@@ -40,8 +40,6 @@ class DockerCompose extends Component- database__connection__user=$SERVICE_USER_MYSQL- database__connection__password=$SERVICE_PASSWORD_MYSQL- database__connection__database=${MYSQL_DATABASE-ghost}- ports:- - "2368"depends_on:- mysqlmysql:@@ -62,93 +60,25 @@ class DockerCompose extends Component$this->validate(['dockercompose' => 'required']);- $destination_uuid = $this->query['destination'];- $destination = StandaloneDocker::where('uuid', $destination_uuid)->first();- if (!$destination) {- $destination = SwarmDocker::where('uuid', $destination_uuid)->first();- }- if (!$destination) {- throw new \Exception('Destination not found. What?!');- }- $destination_class = $destination->getMorphClass();+ $server_id = $this->query['server_id'];$project = Project::where('uuid', $this->parameters['project_uuid'])->first();$environment = $project->load(['environments'])->environments->where('name', $this->parameters['environment_name'])->first();- $service = new Service();- $service->uuid = (string) new Cuid2(7);- $service->name = 'service-' . new Cuid2(7);- $service->docker_compose_raw = $this->dockercompose;- $service->environment_id = $environment->id;- $service->destination_id = $destination->id;- $service->destination_type = $destination_class;- $service->save();- $service->parse(saveIt: true);++ $service = Service::create([+ 'name' => 'service' . Str::random(10),+ 'docker_compose_raw' => $this->dockercompose,+ 'environment_id' => $environment->id,+ 'server_id' => (int) $server_id,+ ]);+ $service->name = "service-$service->uuid";++ $service->parse(isNew: true);return redirect()->route('project.service', ['service_uuid' => $service->uuid,'environment_name' => $environment->name,'project_uuid' => $project->uuid,]);- // $compose = data_get($parsedService, 'docker_compose');- // $service->docker_compose = $compose;- // $shouldDefine = data_get($parsedService, 'should_define', collect([]));- // if ($shouldDefine->count() > 0) {- // $envs = data_get($shouldDefine, 'envs', []);- // foreach($envs as $env) {- // ray($env);- // $variableName = Str::of($env)->before('=');- // $variableValue = Str::of($env)->after('=');- // ray($variableName, $variableValue);- // }- // }- // foreach ($services as $serviceName => $serviceDetails) {- // if (data_get($serviceDetails,'is_database')) {- // $serviceDatabase = new ServiceDatabase();- // $serviceDatabase->name = $serviceName . '-' . $service->uuid;- // $serviceDatabase->service_id = $service->id;- // $serviceDatabase->save();- // } else {- // $serviceApplication = new ServiceApplication();- // $serviceApplication->name = $serviceName . '-' . $service->uuid;- // $serviceApplication->fqdn =- // $serviceApplication->service_id = $service->id;- // $serviceApplication->save();- // }- // }-- // ray($details);- // $envs = data_get($details, 'envs', []);- // if ($envs->count() > 0) {- // foreach ($envs as $env) {- // $key = Str::of($env)->before('=');- // $value = Str::of($env)->after('=');- // EnvironmentVariable::create([- // 'key' => $key,- // 'value' => $value,- // 'is_build_time' => false,- // 'service_id' => $service->id,- // 'is_preview' => false,- // ]);- // }- // }- // $volumes = data_get($details, 'volumes', []);- // if ($volumes->count() > 0) {- // foreach ($volumes as $volume => $mount_path) {- // LocalPersistentVolume::create([- // 'name' => $volume,- // 'mount_path' => $mount_path,- // 'resource_id' => $service->id,- // 'resource_type' => $service->getMorphClass(),- // 'is_readonly' => false- // ]);- // }- // }- // $dockercompose_coolified = data_get($details, 'dockercompose', '');- // $service->update([- // 'docker_compose' => $dockercompose_coolified,- // ]);---}}diff --git a/app/Http/Livewire/Project/New/Select.php b/app/Http/Livewire/Project/New/Select.phpindex 89a58d20e3..53fb6c9fdb 100644--- a/app/Http/Livewire/Project/New/Select.php+++ b/app/Http/Livewire/Project/New/Select.php@@ -83,6 +83,7 @@ class Select extends Component'environment_name' => $this->parameters['environment_name'],'type' => $this->type,'destination' => $this->destination_uuid,+ 'server_id' => $this->server_id,]);}diff --git a/app/Http/Livewire/Project/Service/Index.php b/app/Http/Livewire/Project/Service/Index.phpindex 17429d3151..348f16f8bf 100644--- a/app/Http/Livewire/Project/Service/Index.php+++ b/app/Http/Livewire/Project/Service/Index.php@@ -2,7 +2,10 @@namespace App\Http\Livewire\Project\Service;+use App\Actions\Service\StartService;+use App\Jobs\ContainerStatusJob;use App\Models\Service;+use Illuminate\Support\Collection;use Livewire\Component;class Index extends Component@@ -11,14 +14,66 @@ class Index extends Componentpublic array $parameters;public array $query;+ public Collection $services;- public function mount() {+ protected $rules = [+ 'services.*.fqdn' => 'nullable',+ ];++ public function mount()+ {+ $this->services = collect([]);$this->parameters = get_route_parameters();$this->query = request()->query();$this->service = Service::whereUuid($this->parameters['service_uuid'])->firstOrFail();+ foreach ($this->service->applications as $application) {+ $this->services->put($application->name, [+ 'fqdn' => $application->fqdn,+ ]);+ }+ // foreach ($this->service->databases as $database) {+ // $this->services->put($database->name, $database->fqdn);+ // }}public function render(){return view('livewire.project.service.index')->layout('layouts.app');}+ public function check_status()+ {+ dispatch_sync(new ContainerStatusJob($this->service->server));+ $this->service->refresh();++ }+ public function submit()+ {+ try {+ if ($this->services->count() === 0) {+ return;+ }+ foreach ($this->services as $name => $value) {+ $foundService = $this->service->applications()->whereName($name)->first();+ if ($foundService) {+ $foundService->fqdn = data_get($value, 'fqdn');+ $foundService->save();+ return;+ }+ $foundService = $this->service->databases()->whereName($name)->first();+ if ($foundService) {+ // $foundService->save();+ return;+ }+ }+ } catch (\Throwable $e) {+ ray($e);+ } finally {+ $this->service->parse();+ }+ }+ public function deploy()+ {+ $this->service->parse();+ $activity = StartService::run($this->service);+ $this->emit('newMonitorActivity', $activity->id);+ }}diff --git a/app/Http/Livewire/Service/Index.php b/app/Http/Livewire/Service/Index.phpdeleted file mode 100644index fbf6510848..0000000000--- a/app/Http/Livewire/Service/Index.php+++ /dev/null@@ -1,25 +0,0 @@-<?php--namespace App\Http\Livewire\Service;--use App\Models\Service;-use Livewire\Component;--class Index extends Component-{- public Service $service;-- public array $parameters;- public array $query;-- public function mount() {- $this->parameters = get_route_parameters();- $this->query = request()->query();- $this->service = Service::whereUuid($this->parameters['service_uuid'])->firstOrFail();- ray($this->service->docker_compose);- }- public function render()- {- return view('livewire.project.service.index')->layout('layouts.app');- }-}diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex 816742d8f3..7e59d99bd1 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -73,7 +73,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted$this->log_model = $this->application_deployment_queue;$this->application = Application::find($this->application_deployment_queue->application_id);- $isService = $this->application->services()->count() > 0;$this->application_deployment_queue_id = $application_deployment_queue_id;$this->deployment_uuid = $this->application_deployment_queue->deployment_uuid;$this->pull_request_id = $this->application_deployment_queue->pull_request_id;@@ -129,8 +128,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncryptedtry {if ($this->application->dockerfile) {$this->deploy_simple_dockerfile();- } else if ($this->application->services()->count() > 0) {- $this->deploy_docker_compose();} else {if ($this->pull_request_id !== 0) {$this->deploy_pull_request();diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.phpindex 234f8e9117..6da47121b6 100644--- a/app/Jobs/ContainerStatusJob.php+++ b/app/Jobs/ContainerStatusJob.php@@ -74,6 +74,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted$containers = format_docker_command_output_to_json($containers);$applications = $this->server->applications();$databases = $this->server->databases();+ $services = $this->server->services();$previews = $this->server->previews();/// Check if proxy is running@@ -92,6 +93,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted$foundApplications = [];$foundApplicationPreviews = [];$foundDatabases = [];+ $foundServices = [];foreach ($containers as $container) {$containerStatus = data_get($container, 'State.Status');$labels = data_get($container, 'Config.Labels');@@ -138,7 +140,69 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted}}}+ $serviceLabelId = data_get($labels, 'coolify.serviceId');+ if ($serviceLabelId) {+ $coolifyName = data_get($labels, 'coolify.name');+ $serviceName = Str::of($coolifyName)->before('-');+ $serviceUuid = Str::of($coolifyName)->after('-');+ $service = $services->where('uuid', $serviceUuid)->first();+ if ($service) {+ $foundService = $service->byName($serviceName);+ if ($foundService) {+ $foundServices[] = "$foundService->id-$serviceName";+ $statusFromDb = $foundService->status;+ if ($statusFromDb !== $containerStatus) {+ ray('Updating status: ' . $containerStatus);+ $foundService->update(['status' => $containerStatus]);+ }+ }+ }+ }}+ $exitedServices = collect([]);+ foreach ($services->get() as $service) {+ $apps = $service->applications()->get();+ $dbs = $service->databases()->get();+ foreach ($apps as $app) {+ if (in_array("$service->id-$app->name", $foundServices)) {+ continue;+ } else {+ $exitedServices->push($service);+ $app->update(['status' => 'exited']);+ }+ }+ foreach ($dbs as $db) {+ if (in_array("$service->id-$db->name", $foundServices)) {+ continue;+ } else {+ $exitedServices->push($service);+ $db->update(['status' => 'exited']);+ }+ }+ }+ $exitedServices = $exitedServices->unique('id');+ ray($exitedServices);+ // ray($exitedServices);+ // foreach ($serviceIds as $serviceId) {+ // $service = $services->where('id', $serviceId)->first();+ // if ($service->status === 'exited') {+ // continue;+ // }++ // $name = data_get($service, 'name');+ // $fqdn = data_get($service, 'fqdn');++ // $containerName = $name ? "$name ($fqdn)" : $fqdn;++ // $project = data_get($service, 'environment.project');+ // $environment = data_get($service, 'environment');++ // $url = base_url() . '/project/' . $project->uuid . "/" . $environment->name . "/service/" . $service->uuid;++ // $this->server->team->notify(new ContainerStopped($containerName, $this->server, $url));+ // }++$notRunningApplications = $applications->pluck('id')->diff($foundApplications);foreach ($notRunningApplications as $applicationId) {$application = $applications->where('id', $applicationId)->first();diff --git a/app/Models/Application.php b/app/Models/Application.phpindex 2286ace22c..8f518efc9f 100644--- a/app/Models/Application.php+++ b/app/Models/Application.php@@ -12,9 +12,7 @@ use Illuminate\Support\Str;class Application extends BaseModel{protected $guarded = [];- protected $casts = [- 'service_configurations' => 'array',- ];+protected static function booted(){static::created(function ($application) {diff --git a/app/Models/Server.php b/app/Models/Server.phpindex 13df241d6a..89f1041990 100644--- a/app/Models/Server.php+++ b/app/Models/Server.php@@ -2,6 +2,8 @@namespace App\Models;+use App\Enums\ProxyStatus;+use App\Enums\ProxyTypes;use Illuminate\Database\Eloquent\Builder;use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;use Spatie\SchemalessAttributes\SchemalessAttributesTrait;@@ -77,6 +79,12 @@ class Server extends BaseModel}public function proxyType() {+ $type = $this->proxy->get('type');+ if (is_null($type)) {+ $this->proxy->type = ProxyTypes::TRAEFIK_V2->value;+ $this->proxy->status = ProxyStatus::EXITED->value;+ $this->save();+ }return $this->proxy->get('type');}public function scopeWithProxy(): Builder@@ -107,6 +115,9 @@ class Server extends BaseModelreturn $standaloneDocker->applications;})->flatten();}+ public function services() {+ return $this->hasMany(Service::class);+ }public function previews() {return $this->destinations()->map(function ($standaloneDocker) {diff --git a/app/Models/Service.php b/app/Models/Service.phpindex c4d4929482..e713d51305 100644--- a/app/Models/Service.php+++ b/app/Models/Service.php@@ -2,6 +2,7 @@namespace App\Models;+use App\Enums\ProxyTypes;use Illuminate\Database\Eloquent\Casts\Attribute;use Illuminate\Database\Eloquent\Factories\HasFactory;use Illuminate\Database\Eloquent\Relations\HasMany;@@ -13,10 +14,6 @@ class Service extends BaseModel{use HasFactory;protected $guarded = [];- public function destination()- {- return $this->morphTo();- }public function persistentStorages(){return $this->morphMany(LocalPersistentVolume::class, 'resource');@@ -46,26 +43,49 @@ class Service extends BaseModel{return $this->hasMany(ServiceDatabase::class);}+ public function environment()+ {+ return $this->belongsTo(Environment::class);+ }+ public function server() {+ return $this->belongsTo(Server::class);+ }++ public function byName(string $name)+ {+ $app = $this->applications()->whereName($name)->first();+ if ($app) {+ return $app;+ }+ $db = $this->databases()->whereName($name)->first();+ if ($db) {+ return $db;+ }+ return null;+ }public function environment_variables(): HasMany{return $this->hasMany(EnvironmentVariable::class)->orderBy('key', 'asc');}- public function parse(bool $saveIt = false): Collection+ public function parse(bool $isNew = false): Collection{+ // ray()->clearAll();+ ray('Service parse');if ($this->docker_compose_raw) {- ray()->clearAll();$yaml = Yaml::parse($this->docker_compose_raw);$composeVolumes = collect(data_get($yaml, 'volumes', []));$composeNetworks = collect(data_get($yaml, 'networks', []));+ $dockerComposeVersion = data_get($yaml, 'version') ?? '3.8';$services = data_get($yaml, 'services');- $definedNetwork = data_get($this, 'destination.network');+ $definedNetwork = $this->uuid;$volumes = collect([]);$envs = collect([]);$ports = collect([]);- $services = collect($services)->map(function ($service, $serviceName) use ($composeVolumes, $composeNetworks, $definedNetwork, $envs, $volumes, $ports, $saveIt) {+ $services = collect($services)->map(function ($service, $serviceName) use ($composeVolumes, $composeNetworks, $definedNetwork, $envs, $volumes, $ports, $isNew) {+ $container_name = "$serviceName-{$this->uuid}";$isDatabase = false;// Decide if the service is a database$image = data_get($service, 'image');@@ -76,24 +96,49 @@ class Service extends BaseModeldata_set($service, 'is_database', true);}}- if ($saveIt) {+ if ($isNew) {if ($isDatabase) {$savedService = ServiceDatabase::create(['name' => $serviceName,'service_id' => $this->id]);} else {+ $defaultUsableFqdn = "http://$serviceName-{$this->uuid}.{$this->server->ip}.sslip.io";+ if (isDev()) {+ $defaultUsableFqdn = "http://$serviceName-{$this->uuid}.127.0.0.1.sslip.io";+ }$savedService = ServiceApplication::create(['name' => $serviceName,+ 'fqdn' => $defaultUsableFqdn,'service_id' => $this->id]);}+ } else {+ if ($isDatabase) {+ $savedService = $this->databases()->whereName($serviceName)->first();+ } else {+ $savedService = $this->applications()->whereName($serviceName)->first();+ }}+ $fqdn = data_get($savedService, 'fqdn');// Collect ports$servicePorts = collect(data_get($service, 'ports', []));$ports->put($serviceName, $servicePorts);- if ($saveIt) {- $savedService->ports_exposes = $servicePorts->implode(',');+ if ($isNew) {+ $ports = collect([]);+ if ($servicePorts->count() > 0) {+ foreach ($servicePorts as $sport) {+ if (is_string($sport)) {+ $ports->push($sport);+ }+ if (is_array($sport)) {+ $target = data_get($sport, 'target');+ $published = data_get($sport, 'published');+ $ports->push("$target:$published");+ }+ }+ }+ $savedService->ports_exposes = $ports->implode(',');$savedService->save();}// Collect volumes@@ -117,7 +162,7 @@ class Service extends BaseModel$composeVolumes->put($volumeName, null);}$volumes->put($volumeName, $volumePath);- if ($saveIt) {+ if ($isNew) {LocalPersistentVolume::create(['name' => $volumeName,'mount_path' => $volumePath,@@ -137,7 +182,7 @@ class Service extends BaseModelreturn $value == $networkName || $key == $networkName;});if (!$networkExists) {- $composeNetworks->put($networkName, null);+ $composeNetworks->put($networkDetails, null);}}}@@ -147,11 +192,16 @@ class Service extends BaseModel});if (!$definedNetworkExists) {$composeNetworks->put($definedNetwork, [- 'external' => true+ 'name' => $definedNetwork,+ 'external' => false]);}+ $networks = $serviceNetworks->toArray();+ $networks = array_merge($networks, [$definedNetwork]);+ data_set($service, 'networks', $networks);+- // Get variables from the service that does not start with SERVICE_*+ // Get variables from the service$serviceVariables = collect(data_get($service, 'environment', []));foreach ($serviceVariables as $variable) {$value = Str::after($variable, '=');@@ -179,7 +229,7 @@ class Service extends BaseModel}if (!$envs->has($nakedName->value())) {$envs->put($nakedName->value(), $nakedValue->value());- if ($saveIt) {+ if ($isNew) {EnvironmentVariable::create(['key' => $nakedName->value(),'value' => $nakedValue->value(),@@ -192,7 +242,7 @@ class Service extends BaseModel} else {if (!$envs->has($nakedName->value())) {$envs->put($nakedName->value(), null);- if ($saveIt) {+ if ($isNew) {EnvironmentVariable::create(['key' => $nakedName->value(),'value' => null,@@ -205,15 +255,15 @@ class Service extends BaseModel}}} else {- $value = Str::of(replaceVariables(Str::of($value)));+ $variableName = Str::of(replaceVariables(Str::of($value)));$generatedValue = null;- if ($value->startsWith('SERVICE_USER')) {+ if ($variableName->startsWith('SERVICE_USER')) {$generatedValue = Str::random(10);- if ($saveIt) {- if (!$envs->has($value->value())) {- $envs->put($value->value(), $generatedValue);+ if ($isNew) {+ if (!$envs->has($variableName->value())) {+ $envs->put($variableName->value(), $generatedValue);EnvironmentVariable::create([- 'key' => $value->value(),+ 'key' => $variableName->value(),'value' => $generatedValue,'is_build_time' => false,'service_id' => $this->id,@@ -221,13 +271,13 @@ class Service extends BaseModel]);}}- } else if ($value->startsWith('SERVICE_PASSWORD')) {+ } else if ($variableName->startsWith('SERVICE_PASSWORD')) {$generatedValue = Str::password(symbols: false);- if ($saveIt) {- if (!$envs->has($value->value())) {- $envs->put($value->value(), $generatedValue);+ if ($isNew) {+ if (!$envs->has($variableName->value())) {+ $envs->put($variableName->value(), $generatedValue);EnvironmentVariable::create([- 'key' => $value->value(),+ 'key' => $variableName->value(),'value' => $generatedValue,'is_build_time' => false,'service_id' => $this->id,@@ -235,28 +285,74 @@ class Service extends BaseModel]);}}+ } else if ($variableName->startsWith('SERVICE_FQDN')) {+ if ($fqdn) {+ $environments = collect(data_get($service, 'environment'));+ $environments = $environments->map(function ($envValue) use ($value, $fqdn) {+ $envValue = Str::of($envValue)->replace($value, $fqdn);+ return $envValue->value();+ });+ $service['environment'] = $environments->toArray();+ }+ } else if ($variableName->startsWith('SERVICE_URL')) {+ if ($fqdn) {+ $url = Str::of($fqdn)->after('https://')->before('/');+ $environments = collect(data_get($service, 'environment'));+ $environments = $environments->map(function ($envValue) use ($value, $url) {+ $envValue = Str::of($envValue)->replace($value, $url);+ return $envValue->value();+ });+ $service['environment'] = $environments->toArray();+ }}}}-+ if ($this->server->proxyType() === ProxyTypes::TRAEFIK_V2->value) {+ $labels = collect(data_get($service, 'labels', []));+ $labels = collect([]);+ $labels = $labels->merge(defaultLabels($this->id, $container_name, type: 'service'));+ if (!$isDatabase) {+ if ($fqdn) {+ $labels = $labels->merge(fqdnLabelsForTraefik($fqdn, $container_name, true));+ }+ }+ data_set($service, 'labels', $labels->toArray());+ }data_forget($service, 'is_database');+ data_set($service, 'restart', RESTART_MODE);+ data_set($service, 'container_name', $container_name);data_forget($service, 'documentation');return $service;});- data_set($services, 'volumes', $composeVolumes->toArray());- data_set($services, 'networks', $composeNetworks->toArray());- $this->docker_compose = Yaml::parse($services);- // $compose = Str::of(Yaml::dump($services, 10, 2));- // TODO: Replace SERVICE_FQDN_* with the actual FQDN- // TODO: Replace SERVICE_URL_*+ // $services = $services->map(function ($service, $serviceName) {+ // $dependsOn = collect(data_get($service, 'depends_on', []));+ // $dependsOn = $dependsOn->map(function ($value) {+ // return "$value-{$this->uuid}";+ // });+ // data_set($service, 'depends_on', $dependsOn->toArray());+ // return $service;+ // });+ // $renamedServices = collect([]);+ // collect($services)->map(function ($service, $serviceName) use ($renamedServices) {+ // $newServiceName = "$serviceName-$this->uuid";+ // $renamedServices->put($newServiceName, $service);+ // });+ $finalServices = [+ 'version' => $dockerComposeVersion,+ 'services' => $services->toArray(),+ 'volumes' => $composeVolumes->toArray(),+ 'networks' => $composeNetworks->toArray(),+ ];+ $this->docker_compose = Yaml::dump($finalServices, 10, 2);+ $this->save();$shouldBeDefined = collect(['envs' => $envs,'volumes' => $volumes,'ports' => $ports]);$parsedCompose = collect([- 'dockerCompose' => $services,+ 'dockerCompose' => $finalServices,'shouldBeDefined' => $shouldBeDefined]);return $parsedCompose;diff --git a/app/Models/StandaloneDocker.php b/app/Models/StandaloneDocker.phpindex ad401f12de..16d85d956f 100644--- a/app/Models/StandaloneDocker.php+++ b/app/Models/StandaloneDocker.php@@ -21,9 +21,9 @@ class StandaloneDocker extends BaseModelreturn $this->belongsTo(Server::class);}- public function service()+ public function services(){- return $this->belongsTo(Service::class, 'destination');+ return $this->morphMany(Service::class, 'destination');}public function attachedTo()diff --git a/app/Traits/ExecuteRemoteCommand.php b/app/Traits/ExecuteRemoteCommand.phpindex 67761a69d0..1244fde285 100644--- a/app/Traits/ExecuteRemoteCommand.php+++ b/app/Traits/ExecuteRemoteCommand.php@@ -36,7 +36,7 @@ trait ExecuteRemoteCommand$this->save = data_get($single_command, 'save');$remote_command = generateSshCommand($this->server, $command);- $process = Process::timeout(3600)->idleTimeout(3600)->start($remote_command, function (string $type, string $output) use ($command, $hidden) {+ $process = Process::timeout(3600)->idleTimeout(3600)->start($remote_command, function (string $type, string $output) use ($command, $hidden) {$output = Str::of($output)->trim();$new_log_entry = ['command' => $command,diff --git a/app/View/Components/Status/Index.php b/app/View/Components/Status/Index.phpnew file mode 100644index 0000000000..a7128c7fd0--- /dev/null+++ b/app/View/Components/Status/Index.php@@ -0,0 +1,28 @@+<?php++namespace App\View\Components\Status;++use Closure;+use Illuminate\Contracts\View\View;+use Illuminate\View\Component;++class Index extends Component+{+ /**+ * Create a new component instance.+ */+ public function __construct(+ public string $status = 'exited',+ )+ {+ //+ }++ /**+ * Get the view / contents that represent the component.+ */+ public function render(): View|Closure|string+ {+ return view('components.status.index');+ }+}diff --git a/app/View/Components/Status/Services.php b/app/View/Components/Status/Services.phpnew file mode 100644index 0000000000..0db5e1ac39--- /dev/null+++ b/app/View/Components/Status/Services.php@@ -0,0 +1,53 @@+<?php++namespace App\View\Components\Status;++use App\Models\Service;+use Closure;+use Illuminate\Contracts\View\View;+use Illuminate\View\Component;++class Services extends Component+{+ /**+ * Create a new component instance.+ */+ public function __construct(+ public Service $service,+ public string $complexStatus = 'exited',+ ) {+ $foundRunning = false;+ $isDegraded = false;+ $applications = $service->applications;+ $databases = $service->databases;+ foreach ($applications as $application) {+ if ($application->status === 'running') {+ $foundRunning = true;+ } else {+ $isDegraded = true;+ }+ }+ foreach ($databases as $database) {+ if ($database->status === 'running') {+ $foundRunning = true;+ } else {+ $isDegraded = true;+ }+ }+ if ($foundRunning && !$isDegraded) {+ $this->complexStatus = 'running';+ } else if ($foundRunning && $isDegraded) {+ $this->complexStatus = 'degraded';+ } else if (!$foundRunning && $isDegraded) {+ $this->complexStatus = 'exited';+ }+ }++ /**+ * Get the view / contents that represent the component.+ */+ public function render(): View|Closure|string+ {+ return view('components.status.services');+ }+}diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.phpindex 7925bbacc5..123e9fb9f2 100644--- a/bootstrap/helpers/docker.php+++ b/bootstrap/helpers/docker.php@@ -130,13 +130,14 @@ function get_port_from_dockerfile($dockerfile): intreturn 80;}-function defaultLabels($id, $name, $pull_request_id = 0)+function defaultLabels($id, $name, $pull_request_id = 0, string $type = 'application'){+ ray($type);$labels = collect([]);$labels->push('coolify.managed=true');$labels->push('coolify.version=' . config('version'));- $labels->push('coolify.applicationId=' . $id);- $labels->push('coolify.type=application');+ $labels->push("coolify." . $type . "Id=" . $id);+ $labels->push("coolify.type=$type");$labels->push('coolify.name=' . $name);if ($pull_request_id !== 0) {$labels->push('coolify.pullRequestId=' . $pull_request_id);diff --git a/bootstrap/helpers/remoteProcess.php b/bootstrap/helpers/remoteProcess.phpindex 7bf1947114..7936ca62bf 100644--- a/bootstrap/helpers/remoteProcess.php+++ b/bootstrap/helpers/remoteProcess.php@@ -33,7 +33,6 @@ function remote_process(throw new \Exception("User is not part of the team that owns this server");}}-return resolve(PrepareCoolifyTask::class, ['remoteProcessArgs' => new CoolifyTaskArgs(server_uuid: $server->uuid,diff --git a/bootstrap/helpers/services.php b/bootstrap/helpers/services.phpindex eebeae72c6..4448d08acf 100644--- a/bootstrap/helpers/services.php+++ b/bootstrap/helpers/services.php@@ -13,188 +13,188 @@ use Illuminate\Support\Str;# SERVICE_PASSWORD_*: Generated by your application, password (encrypted)-function generateServiceFromTemplate(Service $service)-{- // ray()->clearAll();- $template = data_get($service, 'docker_compose_raw');- $network = data_get($service, 'destination.network');- $yaml = Yaml::parse($template);-- $services = $service->parse();- $volumes = collect(data_get($yaml, 'volumes', []));- $composeVolumes = collect([]);- $env = collect([]);- $ports = collect([]);-- foreach ($services as $serviceName => $service) {- $container_name = generateApplicationContainerName($application);- $domain = data_get($application, "service_configurations.{$serviceName}.fqdn", null);- if ($domain === '') {- $domain = null;- }- data_forget($service, 'documentation');- // Some default things- data_set($service, 'restart', RESTART_MODE);- data_set($service, 'container_name', $container_name);- $healthcheck = data_get($service, 'healthcheck');- if (is_null($healthcheck)) {- $healthcheck = [- 'test' => [- 'CMD-SHELL',- 'exit 0'- ],- 'interval' => $application->health_check_interval . 's',- 'timeout' => $application->health_check_timeout . 's',- 'retries' => $application->health_check_retries,- 'start_period' => $application->health_check_start_period . 's'- ];- data_set($service, 'healthcheck', $healthcheck);- }- // Labels- $server = data_get($application, 'destination.server');- if ($server->proxyType() === ProxyTypes::TRAEFIK_V2->value) {- $labels = collect(data_get($service, 'labels', []));- $labels = collect([]);- $labels = $labels->merge(defaultLabels($application->id, $container_name));- if (!data_get($service, 'is_database')) {- if ($domain) {- $labels = $labels->merge(fqdnLabelsForTraefik($domain, $container_name, $application->settings->is_force_https_enabled));- }-- }- data_set($service, 'labels', $labels->toArray());- }-- data_forget($service, 'is_database');-- // Add volumes to the volumes collection if they don't already exist- $serviceVolumes = collect(data_get($service, 'volumes', []));- if ($serviceVolumes->count() > 0) {- foreach ($serviceVolumes as $volume) {- $volumeName = Str::before($volume, ':');- $volumePath = Str::after($volume, ':');- if (Str::startsWith($volumeName, '/')) {- continue;- }- $volumeExists = $volumes->contains(function ($_, $key) use ($volumeName) {- return $key == $volumeName;- });- if ($volumeExists) {- ray('Volume already exists');- } else {- $composeVolumes->put($volumeName, null);- $volumes->put($volumeName, $volumePath);- }- }- }- // Add networks to the networks collection if they don't already exist- $serviceNetworks = collect(data_get($service, 'networks', []));- $networkExists = $serviceNetworks->contains(function ($_, $key) use ($network) {- return $key == $network;- });- if (is_null($networkExists) || !$networkExists) {- $serviceNetworks->push($network);- }- data_set($service, 'networks', $serviceNetworks->toArray());- data_set($yaml, "services.{$serviceName}", $service);-- // Get variables from the service that does not start with SERVICE_*- $serviceVariables = collect(data_get($service, 'environment', []));- foreach ($serviceVariables as $variable) {- // $key = Str::before($variable, '=');- $value = Str::after($variable, '=');- if (!Str::startsWith($value, '$SERVICE_') && !Str::startsWith($value, '${SERVICE_') && Str::startsWith($value, '$')) {- if (Str::of($value)->contains(':')) {- $nakedName = replaceVariables(Str::of($value)->before(':'));- $nakedValue = replaceVariables(Str::of($value)->after(':'));- }- if (Str::of($value)->contains('-')) {- $nakedName = replaceVariables(Str::of($value)->before('-'));- $nakedValue = replaceVariables(Str::of($value)->after('-'));- }- if (Str::of($value)->contains('+')) {- $nakedName = replaceVariables(Str::of($value)->before('+'));- $nakedValue = replaceVariables(Str::of($value)->after('+'));- }- if ($nakedValue->startsWith('-')) {- $nakedValue = Str::of($nakedValue)->after('-');- }- if ($nakedValue->startsWith('+')) {- $nakedValue = Str::of($nakedValue)->after('+');- }- if (!$env->contains("{$nakedName->value()}={$nakedValue->value()}")) {- $env->push("$nakedName=$nakedValue");- }- }- }- // Get ports from the service- $servicePorts = collect(data_get($service, 'ports', []));- foreach ($servicePorts as $port) {- $port = Str::of($port)->before(':');- $ports->push($port);- }- }- data_set($yaml, 'networks', [- $network => [- 'name' => $network- ],- ]);- data_set($yaml, 'volumes', $composeVolumes->toArray());- $compose = Str::of(Yaml::dump($yaml, 10, 2));-- // Replace SERVICE_FQDN_* with the actual FQDN- preg_match_all(collectRegex('SERVICE_FQDN_'), $compose, $fqdns);- $fqdns = collect($fqdns)->flatten()->unique()->values();- $generatedFqdns = collect([]);- foreach ($fqdns as $fqdn) {- $generatedFqdns->put("$fqdn", data_get($application, 'fqdn'));- }-- // Replace SERVICE_URL_*- preg_match_all(collectRegex('SERVICE_URL_'), $compose, $urls);- $urls = collect($urls)->flatten()->unique()->values();- $generatedUrls = collect([]);- foreach ($urls as $url) {- $generatedUrls->put("$url", data_get($application, 'url'));- }-- // Generate SERVICE_USER_*- preg_match_all(collectRegex('SERVICE_USER_'), $compose, $users);- $users = collect($users)->flatten()->unique()->values();- $generatedUsers = collect([]);- foreach ($users as $user) {- $generatedUsers->put("$user", Str::random(10));- }-- // Generate SERVICE_PASSWORD_*- preg_match_all(collectRegex('SERVICE_PASSWORD_'), $compose, $passwords);- $passwords = collect($passwords)->flatten()->unique()->values();- $generatedPasswords = collect([]);- foreach ($passwords as $password) {- $generatedPasswords->put("$password", Str::password(symbols: false));- }-- // Save .env file- foreach ($generatedFqdns as $key => $value) {- $env->push("$key=$value");- }- foreach ($generatedUrls as $key => $value) {- $env->push("$key=$value");- }- foreach ($generatedUsers as $key => $value) {- $env->push("$key=$value");- }- foreach ($generatedPasswords as $key => $value) {- $env->push("$key=$value");- }- return [- 'dockercompose' => $compose,- 'yaml' => Yaml::parse($compose),- 'envs' => $env,- 'volumes' => $volumes,- 'ports' => $ports->values(),- ];-}+// function generateServiceFromTemplate(Service $service)+// {+// // ray()->clearAll();+// $template = data_get($service, 'docker_compose_raw');+// $network = data_get($service, 'destination.network');+// $yaml = Yaml::parse($template);++// $services = $service->parse();+// $volumes = collect(data_get($yaml, 'volumes', []));+// $composeVolumes = collect([]);+// $env = collect([]);+// $ports = collect([]);++// foreach ($services as $serviceName => $service) {+// $container_name = generateApplicationContainerName($application);+// $domain = data_get($application, "service_configurations.{$serviceName}.fqdn", null);+// if ($domain === '') {+// $domain = null;+// }+// data_forget($service, 'documentation');+// // Some default things+// data_set($service, 'restart', RESTART_MODE);+// data_set($service, 'container_name', $container_name);+// $healthcheck = data_get($service, 'healthcheck');+// if (is_null($healthcheck)) {+// $healthcheck = [+// 'test' => [+// 'CMD-SHELL',+// 'exit 0'+// ],+// 'interval' => $application->health_check_interval . 's',+// 'timeout' => $application->health_check_timeout . 's',+// 'retries' => $application->health_check_retries,+// 'start_period' => $application->health_check_start_period . 's'+// ];+// data_set($service, 'healthcheck', $healthcheck);+// }+// // Labels+// $server = data_get($application, 'destination.server');+// if ($server->proxyType() === ProxyTypes::TRAEFIK_V2->value) {+// $labels = collect(data_get($service, 'labels', []));+// $labels = collect([]);+// $labels = $labels->merge(defaultLabels($application->id, $container_name));+// if (!data_get($service, 'is_database')) {+// if ($domain) {+// $labels = $labels->merge(fqdnLabelsForTraefik($domain, $container_name, $application->settings->is_force_https_enabled));+// }++// }+// data_set($service, 'labels', $labels->toArray());+// }++// data_forget($service, 'is_database');++// // Add volumes to the volumes collection if they don't already exist+// $serviceVolumes = collect(data_get($service, 'volumes', []));+// if ($serviceVolumes->count() > 0) {+// foreach ($serviceVolumes as $volume) {+// $volumeName = Str::before($volume, ':');+// $volumePath = Str::after($volume, ':');+// if (Str::startsWith($volumeName, '/')) {+// continue;+// }+// $volumeExists = $volumes->contains(function ($_, $key) use ($volumeName) {+// return $key == $volumeName;+// });+// if ($volumeExists) {+// ray('Volume already exists');+// } else {+// $composeVolumes->put($volumeName, null);+// $volumes->put($volumeName, $volumePath);+// }+// }+// }+// // Add networks to the networks collection if they don't already exist+// $serviceNetworks = collect(data_get($service, 'networks', []));+// $networkExists = $serviceNetworks->contains(function ($_, $key) use ($network) {+// return $key == $network;+// });+// if (is_null($networkExists) || !$networkExists) {+// $serviceNetworks->push($network);+// }+// data_set($service, 'networks', $serviceNetworks->toArray());+// data_set($yaml, "services.{$serviceName}", $service);++// // Get variables from the service that does not start with SERVICE_*+// $serviceVariables = collect(data_get($service, 'environment', []));+// foreach ($serviceVariables as $variable) {+// // $key = Str::before($variable, '=');+// $value = Str::after($variable, '=');+// if (!Str::startsWith($value, '$SERVICE_') && !Str::startsWith($value, '${SERVICE_') && Str::startsWith($value, '$')) {+// if (Str::of($value)->contains(':')) {+// $nakedName = replaceVariables(Str::of($value)->before(':'));+// $nakedValue = replaceVariables(Str::of($value)->after(':'));+// }+// if (Str::of($value)->contains('-')) {+// $nakedName = replaceVariables(Str::of($value)->before('-'));+// $nakedValue = replaceVariables(Str::of($value)->after('-'));+// }+// if (Str::of($value)->contains('+')) {+// $nakedName = replaceVariables(Str::of($value)->before('+'));+// $nakedValue = replaceVariables(Str::of($value)->after('+'));+// }+// if ($nakedValue->startsWith('-')) {+// $nakedValue = Str::of($nakedValue)->after('-');+// }+// if ($nakedValue->startsWith('+')) {+// $nakedValue = Str::of($nakedValue)->after('+');+// }+// if (!$env->contains("{$nakedName->value()}={$nakedValue->value()}")) {+// $env->push("$nakedName=$nakedValue");+// }+// }+// }+// // Get ports from the service+// $servicePorts = collect(data_get($service, 'ports', []));+// foreach ($servicePorts as $port) {+// $port = Str::of($port)->before(':');+// $ports->push($port);+// }+// }+// data_set($yaml, 'networks', [+// $network => [+// 'name' => $network+// ],+// ]);+// data_set($yaml, 'volumes', $composeVolumes->toArray());+// $compose = Str::of(Yaml::dump($yaml, 10, 2));++// // Replace SERVICE_FQDN_* with the actual FQDN+// preg_match_all(collectRegex('SERVICE_FQDN_'), $compose, $fqdns);+// $fqdns = collect($fqdns)->flatten()->unique()->values();+// $generatedFqdns = collect([]);+// foreach ($fqdns as $fqdn) {+// $generatedFqdns->put("$fqdn", data_get($application, 'fqdn'));+// }++// // Replace SERVICE_URL_*+// preg_match_all(collectRegex('SERVICE_URL_'), $compose, $urls);+// $urls = collect($urls)->flatten()->unique()->values();+// $generatedUrls = collect([]);+// foreach ($urls as $url) {+// $generatedUrls->put("$url", data_get($application, 'url'));+// }++// // Generate SERVICE_USER_*+// preg_match_all(collectRegex('SERVICE_USER_'), $compose, $users);+// $users = collect($users)->flatten()->unique()->values();+// $generatedUsers = collect([]);+// foreach ($users as $user) {+// $generatedUsers->put("$user", Str::random(10));+// }++// // Generate SERVICE_PASSWORD_*+// preg_match_all(collectRegex('SERVICE_PASSWORD_'), $compose, $passwords);+// $passwords = collect($passwords)->flatten()->unique()->values();+// $generatedPasswords = collect([]);+// foreach ($passwords as $password) {+// $generatedPasswords->put("$password", Str::password(symbols: false));+// }++// // Save .env file+// foreach ($generatedFqdns as $key => $value) {+// $env->push("$key=$value");+// }+// foreach ($generatedUrls as $key => $value) {+// $env->push("$key=$value");+// }+// foreach ($generatedUsers as $key => $value) {+// $env->push("$key=$value");+// }+// foreach ($generatedPasswords as $key => $value) {+// $env->push("$key=$value");+// }+// return [+// 'dockercompose' => $compose,+// 'yaml' => Yaml::parse($compose),+// 'envs' => $env,+// 'volumes' => $volumes,+// 'ports' => $ports->values(),+// ];+// }function replaceRegex(?string $name = null){diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.phpindex ce41d19db5..11ded05428 100644--- a/bootstrap/helpers/shared.php+++ b/bootstrap/helpers/shared.php@@ -21,23 +21,29 @@ use Poliander\Cron\CronExpression;use Visus\Cuid2\Cuid2;use phpseclib3\Crypt\RSA;+function base_configuration_dir(): string+{+ return '/data/coolify';+}function application_configuration_dir(): string{- return '/data/coolify/applications';+ return base_configuration_dir() . "/applications";+}+function service_configuration_dir(): string+{+ return base_configuration_dir() . "/services";}-function database_configuration_dir(): string{- return '/data/coolify/databases';+ return base_configuration_dir() . "/databases";}function database_proxy_dir($uuid): string{- return "/data/coolify/databases/$uuid/proxy";+ return base_configuration_dir() . "/databases/$uuid/proxy";}-function backup_dir(): string{- return '/data/coolify/backups';+ return base_configuration_dir() . "/backups";}function generate_readme_file(string $name, string $updated_at): stringdiff --git a/database/migrations/2023_03_27_083621_create_services_table.php b/database/migrations/2023_03_27_083621_create_services_table.phpindex 12bb77b1ba..a363d21197 100644--- a/database/migrations/2023_03_27_083621_create_services_table.php+++ b/database/migrations/2023_03_27_083621_create_services_table.php@@ -16,8 +16,7 @@ return new class extends Migration$table->string('uuid')->unique();$table->string('name');- $table->morphs('destination');-+ $table->foreignId('server_id')->nullable();$table->foreignId('environment_id');$table->timestamps();});diff --git a/database/migrations/2023_09_20_082733_create_service_databases_table.php b/database/migrations/2023_09_20_082733_create_service_databases_table.phpindex 8418883499..0b7a06dd94 100644--- a/database/migrations/2023_09_20_082733_create_service_databases_table.php+++ b/database/migrations/2023_09_20_082733_create_service_databases_table.php@@ -16,6 +16,8 @@ return new class extends Migration$table->string('uuid')->unique();$table->string('name');+ $table->string('status')->default('exited');+$table->string('ports_exposes')->nullable();$table->string('ports_mappings')->nullable();diff --git a/resources/views/components/resources/breadcrumbs.blade.php b/resources/views/components/resources/breadcrumbs.blade.phpindex cb18785814..ae46964a67 100644--- a/resources/views/components/resources/breadcrumbs.blade.php+++ b/resources/views/components/resources/breadcrumbs.blade.php@@ -38,12 +38,10 @@</svg></div></li>- @if ($resource->status === 'running')- <x-status.running />- @elseif($resource->status === 'restarting')- <x-status.restarting />+ @if ($resource->getMorphClass() == 'App\Models\Service')+ <x-status.services :service="$resource" />@else- <x-status.stopped />+ <x-status.index :status="$resource->status" />@endif</ol></nav>diff --git a/resources/views/components/status/degraded.blade.php b/resources/views/components/status/degraded.blade.phpnew file mode 100644index 0000000000..2220a6d0e3--- /dev/null+++ b/resources/views/components/status/degraded.blade.php@@ -0,0 +1,8 @@+@props([+ 'text' => 'Degraded',+])+<x-loading wire:loading.delay />+<div class="flex items-center gap-2" wire:loading.remove.delay.longer>+ <div class="badge badge-warning badge-xs"></div>+ <div class="text-xs font-medium tracking-wide text-warning">{{ $text }}</div>+</div>diff --git a/resources/views/components/status/index.blade.php b/resources/views/components/status/index.blade.phpnew file mode 100644index 0000000000..7848cee02c--- /dev/null+++ b/resources/views/components/status/index.blade.php@@ -0,0 +1,7 @@+@if ($status === 'running')+ <x-status.running />+@elseif($status === 'restarting')+ <x-status.restarting />+@else+ <x-status.stopped />+@endifdiff --git a/resources/views/components/status/services.blade.php b/resources/views/components/status/services.blade.phpnew file mode 100644index 0000000000..bafa2954e8--- /dev/null+++ b/resources/views/components/status/services.blade.php@@ -0,0 +1,9 @@+@if ($complexStatus === 'running')+ <x-status.running />+@elseif($complexStatus === 'restarting')+ <x-status.restarting />+@elseif($complexStatus === 'degraded')+ <x-status.degraded />+@else+ <x-status.stopped />+@endifdiff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.phpindex 5f00695837..e8f94ab64c 100644--- a/resources/views/livewire/project/application/general.blade.php+++ b/resources/views/livewire/project/application/general.blade.php@@ -12,40 +12,6 @@<x-forms.input id="application.name" label="Name" required /><x-forms.input id="application.description" label="Description" /></div>- @if ($services->count() === 0)- <div class="flex items-end gap-2">- <x-forms.input placeholder="https://coolify.io" id="application.fqdn" label="Domains"- helper="You can specify one domain with path or more with comma.<br><span class='text-helper'>Example</span>- http://app.coolify.io, https://cloud.coolify.io/dashboard<br>- http://app.coolify.io/api/v3" />- @if ($wildcard_domain)- @if ($global_wildcard_domain)- <x-forms.button wire:click="generateGlobalRandomDomain">Set Global Wildcard- </x-forms.button>- @endif- @if ($server_wildcard_domain)- <x-forms.button wire:click="generateServerRandomDomain">Set Server Wildcard- </x-forms.button>- @endif- @endif- </div>- <div class="flex items-end gap-2">- @if ($application->build_pack === 'dockerfile')- <x-forms.select disabled id="application.build_pack" label="Build Pack" required>- <option value="dockerfile">Dockerfile</option>- </x-forms.select>- @elseif ($application->build_pack === 'dockercompose')- <x-forms.select disabled id="application.build_pack" label="Build Pack" required>- <option selected value="dockercompose">Docker Compose</option>- </x-forms.select>- @else- <x-forms.select id="application.build_pack" label="Build Pack" required>- <option value="nixpacks">Nixpacks</option>- <option value="dockerfile">Dockerfile</option>- <option disabled value="dockercompose">Docker Compose</option>- </x-forms.select>- @endif-- </div>- @endif@if ($application->settings->is_static)<x-forms.select id="application.static_image" label="Static Image" required><option value="nginx:alpine">nginx:alpine</option>@@ -74,38 +40,17 @@@if ($application->dockerfile)<x-forms.textarea label="Dockerfile" id="application.dockerfile" rows="6"> </x-forms.textarea>@endif- @if ($services->count() > 0)- <h3>Services</h3>- @foreach ($services as $serviceName => $service)- @if (!data_get($service, 'is_database'))- <h4>{{ Str::headline($serviceName) }}</h4>- <div class="flex gap-2">- <x-forms.input id="service_configurations.{{ $serviceName }}.fqdn" label="FQDN">- </x-forms.input>- {{-- <x-forms.input id="service_configurations.{{ $serviceName }}.port"- label="{{ Str::headline($serviceName) }} Port">- </x-forms.input> --}}- </div>- @endif- @endforeach- <x-forms.textarea label="Docker Compose (Raw)" id="application.dockercompose_raw" rows="16">- </x-forms.textarea>- <x-forms.textarea readonly helper="Added all required fields" label="Docker Compose (Coolified)"- id="application.dockercompose" rows="6">- </x-forms.textarea>- @else- <h3>Network</h3>- <div class="flex flex-col gap-2 xl:flex-row">- @if ($application->settings->is_static)- <x-forms.input id="application.ports_exposes" label="Ports Exposes" readonly />- @else- <x-forms.input placeholder="3000,3001" id="application.ports_exposes" label="Ports Exposes"- required helper="A comma separated list of ports you would like to expose for the proxy." />- @endif- <x-forms.input placeholder="3000:3000" id="application.ports_mappings" label="Ports Mappings"- helper="A comma separated list of ports you would like to map to the host system. Useful when you do not want to use domains.<br><span class='inline-block font-bold text-warning'>Example</span>3000:3000,3002:3002" />- </div>- @endif+ <h3>Network</h3>+ <div class="flex flex-col gap-2 xl:flex-row">+ @if ($application->settings->is_static)+ <x-forms.input id="application.ports_exposes" label="Ports Exposes" readonly />+ @else+ <x-forms.input placeholder="3000,3001" id="application.ports_exposes" label="Ports Exposes" required+ helper="A comma separated list of ports you would like to expose for the proxy." />+ @endif+ <x-forms.input placeholder="3000:3000" id="application.ports_mappings" label="Ports Mappings"+ helper="A comma separated list of ports you would like to map to the host system. Useful when you do not want to use domains.<br><span class='inline-block font-bold text-warning'>Example</span>3000:3000,3002:3002" />+ </div></div><h3>Advanced</h3><div class="flex flex-col">diff --git a/resources/views/livewire/project/service/index.blade.php b/resources/views/livewire/project/service/index.blade.phpindex 51007cd967..26d73bb3d3 100644--- a/resources/views/livewire/project/service/index.blade.php+++ b/resources/views/livewire/project/service/index.blade.php@@ -1,16 +1,26 @@-<div>+<div x-init="$wire.check_status"><h1>Configuration</h1>+ <x-resources.breadcrumbs :resource="$service" :parameters="$parameters" /><h3>Applications</h3>@foreach ($service->applications as $application)+ <form wire:submit.prevent='submit'><p>{{ $application->name }}</p>+ <p>{{ $application->status }}</p>+ <x-forms.input id="services.{{$application->name}}.fqdn"></x-forms.input>+ <x-forms.button type="submit">Save</x-forms.button>+ </form>@endforeach<h3>Databases</h3>@foreach ($service->databases as $database)<p>{{ $database->name }}</p>+ <p>{{ $database->status }}</p>@endforeach<h3>Variables</h3>@foreach ($service->environment_variables as $variable)<p>{{ $variable->key }}={{ $variable->value }}</p>@endforeach-+ <x-forms.button wire:click='deploy'>Deploy</x-forms.button>+ <div class="container w-full py-10 mx-auto">+ <livewire:activity-monitor header="Service Startup Logs" />+ </div></div>diff --git a/routes/web.php b/routes/web.phpindex 665f5d3ee2..82c760a083 100644--- a/routes/web.php+++ b/routes/web.php@@ -7,7 +7,7 @@ use App\Http\Controllers\MagicController;use App\Http\Controllers\ProjectController;use App\Http\Controllers\ServerController;use App\Http\Livewire\Boarding\Index as BoardingIndex;-use App\Http\Livewire\Service\Index as ServiceIndex;+use App\Http\Livewire\Project\Service\Index as ServiceIndex;use App\Http\Livewire\Dashboard;use App\Http\Livewire\Server\All;use App\Http\Livewire\Server\Show;@@ -22,7 +22,6 @@ use App\Models\SwarmDocker;use Illuminate\Http\Request;use Illuminate\Support\Facades\Password;use Illuminate\Support\Facades\Route;-use Illuminate\Support\Facades\Storage;use Illuminate\Support\Str;use Laravel\Fortify\Contracts\FailedPasswordResetLinkRequestResponse;use Laravel\Fortify\Contracts\SuccessfulPasswordResetLinkRequestResponse;