-
Notifications
You must be signed in to change notification settings - Fork 268
/
ComposeDetails.svelte
102 lines (90 loc) · 3.52 KB
/
ComposeDetails.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<script lang="ts">
import Route from '../../Route.svelte';
import ComposeIcon from '../images/PodIcon.svelte';
import StatusIcon from '../images/StatusIcon.svelte';
import ComposeActions from './ComposeActions.svelte';
import type { Unsubscriber } from 'svelte/store';
import { onDestroy, onMount } from 'svelte';
import { containersInfos } from '/@/stores/containers';
import type { ComposeInfoUI } from './ComposeInfoUI';
import { ContainerUtils } from '../container/container-utils';
import ComposeDetailsLogs from './ComposeDetailsLogs.svelte';
import type { ContainerInfoUI } from '../container/ContainerInfoUI';
import DetailsPage from '../ui/DetailsPage.svelte';
import Tab from '../ui/Tab.svelte';
export let composeName: string;
export let engineId: string;
const containerUtils = new ContainerUtils();
let composeUnsubscribe: Unsubscriber;
let compose: ComposeInfoUI;
// Assume that the engine type is podman until we find a compose group that is docker
let engineType: 'docker' | 'podman' = 'podman';
onMount(() => {
// We will use the containersInfos store to get every container that matches
// the label com.docker.compose.project={composeName}
// We only care about the status. Check each containersMatchingProject status and if every container is RUNNING, set status to RUNNING,
// else let status be 'STOPPED'
composeUnsubscribe = containersInfos.subscribe(containers => {
let convertedContainers: ContainerInfoUI[];
let status: string;
// Get all containers that match the composeName we are looking at
const containersMatchingProject = containers.filter(container => {
return container?.Labels['com.docker.compose.project'] === composeName;
});
// Update our current status
if (containersMatchingProject.length === 0) {
status = 'STOPPED';
} else {
const allRunning = containersMatchingProject.every(container => {
return container?.State === 'running';
});
if (allRunning) {
status = 'RUNNING';
} else {
status = 'STOPPED';
}
}
// Convert each matching container to the ComposeInfoContainerUI type and add it to compose.containers
convertedContainers = containersMatchingProject.map(container => {
return containerUtils.getContainerInfoUI(container);
});
// Get the engine type from the first container in the list (if it exists)
if (convertedContainers.length > 0) {
engineType = convertedContainers[0].engineType;
}
// Make sure we update the compose object with the name, status, engineID, containers, etc.
// or else logging will not appear correctly when loading (it'll see empty containers..)
compose = {
name: composeName,
engineId: engineId,
engineType: engineType,
status: status,
containers: convertedContainers,
};
});
});
onDestroy(() => {
if (composeUnsubscribe) {
composeUnsubscribe();
}
});
</script>
{#if compose}
<DetailsPage title="{composeName}" subtitle="">
<StatusIcon slot="icon" icon="{ComposeIcon}" status="{compose.status}" />
<svelte:fragment slot="actions">
<div class="flex items-center w-5">
<div> </div>
</div>
<ComposeActions compose="{compose}" detailed="{true}" />
</svelte:fragment>
<svelte:fragment slot="tabs">
<Tab title="Logs" url="logs" />
</svelte:fragment>
<svelte:fragment slot="content">
<Route path="/logs" breadcrumb="Logs" navigationHint="tab">
<ComposeDetailsLogs compose="{compose}" />
</Route>
</svelte:fragment>
</DetailsPage>
{/if}