Skip to content

Commit 82057e1

Browse files
authored
Merge pull request coollabsio#2681 from coollabsio/next
v4.0.0-beta.307
2 parents e9158b7 + 4ce3663 commit 82057e1

File tree

104 files changed

+13663
-1207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+13663
-1207
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Actions\Application;
4+
5+
use App\Models\Application;
6+
use Lorisleiva\Actions\Concerns\AsAction;
7+
8+
class LoadComposeFile
9+
{
10+
use AsAction;
11+
12+
public function handle(Application $application)
13+
{
14+
$application->loadComposeFile();
15+
}
16+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Actions\Database;
4+
5+
use App\Models\StandaloneClickhouse;
6+
use App\Models\StandaloneDragonfly;
7+
use App\Models\StandaloneKeydb;
8+
use App\Models\StandaloneMariadb;
9+
use App\Models\StandaloneMongodb;
10+
use App\Models\StandaloneMysql;
11+
use App\Models\StandalonePostgresql;
12+
use App\Models\StandaloneRedis;
13+
use Lorisleiva\Actions\Concerns\AsAction;
14+
15+
class RestartDatabase
16+
{
17+
use AsAction;
18+
19+
public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database)
20+
{
21+
$server = $database->destination->server;
22+
if (! $server->isFunctional()) {
23+
return 'Server is not functional';
24+
}
25+
StopDatabase::run($database);
26+
27+
return StartDatabase::run($database);
28+
}
29+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace App\Actions\Database;
4+
5+
use App\Models\StandaloneClickhouse;
6+
use App\Models\StandaloneDragonfly;
7+
use App\Models\StandaloneKeydb;
8+
use App\Models\StandaloneMariadb;
9+
use App\Models\StandaloneMongodb;
10+
use App\Models\StandaloneMysql;
11+
use App\Models\StandalonePostgresql;
12+
use App\Models\StandaloneRedis;
13+
use Lorisleiva\Actions\Concerns\AsAction;
14+
15+
class StartDatabase
16+
{
17+
use AsAction;
18+
19+
public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database)
20+
{
21+
$server = $database->destination->server;
22+
if (! $server->isFunctional()) {
23+
return 'Server is not functional';
24+
}
25+
switch ($database->getMorphClass()) {
26+
case 'App\Models\StandalonePostgresql':
27+
$activity = StartPostgresql::run($database);
28+
break;
29+
case 'App\Models\StandaloneRedis':
30+
$activity = StartRedis::run($database);
31+
break;
32+
case 'App\Models\StandaloneMongodb':
33+
$activity = StartMongodb::run($database);
34+
break;
35+
case 'App\Models\StandaloneMysql':
36+
$activity = StartMysql::run($database);
37+
break;
38+
case 'App\Models\StandaloneMariadb':
39+
$activity = StartMariadb::run($database);
40+
break;
41+
case 'App\Models\StandaloneKeydb':
42+
$activity = StartKeydb::run($database);
43+
break;
44+
case 'App\Models\StandaloneDragonfly':
45+
$activity = StartDragonfly::run($database);
46+
break;
47+
case 'App\Models\StandaloneClickhouse':
48+
$activity = StartClickhouse::run($database);
49+
break;
50+
}
51+
if ($database->is_public && $database->public_port) {
52+
StartDatabaseProxy::dispatch($database);
53+
}
54+
55+
return $activity;
56+
}
57+
}

app/Actions/Database/StopDatabase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,5 @@ public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|St
2929
if ($database->is_public) {
3030
StopDatabaseProxy::run($database);
3131
}
32-
// TODO: make notification for services
33-
// $database->environment->project->team->notify(new StatusChanged($database));
3432
}
3533
}

