diff --git a/app/Http/Controllers/NodeController.php b/app/Http/Controllers/NodeController.php index 7d55cb7..73c2c48 100644 --- a/app/Http/Controllers/NodeController.php +++ b/app/Http/Controllers/NodeController.php @@ -8,7 +8,6 @@ use App\Models\Node; use App\Models\NodeTaskGroupType; use App\Models\Service; -use App\Models\Swarm; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Inertia\Inertia; @@ -87,13 +86,11 @@ public function show(Node $node) return Inertia::render('Nodes/Show', [ 'node' => $node, - 'swarms' => Swarm::all(), 'isLastNode' => $node->team->nodes->count() === 1, 'initTaskGroup' => $initTaskGroup ?: $joinTaskGroup, 'lastAgentVersion' => $lastAgentVersion, 'agentUpgradeTaskGroup' => $taskGroup?->is_completed ? null : $taskGroup, 'registryUpdateTaskGroup' => $registryTaskGroup?->is_completed ? null : $registryTaskGroup, - 'swarmsQuotaReached' => auth()->user()->currentTeam->quotas()->swarms->quotaReached(), ]); } diff --git a/app/Http/Controllers/ServiceController.php b/app/Http/Controllers/ServiceController.php index f5f324d..e324238 100644 --- a/app/Http/Controllers/ServiceController.php +++ b/app/Http/Controllers/ServiceController.php @@ -33,19 +33,18 @@ public function index() */ public function create() { - $swarms = Swarm::all(); + $swarm = auth()->user()->currentTeam->swarms()->first(); - $networks = count($swarms) ? $swarms[0]->networks : []; - $nodes = count($swarms) ? $swarms[0]->nodes : []; - $dockerRegistries = count($swarms) ? $swarms[0]->data->registries : []; - $s3Storages = count($swarms) ? $swarms[0]->data->s3Storages : []; + $networks = $swarm->networks; + $nodes = $swarm->nodes; + $dockerRegistries = $swarm->data->registries; + $s3Storages = $swarm->data->s3Storages; $deploymentData = DeploymentData::make([ - 'networkName' => count($networks) ? $networks[0]->name : null, + 'networkName' => $networks->first()->name, ]); return Inertia::render('Services/Create', [ - 'swarms' => $swarms, 'networks' => $networks, 'nodes' => $nodes, 'deploymentData' => $deploymentData, @@ -62,15 +61,21 @@ public function store(StoreServiceRequest $request) { $deploymentData = DeploymentData::validateAndCreate($request->get('deploymentData')); + $team = auth()->user()->currentTeam; + $swarm = $team->swarms()->firstOrFail(); + $service = Service::make($request->validated()); - $service->team_id = auth()->user()->current_team_id; + $service->team_id = $team->id; + $service->swarm_id = $swarm->id; + DB::transaction(function () use ($service, $deploymentData) { $service->save(); $service->deploy($deploymentData); }); - return to_route('services.deployments', ['service' => $service->id]); + return to_route('services.deployments', $service) + ->with('success', 'Service created and deployment scheduled successfully.'); } /** diff --git a/app/Http/Controllers/SwarmTaskController.php b/app/Http/Controllers/SwarmTaskController.php index b08cb1d..b4f1d16 100644 --- a/app/Http/Controllers/SwarmTaskController.php +++ b/app/Http/Controllers/SwarmTaskController.php @@ -217,16 +217,22 @@ public function initCluster(InitClusterFormRequest $request) public function joinCluster(JoinClusterFormRequest $request) { DB::transaction(function () use ($request) { + $node = Node::findOrFail($request->node_id); + $swarm = $node->team->swarms()->first(); + + if (! $swarm) { + throw new \Exception('No swarm found for the node\'s team.'); + } + $taskGroup = NodeTaskGroup::create([ 'type' => NodeTaskGroupType::JoinSwarm, - 'swarm_id' => $request->swarm_id, - 'team_id' => auth()->user()->currentTeam->id, - 'node_id' => $request->node_id, + 'swarm_id' => $swarm->id, + 'team_id' => $node->team_id, + 'node_id' => $node->id, 'invoker_id' => auth()->user()->id, ]); - $node = Node::findOrFail($request->node_id); - $node->swarm_id = $request->swarm_id; + $node->swarm_id = $swarm->id; $node->save(); $remoteAddrs = collect($taskGroup->swarm->data->managerNodes)->map(fn (SwarmData\ManagerNode $node) => $node->addr)->toArray(); @@ -238,7 +244,7 @@ public function joinCluster(JoinClusterFormRequest $request) $taskGroup->tasks()->create([ 'type' => NodeTaskType::JoinSwarm, - 'meta' => JoinSwarmMeta::from(['swarmId' => $request->swarm_id, 'role' => $request->role]), + 'meta' => JoinSwarmMeta::from(['swarmId' => $swarm->id, 'role' => $request->role]), 'payload' => [ 'JoinSpec' => [ 'ListenAddr' => '0.0.0.0:2377', diff --git a/app/Http/Requests/NodeTask/InitClusterFormRequest.php b/app/Http/Requests/NodeTask/InitClusterFormRequest.php index 6cfb88c..71453fe 100644 --- a/app/Http/Requests/NodeTask/InitClusterFormRequest.php +++ b/app/Http/Requests/NodeTask/InitClusterFormRequest.php @@ -15,7 +15,6 @@ public function rules(): array { return [ 'node_id' => ['required', 'exists:nodes,id'], - 'name' => ['required', 'string', 'max:255'], 'advertise_addr' => ['required', 'ipv4'], 'force_new_cluster' => ['boolean'], ]; diff --git a/app/Http/Requests/NodeTask/JoinClusterFormRequest.php b/app/Http/Requests/NodeTask/JoinClusterFormRequest.php index 03ee3a9..ffecee7 100644 --- a/app/Http/Requests/NodeTask/JoinClusterFormRequest.php +++ b/app/Http/Requests/NodeTask/JoinClusterFormRequest.php @@ -15,7 +15,6 @@ public function rules(): array { return [ 'node_id' => ['required', 'exists:nodes,id'], - 'swarm_id' => ['required', 'exists:swarms,id'], 'role' => ['required', 'in:manager,worker'], 'advertise_addr' => ['exclude_if:role,worker', 'required', 'ipv4'], ]; diff --git a/app/Http/Requests/StoreServiceRequest.php b/app/Http/Requests/StoreServiceRequest.php index 137ce2c..cbac1f3 100644 --- a/app/Http/Requests/StoreServiceRequest.php +++ b/app/Http/Requests/StoreServiceRequest.php @@ -23,7 +23,6 @@ public function rules(): array { return [ 'name' => ['required', 'string'], - 'swarm_id' => ['required', 'exists:swarms,id'], ]; } } diff --git a/app/Models/NodeTasks/InitSwarm/InitSwarmMeta.php b/app/Models/NodeTasks/InitSwarm/InitSwarmMeta.php index 2064f6e..408169e 100644 --- a/app/Models/NodeTasks/InitSwarm/InitSwarmMeta.php +++ b/app/Models/NodeTasks/InitSwarm/InitSwarmMeta.php @@ -8,13 +8,12 @@ class InitSwarmMeta extends AbstractTaskMeta { public function __construct( public int $swarmId, - public string $name, public bool $forceNewCluster ) {} public function formattedHtml(): string { - $msg = 'Initialize Docker Swarm cluster '.$this->name.''; + $msg = 'Initialize Docker Swarm cluster'; if ($this->forceNewCluster) { $msg .= ' with force cluster creation'; } diff --git a/app/Models/Swarm.php b/app/Models/Swarm.php index 454ef78..137fb72 100644 --- a/app/Models/Swarm.php +++ b/app/Models/Swarm.php @@ -13,7 +13,6 @@ class Swarm extends Model use HasOwningTeam; protected $fillable = [ - 'name', 'data', 'team_id', ]; diff --git a/app/Notifications/TrialEndsSoonNotification.php b/app/Notifications/TrialEndsSoonNotification.php index 91c1f96..3241073 100644 --- a/app/Notifications/TrialEndsSoonNotification.php +++ b/app/Notifications/TrialEndsSoonNotification.php @@ -45,7 +45,7 @@ public function toMail(object $notifiable): MailMessage $dateDiff = $nextPayment->date->longRelativeToNowDiffForHumans(); return (new MailMessage) - ->subject("Your trial ends in {$dateDiff}") + ->subject("Your free trial ends in {$dateDiff}") ->greeting("Hello {$this->team->customer->name}!") ->line('Your trial for team '.$this->team->name.' ends soon.') ->line("You will be charged {$nextPayment->amount()} on {$nextPayment->date->toDateTimeString()} ({$dateDiff}).") diff --git a/database/migrations/2024_08_20_202958_alter_swarms_remove_name_column.php b/database/migrations/2024_08_20_202958_alter_swarms_remove_name_column.php new file mode 100644 index 0000000..acf5cc0 --- /dev/null +++ b/database/migrations/2024_08_20_202958_alter_swarms_remove_name_column.php @@ -0,0 +1,35 @@ +dropColumn('name'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('swarms', function (Blueprint $table) { + $table->string('name')->after('id'); + }); + + DB::table('swarms')->update(['name' => DB::raw('CAST(id AS VARCHAR)')]); + + Schema::table('swarms', function (Blueprint $table) { + $table->string('name')->nullable(false)->change(); + }); + } +}; diff --git a/resources/js/Pages/Nodes/Partials/InitSwarmCluster.vue b/resources/js/Pages/Nodes/Partials/InitSwarmCluster.vue new file mode 100644 index 0000000..0d7ea7f --- /dev/null +++ b/resources/js/Pages/Nodes/Partials/InitSwarmCluster.vue @@ -0,0 +1,88 @@ + + + diff --git a/resources/js/Pages/Nodes/Partials/JoinSwarmCluster.vue b/resources/js/Pages/Nodes/Partials/JoinSwarmCluster.vue new file mode 100644 index 0000000..3d9928f --- /dev/null +++ b/resources/js/Pages/Nodes/Partials/JoinSwarmCluster.vue @@ -0,0 +1,76 @@ + + + diff --git a/resources/js/Pages/Nodes/Partials/NewSwarmCluster.vue b/resources/js/Pages/Nodes/Partials/NewSwarmCluster.vue deleted file mode 100644 index f56c063..0000000 --- a/resources/js/Pages/Nodes/Partials/NewSwarmCluster.vue +++ /dev/null @@ -1,228 +0,0 @@ - - - diff --git a/resources/js/Pages/Nodes/Show.vue b/resources/js/Pages/Nodes/Show.vue index 737635c..0557811 100644 --- a/resources/js/Pages/Nodes/Show.vue +++ b/resources/js/Pages/Nodes/Show.vue @@ -1,5 +1,6 @@ \ No newline at end of file + + + diff --git a/resources/js/Pages/Services/Show.vue b/resources/js/Pages/Services/Show.vue index 6ad38e4..fbd203e 100644 --- a/resources/js/Pages/Services/Show.vue +++ b/resources/js/Pages/Services/Show.vue @@ -1,7 +1,7 @@ \ No newline at end of file + + + + + + + + + + + +
+ + +
+ + Deploy Changes + +
+ + + + + + +
+