Skip to content

Commit

Permalink
Merge branch 'v4-next' into notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed Jun 1, 2023
2 parents 18c69d7 + cd625ba commit 2d9db6d
Show file tree
Hide file tree
Showing 204 changed files with 5,816 additions and 2,617 deletions.
1 change: 1 addition & 0 deletions .env.development.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ GROUPID=
PROJECT_PATH_ON_HOST=/Users/your-username-here/code/coollabsio/coolify
SERVEO_URL=<for receiving webhooks locally https://serveo.net/>
MUX_ENABLED=false
[email protected]
############################################################################################################

APP_NAME=Coolify
Expand Down
10 changes: 9 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
COOLIFY_DEFAULT_PROXY=traefik
COOLIFY_DEFAULT_NETWORK=coolify

SENTRY_LARAVEL_DSN=https://[email protected]/4504672605372416
SENTRY_TRACES_SAMPLE_RATE=0.2

APP_NAME=Coolify
APP_SERVICE=php
APP_ENV=local
APP_ENV=production
APP_KEY=
APP_DEBUG=false
APP_URL=http://localhost
Expand All @@ -18,3 +24,5 @@ DB_PASSWORD=
QUEUE_CONNECTION=redis
REDIS_HOST=coolify-redis
REDIS_PASSWORD=

CACHE_DRIVER=redis
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ _volumes/
.lesshst
psysh_history
.psql_history
_ide_helper.php
.gitignore
.phpstorm.meta.php
_ide_helper_models.php
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ You are checking the next-gen of Coolify here, aka v4. Hi 👋

Thinks will be added here incrementally through PR's.

# Installation

```bash
curl -fsSL https://coolify-cdn.b-cdn.net/files/install.sh | bash
```

## Support

