Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed May 25, 2023
1 parent 5a1a332 commit f766600
Show file tree
Hide file tree
Showing 41 changed files with 151 additions and 79 deletions.
4 changes: 3 additions & 1 deletion app/Http/Livewire/Project/Application/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function deploy(bool $force = false)

public function stop()
{
dispatch(new ContainerStopJob($this->application->id, $this->destination->server));
instant_remote_process(["docker rm -f {$this->application->uuid}"], $this->application->destination->server);
$this->application->status = get_container_status(server: $this->application->destination->server, container_id: $this->application->uuid);
$this->application->save();
}
}
3 changes: 3 additions & 0 deletions app/Http/Livewire/Project/Application/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class Status extends Component
{
public Application $application;

protected $listeners = [
'applicationStatusChanged' => 'pollingStatus',
];
public function pollingStatus()
{
$this->application->refresh();
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Livewire/Server/PrivateKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Storage;
use Livewire\Component;
use LocalStorage;

class PrivateKey extends Component
{
Expand All @@ -19,8 +20,7 @@ public function setPrivateKey($private_key_id)
'private_key_id' => $private_key_id
]);
// Delete the old ssh mux file to force a new one to be created
Storage::disk('local')->delete(".ssh/ssh_mux_{$server->first()->ip}_{$server->first()->port}_{$server->first()->user}");

LocalStorage::ssh_mux()->delete("{$server->first()->ip}_{$server->first()->port}_{$server->first()->user}");
return redirect()->route('server.show', $this->parameters['server_uuid']);
}
public function mount()
Expand Down
58 changes: 58 additions & 0 deletions app/Http/Livewire/Settings/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace App\Http\Livewire\Settings;

use App\Enums\ActivityTypes;
use App\Models\InstanceSettings as ModelsInstanceSettings;
use App\Models\Server;
use Livewire\Component;
use Spatie\Url\Url;
use Symfony\Component\Yaml\Yaml;

class Form extends Component
{
Expand Down Expand Up @@ -44,5 +48,59 @@ public function submit()
}
$this->validate();
$this->settings->save();
if (isset($this->settings->fqdn)) {
if (config('app.env') == 'local') {
$server = Server::findOrFail(1);
$dynamic_config_path = '/data/coolify/proxy/dynamic';
} else {
$server = Server::findOrFail(0);
$dynamic_config_path = '/traefik/dynamic';
}
$url = Url::fromString($this->settings->fqdn);
$host = $url->getHost();
$schema = $url->getScheme();
$entryPoints = [
0 => 'http',
];
if ($schema === 'https') {
$entryPoints[] = 'https';
}
$traefik_dynamic_conf = [
'http' =>
[
'routers' =>
[
'coolify' =>
[
'entryPoints' => $entryPoints,
'service' => 'coolify',
'rule' => "Host(`{$host}`)",
],
],
'services' =>
[
'coolify' =>
[
'loadBalancer' =>
[
'servers' =>
[
0 =>
[
'url' => 'http://coolify:80',
],
],
],
],
],
],
];
$yaml = Yaml::dump($traefik_dynamic_conf);
$base64 = base64_encode($yaml);
remote_process([
"mkdir -p $dynamic_config_path",
"echo '$base64' | base64 -d > $dynamic_config_path/coolify.yaml",
], $server, ActivityTypes::INLINE->value);
}
}
}
4 changes: 3 additions & 1 deletion app/Jobs/ApplicationDeploymentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Spatie\Activitylog\Models\Activity;
use Symfony\Component\Yaml\Yaml;
use Illuminate\Support\Str;
use LocalStorage;
use Log;
use Spatie\Url\Url;

class ApplicationDeploymentJob implements ShouldQueue
Expand Down Expand Up @@ -203,7 +205,7 @@ public function handle(): void
$this->fail();
} finally {
if (isset($this->docker_compose)) {
Storage::disk('deployments')->put(Str::kebab($this->application->name) . '/docker-compose.yml', $this->docker_compose);
LocalStorage::deployments()->put(Str::kebab($this->application->name) . '/docker-compose.yml', $this->docker_compose);
}
$this->execute_now(["docker rm -f {$this->deployment_uuid} >/dev/null 2>&1"], hideFromOutput: true);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/ContainerStatusJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
public string|null $application_id = null,
) {
if ($this->application_id) {
$this->application = Application::find($this->application_id)->first();
$this->application = Application::find($this->application_id);
}
}
public function uniqueId(): string
Expand Down
39 changes: 0 additions & 39 deletions app/Jobs/ContainerStopJob.php

This file was deleted.

1 change: 1 addition & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use LocalStorage;

