Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ijpatricio committed May 12, 2023
2 parents 931664c + d6dc540 commit ee084b0
Show file tree
Hide file tree
Showing 128 changed files with 3,944 additions and 650 deletions.
5 changes: 4 additions & 1 deletion .env.development.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
USERID=
GROUPID=
PROJECT_PATH_ON_HOST=/Users/your-username-here/code/coollabsio/coolify
SERVEO_URL=<for receiving webhooks locally https://serveo.net/>
MUX_ENABLED=false
############################################################################################################

APP_NAME=Coolify
Expand All @@ -26,4 +28,5 @@ DB_DATABASE=coolify
DB_USERNAME=coolify
DB_PASSWORD=password

QUEUE_CONNECTION=database
QUEUE_CONNECTION=redis
REDIS_HOST=coolify-redis
4 changes: 3 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ DB_DATABASE=coolify
DB_USERNAME=coolify
DB_PASSWORD=

QUEUE_CONNECTION=database
QUEUE_CONNECTION=redis
REDIS_HOST=coolify-redis
REDIS_PASSWORD=
40 changes: 25 additions & 15 deletions app/Console/Commands/SyncBunny.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ class SyncBunny extends Command
*/
public function handle()
{
$bunny_cdn = "https://coolify-cdn.b-cdn.net/";
$bunny_cdn = "https://coolify-cdn.b-cdn.net";
$bunny_cdn_path = "files";
$bunny_cdn_storage_name = "coolify-cdn";

$parent_dir = realpath(dirname(__FILE__) . '/../../..');

$compose_file = "docker-compose.yml";
$compose_file_prod = "docker-compose.prod.yml";
$install_script = "install.sh";
$upgrade_script = "upgrade.sh";
$docker_install_script = "install-docker.sh";
$production_env = ".env.production";

$versions = "versions.json";

PendingRequest::macro('storage', function ($file) {
$headers = [
'AccessKey' => env('BUNNY_STORAGE_API_KEY'),
Expand All @@ -50,29 +53,36 @@ public function handle()
$file = fread($fileStream, filesize($file));
return PendingRequest::baseUrl('https://storage.bunnycdn.com')->withHeaders($headers)->withBody($file)->throw();
});
PendingRequest::macro('purge', function ($url) {
$headers = [
'AccessKey' => env('BUNNY_API_KEY'),
'Accept' => 'application/json',
];
return PendingRequest::withHeaders($headers)->post('https://api.bunny.net/purge', [
"urls" => [$url],
]);
});
try {
Http::pool(fn (Pool $pool) => [
$pool->storage(file: "$parent_dir/$compose_file")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$compose_file"),
$pool->storage(file: "$parent_dir/$compose_file_prod")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$compose_file_prod"),
$pool->storage(file: "$parent_dir/$production_env")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$production_env"),
$pool->storage(file: "$parent_dir/scripts/$upgrade_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$upgrade_script"),
$pool->storage(file: "$parent_dir/scripts/$install_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$install_script"),
$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"),
]);

$res = Http::withHeaders([
'AccessKey' => env('BUNNY_API_KEY'),
'Accept' => 'application/json',
])->get('https://api.bunny.net/purge', [
"url" => "$bunny_cdn/$bunny_cdn_path/$compose_file",
"url" => "$bunny_cdn/$bunny_cdn_path/$compose_file_prod",
"url" => "$bunny_cdn/$bunny_cdn_path/$upgrade_script",
"url" => "$bunny_cdn/$bunny_cdn_path/$production_env",
"url" => "$bunny_cdn/$bunny_cdn_path/$docker_install_script"
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"),
]);
if ($res->ok()) {
echo "All files uploaded & purged...\n";
return;
}
echo "All files uploaded & purged...\n";
return;
throw new \Exception("Something went wrong.");
} catch (\Exception $e) {
echo $e->getMessage();
Expand Down
2 changes: 1 addition & 1 deletion app/Data/CoolifyTaskArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(
public string $type,
public ?string $type_uuid = null,
public ?Model $model = null,
public string $status = ProcessStatus::HOLDING->value,
public string $status = ProcessStatus::QUEUED->value,
) {
}
}
2 changes: 1 addition & 1 deletion app/Enums/ProcessStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

enum ProcessStatus: string
{
case HOLDING = 'holding';
case QUEUED = 'queued';
case IN_PROGRESS = 'in_progress';
case FINISHED = 'finished';
case ERROR = 'error';
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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 Down
9 changes: 7 additions & 2 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function environments()
return view('project.environments', ['project' => $project]);
}

public function resources_new()
public function new()
{
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
Expand All @@ -29,7 +29,12 @@ public function resources_new()
if (!$environment) {
return redirect()->route('dashboard');
}
return view('project.new', ['project' => $project, 'environment' => $environment, 'type' => 'resource']);

$type = request()->query('type');

return view('project.new', [
'type' => $type
]);
}
public function resources()
{
Expand Down
19 changes: 16 additions & 3 deletions app/Http/Livewire/ActivityMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Livewire;

use App\Enums\ProcessStatus;
use Livewire\Component;
use Spatie\Activitylog\Models\Activity;

Expand Down Expand Up @@ -31,12 +32,24 @@ public function newMonitorActivity($activityId)
public function polling()
{
$this->hydrateActivity();

if (data_get($this->activity, 'properties.exitCode') !== null) {
$this->setStatus(ProcessStatus::IN_PROGRESS);
$exit_code = data_get($this->activity, 'properties.exitCode');
if ($exit_code !== null) {
if ($exit_code === 0) {
$this->setStatus(ProcessStatus::FINISHED);
} else {
$this->setStatus(ProcessStatus::ERROR);
}
$this->isPollingActive = false;
}
}

protected function setStatus($status)
{
$this->activity->properties = $this->activity->properties->merge([
'status' => $status,
]);
$this->activity->save();
}
public function render()
{
return view('livewire.activity-monitor');
Expand Down
4 changes: 1 addition & 3 deletions app/Http/Livewire/CheckUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Http\Livewire;

use App\Models\Server;
use Illuminate\Support\Facades\Http;
use Livewire\Component;

class CheckUpdate extends Component
Expand All @@ -16,7 +14,7 @@ class CheckUpdate extends Component
public function checkUpdate()
{
$this->latestVersion = getLatestVersionOfCoolify();
$this->currentVersion = config('coolify.version');
$this->currentVersion = config('version');
if ($this->latestVersion === 'latest') {
$this->updateAvailable = true;
return;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Livewire/Destination/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function submit()
}
public function delete()
{
instantRemoteProcess(['docker network rm -f ' . $this->destination->network], $this->destination->server);
// instantRemoteProcess(['docker network rm -f ' . $this->destination->network], $this->destination->server);
$this->destination->delete();
return redirect()->route('dashboard');
}
Expand Down
14 changes: 9 additions & 5 deletions app/Http/Livewire/Destination/New/StandaloneDocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class StandaloneDocker extends Component
public string $network;

public Collection $servers;
public int $server_id;
public int|null $server_id = null;

protected $rules = [
'name' => 'required|string',
Expand All @@ -23,10 +23,14 @@ class StandaloneDocker extends Component
];
public function mount()
{
if (request()->query('server_id')) {
$this->server_id = request()->query('server_id');
} else {
$this->server_id = Server::first()->id;
if (!$this->server_id) {
if (request()->query('server_id')) {
$this->server_id = request()->query('server_id');
} else {
if ($this->servers->count() > 0) {
$this->server_id = $this->servers->first()->id;
}
}
}
$this->network = new Cuid2(7);
$this->name = generateRandomName();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Livewire/PrivateKey/Change.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function changePrivateKey()
$this->private_key->save();
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
} catch (\Exception $e) {
$this->addError('private_key_value', $e->getMessage());
return generalErrorHandler($e, $this);
}
}
}
19 changes: 9 additions & 10 deletions app/Http/Livewire/PrivateKey/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
namespace App\Http\Livewire\PrivateKey;

use App\Models\PrivateKey;
use Illuminate\Routing\Route as RoutingRoute;
use Illuminate\Support\Facades\Route;
use Livewire\Component;

class Create extends Component
{
public $private_key_value;
public $private_key_name;
public $private_key_description;
public string $name;
public string|null $description;
public string $value;
public string $currentRoute;

public function mount()
Expand All @@ -20,14 +19,14 @@ public function mount()
}
public function createPrivateKey()
{
$this->private_key_value = trim($this->private_key_value);
if (!str_ends_with($this->private_key_value, "\n")) {
$this->private_key_value .= "\n";
$this->value = trim($this->value);
if (!str_ends_with($this->value, "\n")) {
$this->value .= "\n";
}
$new_private_key = PrivateKey::create([
'name' => $this->private_key_name,
'description' => $this->private_key_description,
'private_key' => $this->private_key_value,
'name' => $this->name,
'description' => $this->description,
'private_key' => $this->value,
'team_id' => session('currentTeam')->id
]);
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Livewire/Project/Application/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Deploy extends Component

public function mount()
{
$this->parameters = Route::current()->parameters();
$this->parameters = getParameters();
$this->application = Application::where('id', $this->applicationId)->first();
$this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Add extends Component
];
public function mount()
{
$this->parameters = Route::current()->parameters();
$this->parameters = getParameters();
}
public function submit()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function submit($data)
$this->application->refresh();
$this->emit('clearAddEnv');
} catch (\Exception $e) {
return generalErrorHandlerLivewire($e, $this);
return generalErrorHandler($e, $this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Show extends Component
];
public function mount()
{
$this->parameters = Route::current()->parameters();
$this->parameters = getParameters();
}
public function submit()
{
Expand Down
1 change: 1 addition & 0 deletions app/Http/Livewire/Project/Application/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function instantSave()
$this->application->settings->is_dual_cert = $this->is_dual_cert;
$this->application->settings->save();
$this->application->refresh();
$this->emit('saved', 'Application settings updated!');
}
public function mount()
{
Expand Down
9 changes: 9 additions & 0 deletions app/Http/Livewire/Project/Application/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ public function mount()
{
$this->application = Application::where('id', $this->applicationId)->first();
}
public function submit()
{
$this->validate();
if (!$this->application->git_commit_sha) {
$this->application->git_commit_sha = 'HEAD';
}
$this->application->save();
$this->emit('saved', 'Application source updated!');
}
}
2 changes: 1 addition & 1 deletion app/Http/Livewire/Project/Application/Storages/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Add extends Component
];
public function mount()
{
$this->parameters = Route::current()->parameters();
$this->parameters = getParameters();
}
public function submit()
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Livewire/Project/Application/Storages/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function submit($data)
$this->application->refresh();
$this->emit('clearAddStorage');
} catch (\Exception $e) {
return generalErrorHandlerLivewire($e, $this);
return generalErrorHandler($e, $this);
}
}
}
25 changes: 25 additions & 0 deletions app/Http/Livewire/Project/Delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Livewire\Project;

use App\Models\Project;
use Livewire\Component;

class Delete extends Component
{
public int $project_id;
public int $resource_count = 0;

public function delete()
{
$this->validate([
'project_id' => 'required|int',
]);
$project = Project::findOrFail($this->project_id);
if ($project->applications->count() > 0) {
return $this->emit('error', 'Project has applications, please delete them first.');
}
$project->delete();
return redirect()->route('dashboard');
}
}
Loading

0 comments on commit ee084b0

Please sign in to comment.