- Mastodon: [@andrasbacsai@fosstodon.org](https://fosstodon.org/@andrasbacsai)
- Telegram: [@andrasbacsai](https://t.me/andrasbacsai)
- Twitter: [@andrasbacsai](https://twitter.com/heyandras)
- Twitter: [@heyandras](https://twitter.com/heyandras)
- Email: [[email protected]](mailto:[email protected])
- Discord: [Invitation](https://coollabs.io/discord)
- Telegram: [@andrasbacsai](https://t.me/andrasbacsai)

---

Expand Down
11 changes: 7 additions & 4 deletions app/Actions/CoolifyTask/RunRemoteProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

use App\Enums\ActivityTypes;
use App\Enums\ProcessStatus;
use App\Jobs\DeployApplicationJob;
use App\Jobs\ApplicationDeploymentJob;
use Illuminate\Process\ProcessResult;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Process;
use Spatie\Activitylog\Models\Activity;

const TIMEOUT = 3600;
const IDLE_TIMEOUT = 3600;

class RunRemoteProcess
{
public Activity $activity;
Expand Down Expand Up @@ -52,7 +55,7 @@ public function __invoke(): ProcessResult

$status = ProcessStatus::IN_PROGRESS;

$processResult = Process::run($this->getCommand(), $this->handleOutput(...));
$processResult = Process::timeout(TIMEOUT)->idleTimeout(IDLE_TIMEOUT)->run($this->getCommand(), $this->handleOutput(...));

if ($this->activity->properties->get('status') === ProcessStatus::ERROR->value) {
$status = ProcessStatus::ERROR;
Expand Down Expand Up @@ -97,7 +100,7 @@ protected function getCommand(): string
$port = $this->activity->getExtraProperty('port');
$command = $this->activity->getExtraProperty('command');

return generateSshCommand($private_key_location, $server_ip, $user, $port, $command);
return generate_ssh_command($private_key_location, $server_ip, $user, $port, $command);
}

protected function handleOutput(string $type, string $output)
Expand Down Expand Up @@ -125,7 +128,7 @@ public function encodeOutput($type, $output)
'type' => $type,
'output' => $output,
'timestamp' => hrtime(true),
'batch' => DeployApplicationJob::$batch_counter,
'batch' => ApplicationDeploymentJob::$batch_counter,
'order' => $this->getLatestCounter(),
];

Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Proxy/CheckProxySettingsInSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CheckProxySettingsInSync
public function __invoke(Server $server, bool $reset = false)
{
$proxy_path = config('coolify.proxy_config_path');
$output = instantRemoteProcess([
$output = instant_remote_process([
"cat $proxy_path/docker-compose.yml",
], $server, false);
if (is_null($output) || $reset) {
Expand All @@ -23,7 +23,7 @@ public function __invoke(Server $server, bool $reset = false)
$server->extra_attributes->last_saved_proxy_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
$server->save();
if (is_null($output) || $reset) {
instantRemoteProcess([
instant_remote_process([
"mkdir -p $proxy_path",
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
], $server);
Expand Down
41 changes: 17 additions & 24 deletions app/Actions/Proxy/InstallProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

namespace App\Actions\Proxy;

use App\Enums\ActivityTypes;
use App\Models\InstanceSettings;
use App\Models\Server;
use Spatie\Activitylog\Models\Activity;
use Illuminate\Support\Str;
use Spatie\Url\Url;

class InstallProxy
{

public function __invoke(Server $server): Activity
{
$proxy_path = config('coolify.proxy_config_path');
Expand All @@ -26,7 +22,7 @@ public function __invoke(Server $server): Activity
return "docker network ls --format '{{.Name}}' | grep '^$network$' >/dev/null 2>&1 || docker network create --attachable $network > /dev/null 2>&1";
});

$configuration = instantRemoteProcess([
$configuration = instant_remote_process([
"cat $proxy_path/docker-compose.yml",
], $server, false);
if (is_null($configuration)) {
Expand All @@ -38,16 +34,16 @@ public function __invoke(Server $server): Activity
$server->extra_attributes->last_applied_proxy_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
$server->save();

$env_file_base64 = base64_encode(
$this->getEnvContents()
);
$activity = remoteProcess([
// $env_file_base64 = base64_encode(
// $this->getEnvContents()
// );
$activity = remote_process([
...$create_networks_command,
"echo 'Docker networks created...'",
"mkdir -p $proxy_path",
"cd $proxy_path",
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
"echo '$env_file_base64' | base64 -d > $proxy_path/.env",
// "echo '$env_file_base64' | base64 -d > $proxy_path/.env",
"echo 'Docker compose file created...'",
"echo 'Pulling docker image...'",
'docker compose pull -q',
Expand All @@ -56,23 +52,20 @@ public function __invoke(Server $server): Activity
"echo 'Starting proxy...'",
'docker compose up -d --remove-orphans',
"echo 'Proxy installed successfully...'"
], $server, ActivityTypes::INLINE->value);
], $server);

return $activity;
}

protected function getEnvContents()
{
$instance_fqdn = InstanceSettings::get()->fqdn ?? config('app.url');
$url = Url::fromString($instance_fqdn);
$data = [
'TRAEFIK_DASHBOARD_HOST' => $url->getHost(),
'LETS_ENCRYPT_EMAIL' => '',
];
// protected function getEnvContents()
// {
// $data = [
// 'LETS_ENCRYPT_EMAIL' => '',
// ];

return collect($data)
->map(fn ($v, $k) => "{$k}={$v}")
->push(PHP_EOL)
->implode(PHP_EOL);
}
// return collect($data)
// ->map(fn ($v, $k) => "{$k}={$v}")
// ->push(PHP_EOL)
// ->implode(PHP_EOL);
// }
}
4 changes: 2 additions & 2 deletions app/Actions/Server/InstallDocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class InstallDocker
public function __invoke(Server $server)
{
$config = base64_encode('{ "live-restore": true }');
$activity = remoteProcess([
$activity = remote_process([
"echo Installing Docker...",
"curl https://releases.rancher.com/install-docker/23.0.sh | sh",
"echo Configuring Docker...",
"echo '{$config}' | base64 -d > /etc/docker/daemon.json",
"echo Restarting Docker...",
"systemctl restart docker"
], $server, ActivityTypes::INLINE->value);
], $server);

return $activity;
}
Expand Down
20 changes: 8 additions & 12 deletions app/Console/Commands/SyncBunny.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function handle()
];
return PendingRequest::withHeaders($headers)->post('https://api.bunny.net/purge', [
"urls" => [$url],
]);
])->throw();
});
try {
Http::pool(fn (Pool $pool) => [
Expand All @@ -72,18 +72,14 @@ public function handle()
$pool->storage(file: "$parent_dir/scripts/$docker_install_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$docker_install_script"),
$pool->storage(file: "$parent_dir/$versions")->put("/$bunny_cdn_storage_name/$versions"),
]);
Http::pool(fn (Pool $pool) => [
$pool->purge(url: "$bunny_cdn/$bunny_cdn_path/$compose_file"),
$pool->purge(url: "$bunny_cdn/$bunny_cdn_path/$compose_file_prod"),
$pool->purge(url: "$bunny_cdn/$bunny_cdn_path/$production_env"),
$pool->purge(url: "$bunny_cdn/$bunny_cdn_path/$upgrade_script"),
$pool->purge(url: "$bunny_cdn/$bunny_cdn_path/$install_script"),
$pool->purge(url: "$bunny_cdn/$bunny_cdn_path/$docker_install_script"),
$pool->purge(url: "$bunny_cdn/$versions"),
]);
Http::withHeaders([
'AccessKey' => env('BUNNY_API_KEY'),
'Accept' => 'application/json',
])->get('https://api.bunny.net/purge', [
"url" => "$bunny_cdn/$bunny_cdn_path/*",
"async" => false
])->throw();
echo "All files uploaded & purged...\n";
return;
throw new \Exception("Something went wrong.");
} catch (\Exception $e) {
echo $e->getMessage();
}
Expand Down
14 changes: 8 additions & 6 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace App\Console;

use App\Jobs\ContainerStatusJob;
use App\Jobs\DockerCleanupDanglingImagesJob;
use App\Jobs\ProxyCheckJob;
use App\Jobs\InstanceAutoUpdateJob;
use App\Jobs\InstanceProxyCheckJob;
use App\Jobs\InstanceDockerCleanupJob;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

Expand All @@ -15,9 +15,11 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule): void
{
$schedule->job(new ContainerStatusJob)->everyMinute();
$schedule->job(new DockerCleanupDanglingImagesJob)->everyMinute();
// $schedule->job(new ProxyCheckJob)->everyMinute();
$schedule->command('horizon:snapshot')->everyFiveMinutes();

$schedule->job(new InstanceDockerCleanupJob)->everyFiveMinutes();
$schedule->job(new InstanceAutoUpdateJob)->everyFifteenMinutes();
// $schedule->job(new InstanceProxyCheckJob)->everyMinute();
}

/**
Expand Down
15 changes: 0 additions & 15 deletions app/Data/ApplicationPreview.php

This file was deleted.

1 change: 1 addition & 0 deletions app/Enums/ProcessStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ enum ProcessStatus: string
case IN_PROGRESS = 'in_progress';
case FINISHED = 'finished';
case ERROR = 'error';
case CANCELLED = 'cancelled';
}
3 changes: 2 additions & 1 deletion app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
use Sentry\Laravel\Integration;

class Handler extends ExceptionHandler
{
Expand Down Expand Up @@ -42,7 +43,7 @@ class Handler extends ExceptionHandler
public function register(): void
{
$this->reportable(function (Throwable $e) {
//
Integration::captureUnhandledException($e);
});
}
}
14 changes: 12 additions & 2 deletions app/Http/Controllers/ApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Models\ApplicationDeploymentQueue;
use Illuminate\Http\Request;
use Spatie\Activitylog\Models\Activity;

Expand All @@ -21,7 +22,7 @@ public function configuration()
if (!$application) {
return redirect()->route('dashboard');
}
return view('project.application.configuration', ['application' => $application,]);
return view('project.application.configuration', ['application' => $application]);
}
public function deployments()
{
Expand All @@ -37,7 +38,7 @@ public function deployments()
if (!$application) {
return redirect()->route('dashboard');
}
return view('project.application.deployments', ['application' => $application, 'deployments' => $application->deployments()]);
return view('project.application.deployments', ['application' => $application]);
}

public function deployment()
Expand All @@ -64,9 +65,18 @@ public function deployment()
'application_uuid' => $application->uuid,
]);
}
$deployment = ApplicationDeploymentQueue::where('deployment_uuid', $deployment_uuid)->first();
if (!$deployment) {
return redirect()->route('project.application.deployments', [
'project_uuid' => $project->uuid,
'environment_name' => $environment->name,
'application_uuid' => $application->uuid,
]);
}
return view('project.application.deployment', [
'application' => $application,
'activity' => $activity,
'deployment' => $deployment,
'deployment_uuid' => $deployment_uuid,
]);
}
Expand Down
Loading

0 comments on commit 2d9db6d

Please sign in to comment.