Skip to content

Commit

Permalink
chore: show docker compose project
Browse files Browse the repository at this point in the history
  • Loading branch information
mdvanes committed Apr 16, 2024
1 parent 8f1db07 commit e4b1372
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 30 deletions.
10 changes: 7 additions & 3 deletions apps/client/src/Components/Molecules/DockerInfo/DockerInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DockerContainerInfo } from "@homeremote/types";
import {
Alert,
Button,
Expand All @@ -10,15 +11,14 @@ import {
} from "@mui/material";
import { FC, useState } from "react";
import {
DockerContainerInfo,
useStartDockerMutation,
useStopDockerMutation,
} from "../../../Services/dockerListApi";

const DockerInfo: FC<{ info: DockerContainerInfo }> = ({ info }) => {
const [startDocker] = useStartDockerMutation();
const [stopDocker] = useStopDockerMutation();
const { Names, Status, Id, State } = info;
const { Names, Status, Id, State, Labels } = info;
const isUp = Status.indexOf("Up") === 0;

const toggleContainer = () => {
Expand Down Expand Up @@ -50,7 +50,11 @@ const DockerInfo: FC<{ info: DockerContainerInfo }> = ({ info }) => {
cursor: "pointer",
}}
>
{name} | {Status}
{name}{" "}
{Labels["com.docker.compose.project"]
? `(${Labels["com.docker.compose.project"]})`
: ""}{" "}
| {Status}
</Alert>
<Dialog
open={open}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DockerContainerInfo } from "@homeremote/types";
import { Box } from "@mui/material";
import { FC } from "react";
import { DockerContainerInfo } from "../../../Services/dockerListApi";

const ContainerDot: FC<{ info: DockerContainerInfo }> = ({ info }) => (
<Box
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { DockerContainerInfo } from "@homeremote/types";
import { Box, Grid } from "@mui/material";
import { Stack } from "@mui/system";
import { FC, useEffect, useState } from "react";
import {
DockerContainerInfo,
useGetDockerListQuery,
} from "../../../Services/dockerListApi";
import { useGetDockerListQuery } from "../../../Services/dockerListApi";
import { getErrorMessage } from "../../../Utils/getErrorMessage";
import CardExpandBar from "../CardExpandBar/CardExpandBar";
import DockerInfo from "../DockerInfo/DockerInfo";
Expand Down
13 changes: 1 addition & 12 deletions apps/client/src/Services/dockerListApi.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/dist/query/react";
import { willAddCredentials } from "../devUtils";

export interface DockerContainerInfo {
Id: string;
Names: string[];
State: string;
Status: string;
}

interface DockerListResponse {
status: "received" | "error";
containers?: DockerContainerInfo[];
}
import { DockerListResponse } from "@homeremote/types";

interface ToggleArgs {
id: string;
Expand Down
32 changes: 22 additions & 10 deletions apps/server/src/dockerlist/dockerlist.controller.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
import {
AllResponse,
DockerContainerInfo,
DockerListResponse,
} from "@homeremote/types";
import {
Controller,
Logger,
UseGuards,
Get,
Param,
HttpException,
HttpStatus,
Logger,
Param,
UseGuards,
} from "@nestjs/common";
import { JwtAuthGuard } from "../auth/jwt-auth.guard";
import got from "got";
import {
DockerContainerInfo,
AllResponse,
DockerListResponse,
} from "@homeremote/types";
import { JwtAuthGuard } from "../auth/jwt-auth.guard";

const pickAndMapContainerProps = ({
Id,
Names,
State,
Status,
}: DockerContainerInfo): DockerContainerInfo => ({ Id, Names, State, Status });
Labels,
}: DockerContainerInfo): DockerContainerInfo => ({
Id,
Names,
State,
Status,
Labels: {
"com.docker.compose.project": Labels["com.docker.compose.project"],
},
});

// Using Docker Engine API: curl --unix-socket /var/run/docker.sock http://v1.24/containers/json?all=true
// These urls also work: http://localhost/v1.24/containers/json?all=true or v1.24/containers/json?all=true
Expand All @@ -44,6 +53,9 @@ export class DockerlistController {
const result = await got(`${ROOT_URL}/json?all=true`, {
socketPath: SOCKET_PATH,
}).json<AllResponse>();
this.logger.verbose(
result.map((r) => r.Labels["com.docker.compose.project"])
);
return {
status: "received",
containers: result.map(pickAndMapContainerProps),
Expand Down
3 changes: 3 additions & 0 deletions libs/types/src/lib/dockerlist.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export interface DockerContainerInfo {
Names: string[];
State: string;
Status: string;
Labels: {
"com.docker.compose.project": string | null;
};
}

export type AllResponse = DockerContainerInfo[];
Expand Down

0 comments on commit e4b1372

Please sign in to comment.