Skip to content

Commit fa93d62

Browse files
committed
feat: #25 list deployments on the service's page
1 parent 60bd5a3 commit fa93d62

14 files changed

+285
-22
lines changed

Diff for: app/Http/Controllers/ServiceController.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ServiceController extends Controller
2020
public function index()
2121
{
2222
$services = Service::with(['latestDeployment' => function ($query) {
23-
$query->with(['taskGroup' => function ($query) {
23+
$query->with(['latestTaskGroup' => function ($query) {
2424
$query->with('latestTask');
2525
}]);
2626
}])->orderBy('name')->get();
@@ -83,6 +83,15 @@ public function show(Service $service)
8383

8484
public function deployments(Service $service)
8585
{
86+
$service->load(['deployments' => function ($deployments) {
87+
$deployments->with(['latestTaskGroup' => function ($taskGroups) {
88+
$taskGroups->with([
89+
'invoker',
90+
'tasks' => function ($tasks) {
91+
}]);
92+
}]);
93+
}]);
94+
8695
return Inertia::render('Services/Deployments', ['service' => $service]);
8796
}
8897

Diff for: app/Http/Controllers/SwarmTaskController.php

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ public function initCluster(InitClusterFormRequest $request)
104104
]);
105105

106106
$deployment = $caddyService->deployments()->create([
107-
'task_group_id' => $taskGroup->id,
108107
'data' => DeploymentData::from([
109108
'dockerRegistryId' => null,
110109
'dockerImage' => 'caddy:2.8-alpine',

Diff for: app/Models/Deployment.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use App\Models\NodeTasks\ApplyCaddyConfig\ApplyCaddyConfigMeta;
1414
use App\Traits\HasOwningTeam;
1515
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
16+
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
1617
use Illuminate\Database\Eloquent\Relations\HasOne;
18+
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
1719
use Illuminate\Database\Query\Builder as QueryBuilder;
1820
use Illuminate\Database\Eloquent\Casts\Json;
1921
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -42,9 +44,14 @@ public function service(): BelongsTo
4244
return $this->belongsTo(Service::class);
4345
}
4446

45-
public function taskGroup(): BelongsTo
47+
public function taskGroups(): HasManyThrough
4648
{
47-
return $this->belongsTo(NodeTaskGroup::class);
49+
return $this->hasManyThrough(NodeTaskGroup::class, NodeTask::class, 'meta__deployment_id', 'id', 'id', 'task_group_id')->orderByDesc('id');
50+
}
51+
52+
public function latestTaskGroup(): HasOneThrough
53+
{
54+
return $this->hasOneThrough(NodeTaskGroup::class, NodeTask::class, 'meta__deployment_id', 'id', 'id', 'task_group_id')->latest();
4855
}
4956

5057
public function previousDeployment(): ?Deployment

Diff for: app/Models/NodeTasks/CreateService/CreateServiceMeta.php

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class CreateServiceMeta extends AbstractTaskMeta
88
{
99
public function __construct(
10+
public int $deploymentId,
1011
public int $serviceId,
1112
public string $serviceName
1213
)

Diff for: app/Models/Service.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function swarm(): BelongsTo
3535

3636
public function deployments(): HasMany
3737
{
38-
return $this->hasMany(Deployment::class);
38+
return $this->hasMany(Deployment::class)->orderByDesc('id');
3939
}
4040

4141
public function latestDeployment(): HasOne
@@ -57,7 +57,6 @@ public function deploy(DeploymentData $deploymentData): Deployment
5757
]);
5858

5959
$deployment = $this->deployments()->create([
60-
'task_group_id' => $taskGroup->id,
6160
'data' => $deploymentData,
6261
]);
6362

Diff for: composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"tightenco/ziggy": "^2.0"
1616
},
1717
"require-dev": {
18+
"barryvdh/laravel-debugbar": "^3.13",
1819
"fakerphp/faker": "^1.23",
1920
"laravel/pint": "^1.13",
2021
"laravel/sail": "^1.26",

Diff for: composer.lock

+154-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('deployments', function (Blueprint $table) {
15+
$table->dropColumn('task_group_id');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('deployments', function (Blueprint $table) {
25+
$table->foreignId('task_group_id')->constrained()->cascadeOnDelete();
26+
});
27+
}
28+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('node_tasks', function (Blueprint $table) {
15+
$table->foreignId('meta__deployment_id')
16+
->nullable()
17+
->storedAs('("meta"->\'deploymentId\')::int')
18+
->constrained('deployments')
19+
->cascadeOnDelete();
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*/
26+
public function down(): void
27+
{
28+
Schema::table('node_tasks', function (Blueprint $table) {
29+
$table->dropColumn('meta__deployment_id');
30+
});
31+
}
32+
};

Diff for: resources/js/Components/NodeTasks/TaskGroup.vue

+12-10
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ const retry = () => {
1515
</script>
1616

1717
<template>
18-
<ul class="col-span-6 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600 dark:text-white">
19-
<TaskResult v-for="task in taskGroup.tasks" :key="task.id" :task="task" />
20-
</ul>
21-
<div class="flex">
22-
<div class="col-span-6 ms-4 mt-1 text-xs text-gray-900 dark:text-white grow">#{{ taskGroup.id }} Invoked by {{ taskGroup.invoker.name }}</div>
23-
<SecondaryButton v-if="taskGroup.status === 'failed' || taskGroup.status === 'canceled'"
24-
@click="retry"
25-
class="col-span-6 ms-4 mt-2 text-xs text-gray-900 dark:text-white">
26-
Retry Failed Tasks
27-
</SecondaryButton>
18+
<div>
19+
<ul class="col-span-6 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600 dark:text-white">
20+
<TaskResult v-for="task in taskGroup.tasks" :key="task.id" :task="task" />
21+
</ul>
22+
<div class="flex">
23+
<div class="col-span-6 ms-4 mt-1 text-xs text-gray-900 dark:text-white grow">#{{ taskGroup.id }} Invoked by {{ taskGroup.invoker.name }} on {{ taskGroup.created_at }}</div>
24+
<SecondaryButton v-if="taskGroup.status === 'failed' || taskGroup.status === 'canceled'"
25+
@click="retry"
26+
class="col-span-6 ms-4 mt-2 text-xs text-gray-900 dark:text-white">
27+
Retry Failed Tasks
28+
</SecondaryButton>
29+
</div>
2830
</div>
2931
</template>

Diff for: resources/js/Pages/Services/Deployments.vue

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
<script setup>
2+
import ShowLayout from "@/Pages/Services/ShowLayout.vue";
3+
import TaskGroup from "@/Components/NodeTasks/TaskGroup.vue";
4+
5+
const props = defineProps({
6+
service: Object,
7+
})
8+
</script>
9+
110
<template>
2-
So, your service has been created. Now you can look after your deployments!
3-
</template>
11+
<ShowLayout :service="$props.service">
12+
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
13+
<div v-for="(deployment, index) in service.deployments" class="my-8 first-of-type:mt-0">
14+
<div class="ps-4 font-extrabold">Deployment #{{deployment.id}}
15+
<span v-if="index === 0">(latest)</span>
16+
</div>
17+
18+
<TaskGroup :task-group="deployment.latest_task_group" class="mt-4" />
19+
</div>
20+
</div>
21+
</ShowLayout>
22+
</template>

0 commit comments

Comments
 (0)