-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2681 from coollabsio/next
v4.0.0-beta.307
- Loading branch information
Showing
104 changed files
with
13,663 additions
and
1,207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Actions\Application; | ||
|
||
use App\Models\Application; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
|
||
class LoadComposeFile | ||
{ | ||
use AsAction; | ||
|
||
public function handle(Application $application) | ||
{ | ||
$application->loadComposeFile(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Actions\Database; | ||
|
||
use App\Models\StandaloneClickhouse; | ||
use App\Models\StandaloneDragonfly; | ||
use App\Models\StandaloneKeydb; | ||
use App\Models\StandaloneMariadb; | ||
use App\Models\StandaloneMongodb; | ||
use App\Models\StandaloneMysql; | ||
use App\Models\StandalonePostgresql; | ||
use App\Models\StandaloneRedis; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
|
||
class RestartDatabase | ||
{ | ||
use AsAction; | ||
|
||
public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database) | ||
{ | ||
$server = $database->destination->server; | ||
if (! $server->isFunctional()) { | ||
return 'Server is not functional'; | ||
} | ||
StopDatabase::run($database); | ||
|
||
return StartDatabase::run($database); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace App\Actions\Database; | ||
|
||
use App\Models\StandaloneClickhouse; | ||
use App\Models\StandaloneDragonfly; | ||
use App\Models\StandaloneKeydb; | ||
use App\Models\StandaloneMariadb; | ||
use App\Models\StandaloneMongodb; | ||
use App\Models\StandaloneMysql; | ||
use App\Models\StandalonePostgresql; | ||
use App\Models\StandaloneRedis; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
|
||
class StartDatabase | ||
{ | ||
use AsAction; | ||
|
||
public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database) | ||
{ | ||
$server = $database->destination->server; | ||
if (! $server->isFunctional()) { | ||
return 'Server is not functional'; | ||
} | ||
switch ($database->getMorphClass()) { | ||
case 'App\Models\StandalonePostgresql': | ||
$activity = StartPostgresql::run($database); | ||
break; | ||
case 'App\Models\StandaloneRedis': | ||
$activity = StartRedis::run($database); | ||
break; | ||
case 'App\Models\StandaloneMongodb': | ||
$activity = StartMongodb::run($database); | ||
break; | ||
case 'App\Models\StandaloneMysql': | ||
$activity = StartMysql::run($database); | ||
break; | ||
case 'App\Models\StandaloneMariadb': | ||
$activity = StartMariadb::run($database); | ||
break; | ||
case 'App\Models\StandaloneKeydb': | ||
$activity = StartKeydb::run($database); | ||
break; | ||
case 'App\Models\StandaloneDragonfly': | ||
$activity = StartDragonfly::run($database); | ||
break; | ||
case 'App\Models\StandaloneClickhouse': | ||
$activity = StartClickhouse::run($database); | ||
break; | ||
} | ||
if ($database->is_public && $database->public_port) { | ||
StartDatabaseProxy::dispatch($database); | ||
} | ||
|
||
return $activity; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Actions\Service; | ||
|
||
use App\Models\Service; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
|
||
class RestartService | ||
{ | ||
use AsAction; | ||
|
||
public function handle(Service $service) | ||
{ | ||
StopService::run($service); | ||
|
||
return StartService::run($service); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\Team; | ||
use Illuminate\Console\Command; | ||
|
||
class CloudCleanupSubscriptions extends Command | ||
{ | ||
protected $signature = 'cloud:cleanup-subs'; | ||
|
||
protected $description = 'Cleanup subcriptions teams'; | ||
|
||
public function handle() | ||
{ | ||
try { | ||
if (! isCloud()) { | ||
$this->error('This command can only be run on cloud'); | ||
|
||
return; | ||
} | ||
ray()->clearAll(); | ||
$this->info('Cleaning up subcriptions teams'); | ||
$stripe = new \Stripe\StripeClient(config('subscription.stripe_api_key')); | ||
|
||
$teams = Team::all()->filter(function ($team) { | ||
return $team->id !== 0; | ||
})->sortBy('id'); | ||
foreach ($teams as $team) { | ||
if ($team) { | ||
$this->info("Checking team {$team->id}"); | ||
} | ||
if (! data_get($team, 'subscription')) { | ||
$this->disableServers($team); | ||
|
||
continue; | ||
} | ||
// If the team has no subscription id and the invoice is paid, we need to reset the invoice paid status | ||
if (! (data_get($team, 'subscription.stripe_subscription_id'))) { | ||
$this->info("Resetting invoice paid status for team {$team->id} {$team->name}"); | ||
|
||
$team->subscription->update([ | ||
'stripe_invoice_paid' => false, | ||
'stripe_trial_already_ended' => false, | ||
'stripe_subscription_id' => null, | ||
]); | ||
$this->disableServers($team); | ||
|
||
continue; | ||
} else { | ||
$subscription = $stripe->subscriptions->retrieve(data_get($team, 'subscription.stripe_subscription_id'), []); | ||
$status = data_get($subscription, 'status'); | ||
if ($status === 'active' || $status === 'past_due') { | ||
$team->subscription->update([ | ||
'stripe_invoice_paid' => true, | ||
'stripe_trial_already_ended' => false, | ||
]); | ||
|
||
continue; | ||
} | ||
$this->info('Subscription status: '.$status); | ||
$this->info('Subscription id: '.data_get($team, 'subscription.stripe_subscription_id')); | ||
$confirm = $this->confirm('Do you want to cancel the subscription?', true); | ||
if (! $confirm) { | ||
$this->info("Skipping team {$team->id} {$team->name}"); | ||
} else { | ||
$this->info("Cancelling subscription for team {$team->id} {$team->name}"); | ||
$team->subscription->update([ | ||
'stripe_invoice_paid' => false, | ||
'stripe_trial_already_ended' => false, | ||
'stripe_subscription_id' => null, | ||
]); | ||
$this->disableServers($team); | ||
} | ||
} | ||
} | ||
|
||
} catch (\Exception $e) { | ||
$this->error($e->getMessage()); | ||
|
||
return; | ||
} | ||
} | ||
|
||
private function disableServers(Team $team) | ||
{ | ||
foreach ($team->servers as $server) { | ||
if ($server->settings->is_usable === true || $server->settings->is_reachable === true || $server->ip !== '1.2.3.4') { | ||
$this->info("Disabling server {$server->id} {$server->name}"); | ||
$server->settings()->update([ | ||
'is_usable' => false, | ||
'is_reachable' => false, | ||
]); | ||
$server->update([ | ||
'ip' => '1.2.3.4', | ||
]); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
enum BuildPackTypes: string | ||
{ | ||
case NIXPACKS = 'nixpacks'; | ||
case STATIC = 'static'; | ||
case DOCKERFILE = 'dockerfile'; | ||
case DOCKERCOMPOSE = 'dockercompose'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
enum NewDatabaseTypes: string | ||
{ | ||
case POSTGRESQL = 'postgresql'; | ||
case MYSQL = 'mysql'; | ||
case MONGODB = 'mongodb'; | ||
case REDIS = 'redis'; | ||
case MARIADB = 'mariadb'; | ||
case KEYDB = 'keydb'; | ||
case DRAGONFLY = 'dragonfly'; | ||
case CLICKHOUSE = 'clickhouse'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
enum NewResourceTypes: string | ||
{ | ||
case PUBLIC = 'public'; | ||
case PRIVATE_GH_APP = 'private-gh-app'; | ||
case PRIVATE_DEPLOY_KEY = 'private-deploy-key'; | ||
case DOCKERFILE = 'dockerfile'; | ||
case DOCKERCOMPOSE = 'dockercompose'; | ||
case DOCKER_IMAGE = 'docker-image'; | ||
case SERVICE = 'service'; | ||
case POSTGRESQL = 'postgresql'; | ||
case MYSQL = 'mysql'; | ||
case MONGODB = 'mongodb'; | ||
case REDIS = 'redis'; | ||
case MARIADB = 'mariadb'; | ||
case KEYDB = 'keydb'; | ||
case DRAGONFLY = 'dragonfly'; | ||
case CLICKHOUSE = 'clickhouse'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
enum RedirectTypes: string | ||
{ | ||
case BOTH = 'both'; | ||
case WWW = 'www'; | ||
case NON_WWW = 'non-www'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.