Skip to content

Commit b8bcfb0

Browse files
committed
Merge branch 'next' of https://github.com/coollabsio/coolify into feat/open-version-new-tab
2 parents 7d1f6b9 + d031911 commit b8bcfb0

34 files changed

+542
-67
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Actions\Application;
4+
5+
use App\Models\Application;
6+
use Lorisleiva\Actions\Concerns\AsAction;
7+
8+
class GenerateConfig
9+
{
10+
use AsAction;
11+
12+
public function handle(Application $application, bool $is_json = false)
13+
{
14+
ray()->clearAll();
15+
return $application->generateConfig(is_json: $is_json);
16+
}
17+
}

app/Livewire/Project/Application/General.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Livewire\Project\Application;
44

5+
use App\Actions\Application\GenerateConfig;
56
use App\Models\Application;
67
use Illuminate\Support\Collection;
78
use Livewire\Component;
@@ -413,4 +414,16 @@ public function submit($showToaster = true)
413414
$this->dispatch('configurationChanged');
414415
}
415416
}
417+
public function downloadConfig()
418+
{
419+
$config = GenerateConfig::run($this->application, true);
420+
$fileName = str($this->application->name)->slug()->append('_config.json');
421+
422+
return response()->streamDownload(function () use ($config) {
423+
echo $config;
424+
}, $fileName, [
425+
'Content-Type' => 'application/json',
426+
'Content-Disposition' => 'attachment; filename=' . $fileName,
427+
]);
428+
}
416429
}

app/Livewire/Project/New/PublicGitRepository.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ class PublicGitRepository extends Component
3131

3232
public bool $isStatic = false;
3333

34+
public bool $checkCoolifyConfig = true;
35+
3436
public ?string $publish_directory = null;
3537

3638
// In case of docker compose
37-
public ?string $base_directory = null;
39+
public string $base_directory = '/';
3840

3941
public ?string $docker_compose_location = '/docker-compose.yaml';
4042
// End of docker compose
@@ -97,6 +99,7 @@ public function updatedBaseDirectory()
9799
$this->base_directory = '/'.$this->base_directory;
98100
}
99101
}
102+
100103
}
101104

102105
public function updatedDockerComposeLocation()
@@ -275,6 +278,7 @@ public function submit()
275278
'destination_id' => $destination->id,
276279
'destination_type' => $destination_class,
277280
'build_pack' => $this->build_pack,
281+
'base_directory' => $this->base_directory,
278282
];
279283
} else {
280284
$application_init = [
@@ -289,6 +293,7 @@ public function submit()
289293
'source_id' => $this->git_source->id,
290294
'source_type' => $this->git_source->getMorphClass(),
291295
'build_pack' => $this->build_pack,
296+
'base_directory' => $this->base_directory,
292297
];
293298
}
294299

@@ -303,11 +308,15 @@ public function submit()
303308