app/Actions/Database/StopDatabaseProxy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|St
2727
$server = data_get($database, 'service.server');
2828
}
2929
instant_remote_process(["docker rm -f {$uuid}-proxy"], $server);
30-
$database->is_public = false;
3130
$database->save();
3231
DatabaseStatusChanged::dispatch();
3332
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Actions\Service;
4+
5+
use App\Models\Service;
6+
use Lorisleiva\Actions\Concerns\AsAction;
7+
8+
class RestartService
9+
{
10+
use AsAction;
11+
12+
public function handle(Service $service)
13+
{
14+
StopService::run($service);
15+
16+
return StartService::run($service);
17+
}
18+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\Team;
6+
use Illuminate\Console\Command;
7+
8+
class CloudCleanupSubscriptions extends Command
9+
{
10+
protected $signature = 'cloud:cleanup-subs';
11+
12+
protected $description = 'Cleanup subcriptions teams';
13+
14+
public function handle()
15+
{
16+
try {
17+
if (! isCloud()) {
18+
$this->error('This command can only be run on cloud');
19+
20+
return;
21+
}
22+
ray()->clearAll();
23+
$this->info('Cleaning up subcriptions teams');
24+
$stripe = new \Stripe\StripeClient(config('subscription.stripe_api_key'));
25+
26+
$teams = Team::all()->filter(function ($team) {
27+
return $team->id !== 0;
28+
})->sortBy('id');
29+
foreach ($teams as $team) {
30+
if ($team) {
31+
$this->info("Checking team {$team->id}");
32+
}
33+
if (! data_get($team, 'subscription')) {
34+
$this->disableServers($team);
35+
36+
continue;
37+
}
38+
// If the team has no subscription id and the invoice is paid, we need to reset the invoice paid status
39+
if (! (data_get($team, 'subscription.stripe_subscription_id'))) {
40+
$this->info("Resetting invoice paid status for team {$team->id} {$team->name}");
41+
42+
$team->subscription->update([
43+
'stripe_invoice_paid' => false,
44+
'stripe_trial_already_ended' => false,
45+
'stripe_subscription_id' => null,
46+
]);
47+
$this->disableServers($team);
48+
49+
continue;
50+
} else {
51+
$subscription = $stripe->subscriptions->retrieve(data_get($team, 'subscription.stripe_subscription_id'), []);
52+
$status = data_get($subscription, 'status');
53+
if ($status === 'active' || $status === 'past_due') {
54+
$team->subscription->update([
55+
'stripe_invoice_paid' => true,
56+
'stripe_trial_already_ended' => false,
57+
]);
58+
59+
continue;
60+
}
61+
$this->info('Subscription status: '.$status);
62+
$this->info('Subscription id: '.data_get($team, 'subscription.stripe_subscription_id'));
63+
$confirm = $this->confirm('Do you want to cancel the subscription?', true);
64+
if (! $confirm) {
65+
$this->info("Skipping team {$team->id} {$team->name}");
66+
} else {
67+
$this->info("Cancelling subscription for team {$team->id} {$team->name}");
68+
$team->subscription->update([
69+
'stripe_invoice_paid' => false,
70+
'stripe_trial_already_ended' => false,
71+
'stripe_subscription_id' => null,
72+
]);
73+
$this->disableServers($team);
74+
}
75+
}
76+
}
77+
78+
} catch (\Exception $e) {
79+
$this->error($e->getMessage());
80+
81+
return;
82+
}
83+
}
84+
85+
private function disableServers(Team $team)
86+
{
87+
foreach ($team->servers as $server) {
88+
if ($server->settings->is_usable === true || $server->settings->is_reachable === true || $server->ip !== '1.2.3.4') {
89+
$this->info("Disabling server {$server->id} {$server->name}");
90+
$server->settings()->update([
91+
'is_usable' => false,
92+
'is_reachable' => false,
93+
]);
94+
$server->update([
95+
'ip' => '1.2.3.4',
96+
]);
97+
}
98+
}
99+
100+
}
101+
}

app/Console/Commands/Dev.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,41 @@
99

1010
class Dev extends Command
1111
{
12-
protected $signature = 'dev:init';
12+
protected $signature = 'dev {--init} {--generate-openapi}';
1313

14-
protected $description = 'Init the app in dev mode';
14+
protected $description = 'Helper commands for development.';
1515

1616
public function handle()
17+
{
18+
if ($this->option('init')) {
19+
$this->init();
20+
21+
return;
22+
}
23+
if ($this->option('generate-openapi')) {
24+
$this->generateOpenApi();
25+
26+
return;
27+
}
28+
29+
}
30+
31+
public function generateOpenApi()
32+
{
33+
// Generate OpenAPI documentation
34+
echo "Generating OpenAPI documentation.\n";
35+
$process = Process::run(['/var/www/html/vendor/bin/openapi', 'app', '-o', 'openapi.yaml']);
36+
$error = $process->errorOutput();
37+
$error = preg_replace('/^.*an object literal,.*$/m', '', $error);
38+
$error = preg_replace('/^\h*\v+/m', '', $error);
39+
echo $error;
40+
echo $process->output();
41+
}
42+
43+
public function init()
1744
{
1845
// Generate APP_KEY if not exists
46+
1947
if (empty(env('APP_KEY'))) {
2048
echo "Generating APP_KEY.\n";
2149
Artisan::call('key:generate');

app/Enums/BuildPackTypes.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace App\Enums;
4+
5+
enum BuildPackTypes: string
6+
{
7+
case NIXPACKS = 'nixpacks';
8+
case STATIC = 'static';
9+
case DOCKERFILE = 'dockerfile';
10+
case DOCKERCOMPOSE = 'dockercompose';
11+
}

app/Enums/NewDatabaseTypes.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace App\Enums;
4+
5+
enum NewDatabaseTypes: string
6+
{
7+
case POSTGRESQL = 'postgresql';
8+
case MYSQL = 'mysql';
9+
case MONGODB = 'mongodb';
10+
case REDIS = 'redis';
11+
case MARIADB = 'mariadb';
12+
case KEYDB = 'keydb';
13+
case DRAGONFLY = 'dragonfly';
14+
case CLICKHOUSE = 'clickhouse';
15+
}

0 commit comments

Comments
 (0)