class AppServiceProvider extends ServiceProvider
{
Expand Down
3 changes: 3 additions & 0 deletions bootstrap/helpers/proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
function getProxyConfiguration(Server $server)
{
$proxy_path = config('coolify.proxy_config_path');
if (config('app.env') === 'local') {
$proxy_path = $proxy_path . '/testing-host-1/';
}
$networks = collect($server->standaloneDockers)->map(function ($docker) {
return $docker['network'];
})->unique();
Expand Down
10 changes: 6 additions & 4 deletions bootstrap/helpers/remoteProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,20 @@ function remote_process(
function save_private_key_for_server(Server $server)
{
$temp_file = "id.root@{$server->ip}";
Storage::disk('ssh-keys')->put($temp_file, $server->privateKey->private_key);
return '/var/www/html/storage/app/ssh-keys/' . $temp_file;
LocalStorage::ssh_keys()->put($temp_file, $server->privateKey->private_key);
return '/var/www/html/storage/app/private/ssh/keys/' . $temp_file;
}

function generate_ssh_command(string $private_key_location, string $server_ip, string $user, string $port, string $command, bool $isMux = true)
{
Storage::disk('local')->makeDirectory('.ssh');
LocalStorage::ssh_keys();
LocalStorage::ssh_mux();

$delimiter = 'EOF-COOLIFY-SSH';
$ssh_command = "ssh ";

if ($isMux && config('coolify.mux_enabled')) {
$ssh_command .= '-o ControlMaster=auto -o ControlPersist=1m -o ControlPath=/var/www/html/storage/app/.ssh/ssh_mux_%h_%p_%r ';
$ssh_command .= '-o ControlMaster=auto -o ControlPersist=1m -o ControlPath=/var/www/html/storage/app/private/ssh/mux/%h_%p_%r ';
}
$ssh_command .= "-i {$private_key_location} "
. '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '
Expand All @@ -85,6 +86,7 @@ function instant_remote_process(array $command, Server $server, $throwError = tr
$output = trim($process->output());
$exitCode = $process->exitCode();
if ($exitCode !== 0) {
Log::info($process->errorOutput());
if (!$throwError) {
return null;
}
Expand Down
38 changes: 38 additions & 0 deletions bootstrap/helpers/storage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\Storage;

class LocalStorage extends Facade
{
public static function deployments()
{
$storage = Storage::build([
'driver' => 'local',
'root' => storage_path("app/private/deployments"),
'visibility' => 'private',
]);
$storage->makeDirectory('.');
return $storage;
}
public static function ssh_keys()
{
$storage = Storage::build([
'driver' => 'local',
'root' => storage_path("app/private/ssh/keys"),
'visibility' => 'private'
]);
$storage->makeDirectory('.');
return $storage;
}
public static function ssh_mux()
{
$storage = Storage::build([
'driver' => 'local',
'root' => storage_path("app/private/ssh/mux"),
'visibility' => 'private',
]);
$storage->makeDirectory('.');
return $storage;
}
}
3 changes: 1 addition & 2 deletions config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*/

'disks' => [

'local' => [
'driver' => 'local',
'root' => storage_path('app'),
Expand All @@ -39,7 +38,7 @@
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
'throw' => false,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->bigIncrements('id');
$table->string('uuid')->unique();
$table->boolean('is_root_user')->default(false);
$table->string('name')->default('Your Name Here');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->id();
$table->bigIncrements('id');
$table->morphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('teams', function (Blueprint $table) {
$table->id();
$table->bigIncrements('id');
$table->string('uuid')->unique();
$table->string('name');
$table->boolean('personal_team')->default(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('team_user', function (Blueprint $table) {
$table->id();
$table->bigIncrements('id');
$table->foreignId('team_id');
$table->foreignId('user_id');
$table->string('role')->nullable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('instance_settings', function (Blueprint $table) {
$table->id();
$table->bigIncrements('id');
$table->string('fqdn')->nullable();
$table->string('wildcard_domain')->nullable();
$table->string('redirect_url')->nullable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('servers', function (Blueprint $table) {
$table->id();
$table->bigIncrements('id');
$table->string('uuid')->unique();
$table->string('name');
$table->string('description')->nullable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('server_settings', function (Blueprint $table) {
$table->id();
$table->bigIncrements('id');
$table->string('uuid')->unique();

$table->boolean('is_part_of_swarm')->default(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('private_keys', function (Blueprint $table) {
$table->id();
$table->bigIncrements('id');
$table->string('uuid')->unique();
$table->string('name');
$table->string('description')->nullable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('projects', function (Blueprint $table) {
$table->id();
$table->bigIncrements('id');
$table->string('uuid')->unique();
$table->string('name');
$table->string('description')->nullable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('project_settings', function (Blueprint $table) {
$table->id();
$table->bigIncrements('id');
$table->string('uuid')->unique();
$table->string('wildcard_domain')->nullable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('environments', function (Blueprint $table) {
$table->id();
$table->bigIncrements('id');
$table->string('name');
$table->foreignId('project_id');
$table->timestamps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('applications', function (Blueprint $table) {
$table->id();
$table->bigIncrements('id');
$table->integer('repository_project_id')->nullable();
$table->string('uuid')->unique();
$table->string('name');
Expand Down
Loading

0 comments on commit f766600

Please sign in to comment.