304309
$application->settings->is_static = $this->isStatic;
305310
$application->settings->save();
306-
307311
$fqdn = generateFqdn($destination->server, $application->uuid);
308312
$application->fqdn = $fqdn;
309313
$application->save();
310-
314+
if ($this->checkCoolifyConfig) {
315+
// $config = loadConfigFromGit($this->repository_url, $this->git_branch, $this->base_directory, $this->query['server_id'], auth()->user()->currentTeam()->id);
316+
// if ($config) {
317+
// $application->setConfig($config);
318+
// }
319+
}
311320
return redirect()->route('project.application.configuration', [
312321
'application_uuid' => $application->uuid,
313322
'environment_name' => $environment->name,

app/Livewire/Project/New/Select.php

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Livewire\Project\Shared;
4+
5+
use App\Models\Application;
6+
use Livewire\Component;
7+
8+
class UploadConfig extends Component
9+
{
10+
public $config;
11+
public $applicationId;
12+
public function mount() {
13+
if (isDev()) {
14+
$this->config = '{
15+
"build_pack": "nixpacks",
16+
"base_directory": "/nodejs",
17+
"publish_directory": "/",
18+
"ports_exposes": "3000",
19+
"settings": {
20+
"is_static": false
21+
}
22+
}';
23+
}
24+
}
25+
public function uploadConfig()
26+
{
27+
try {
28+
$application = Application::findOrFail($this->applicationId);
29+
$application->setConfig($this->config);
30+
$this->dispatch('success', 'Application settings updated');
31+
} catch (\Exception $e) {
32+
$this->dispatch('error', $e->getMessage());
33+
return;
34+
}
35+
36+
}
37+
public function render()
38+
{
39+
return view('livewire.project.shared.upload-config');
40+
}
41+
}

app/Models/Application.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Process\InvokedProcess;
1010
use Illuminate\Support\Collection;
1111
use Illuminate\Support\Facades\Process;
12+
use Illuminate\Support\Facades\Validator;
1213
use Illuminate\Support\Str;
1314
use OpenApi\Attributes as OA;
1415
use RuntimeException;
@@ -1427,4 +1428,67 @@ public function getMetrics(int $mins = 5)
14271428
return $parsedCollection->toArray();
14281429
}
14291430
}
1431+
1432+
public function generateConfig($is_json = false)
1433+
{
1434+
$config = collect([]);
1435+
if ($this->build_pack = 'nixpacks') {
1436+
$config = collect([
1437+
'build_pack' => 'nixpacks',
1438+
'docker_registry_image_name' => $this->docker_registry_image_name,
1439+
'docker_registry_image_tag' => $this->docker_registry_image_tag,
1440+
'install_command' => $this->install_command,
1441+
'build_command' => $this->build_command,
1442+
'start_command' => $this->start_command,
1443+
'base_directory' => $this->base_directory,
1444+
'publish_directory' => $this->publish_directory,
1445+
'custom_docker_run_options' => $this->custom_docker_run_options,
1446+
'ports_exposes' => $this->ports_exposes,
1447+
'ports_mappings' => $this->ports_mapping,
1448+
'settings' => collect([
1449+
'is_static' => $this->settings->is_static,
1450+
]),
1451+
]);
1452+
}
1453+
$config = $config->filter(function ($value) {
1454+
return str($value)->isNotEmpty();
1455+
});
1456+
if ($is_json) {
1457+
return json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
1458+
}
1459+
1460+
return $config;
1461+
}
1462+
public function setConfig($config) {
1463+
1464+
$config = $config;
1465+
$validator = Validator::make(['config' => $config], [
1466+
'config' => 'required|json',
1467+
]);
1468+
if ($validator->fails()) {
1469+
throw new \Exception('Invalid JSON format');
1470+
}
1471+
$config = json_decode($config, true);
1472+
1473+
$deepValidator = Validator::make(['config' => $config], [
1474+
'config.build_pack' => 'required|string',
1475+
'config.base_directory' => 'required|string',
1476+
'config.publish_directory' => 'required|string',
1477+
'config.ports_exposes' => 'required|string',
1478+
'config.settings.is_static' => 'required|boolean',
1479+
]);
1480+
if ($deepValidator->fails()) {
1481+
throw new \Exception('Invalid data');
1482+
}
1483+
$config = $deepValidator->validated()['config'];
1484+
1485+
try {
1486+
$settings = data_get($config, 'settings', []);
1487+
data_forget($config, 'settings');
1488+
$this->update($config);
1489+
$this->settings()->update($settings);
1490+
} catch (\Exception $e) {
1491+
throw new \Exception('Failed to update application settings');
1492+
}
1493+
}
14301494
}

bootstrap/helpers/docker.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,12 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
332332
if (preg_match('/traefik\.http\.middlewares\.(.*?)(\.|$)/', $item, $matches)) {
333333
return $matches[1];
334334
}
335+
if (preg_match('/coolify\.traefik\.middlewares=(.*)/', $item, $matches)) {
336+
return explode(',', $matches[1]);
337+
}
335338
return null;
336-
})->filter()
339+
})->flatten()
340+
->filter()
337341
->unique();
338342
}
339343
foreach ($domains as $loop => $domain) {

bootstrap/helpers/shared.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3981,3 +3981,31 @@ function instanceSettings()
39813981
{
39823982
return InstanceSettings::get();
39833983
}
3984+
3985+
function loadConfigFromGit(string $repository, string $branch, string $base_directory, int $server_id, int $team_id) {
3986+
3987+
$server = Server::find($server_id)->where('team_id', $team_id)->first();
3988+
if (!$server) {
3989+
return;
3990+
}
3991+
$uuid = new Cuid2();
3992+
$cloneCommand = "git clone --no-checkout -b $branch $repository .";
3993+
$workdir = rtrim($base_directory, '/');
3994+
$fileList = collect([".$workdir/coolify.json"]);
3995+
$commands = collect([
3996+
"rm -rf /tmp/{$uuid}",
3997+
"mkdir -p /tmp/{$uuid}",
3998+
"cd /tmp/{$uuid}",
3999+
$cloneCommand,
4000+
'git sparse-checkout init --cone',
4001+
"git sparse-checkout set {$fileList->implode(' ')}",
4002+
'git read-tree -mu HEAD',
4003+
"cat .$workdir/coolify.json",
4004+
'rm -rf /tmp/{$uuid}',
4005+
]);
4006+
try {
4007+
return instant_remote_process($commands, $server);
4008+
} catch (\Exception $e) {
4009+
// continue
4010+
}
4011+
}

config/sentry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
// The release version of your application
99
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
10-
'release' => '4.0.0-beta.357',
10+
'release' => '4.0.0-beta.358',
1111
// When left empty or `null` the Laravel environment will be used
1212
'environment' => config('app.env'),
1313

config/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
return '4.0.0-beta.357';
3+
return '4.0.0-beta.358';

0 commit comments

Comments
 (0)