feat: Add network_mode: host to docker-compose.base.yml

This commit adds the `network_mode: host` configuration to the `docker-compose.base.yml` file. This configuration allows the container to share the host network stack, enabling direct access to the host's network interfaces. This change is made to improve network performance and connectivity for the application.
This commit is contained in:
Simon Larsen 2024-07-14 13:58:48 -06:00
parent 71151ea92e
commit da67dc6930
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA
13 changed files with 254 additions and 36 deletions

View File

@ -8,6 +8,7 @@ import Express, {
ExpressResponse,
ExpressStatic,
} from "CommonServer/Utils/Express";
import Response from "CommonServer/Utils/Response";
import LocalFile from "CommonServer/Utils/LocalFile";
import logger from "CommonServer/Utils/Logger";
import "ejs";
@ -20,6 +21,27 @@ const DocsFeatureSet: FeatureSet = {
res.redirect("/docs/introduction/getting-started");
});
app.get(
"/docs/as-markdown/:categorypath/:pagepath",
async (req: ExpressRequest, res: ExpressResponse) => {
try {
const fullPath: string =
`${req.params["categorypath"]}/${req.params["pagepath"]}`.toLowerCase();
// read file from Content folder.
const contentInMarkdown: string = await LocalFile.read(
`${ContentPath}/${fullPath}.md`,
);
return Response.sendMarkdownResponse(req, res, contentInMarkdown);
} catch (err) {
logger.error(err);
res.status(500);
return res.send("Internal Server Error");
}
},
);
app.get(
"/docs/:categorypath/:pagepath",
async (_req: ExpressRequest, res: ExpressResponse) => {

View File

@ -263,6 +263,14 @@ export default class Response {
oneUptimeResponse.end(html);
}
public static sendMarkdownResponse(
_req: ExpressRequest,
res: ExpressResponse,
html: string,
): void {
return Response.sendHtmlResponse(_req, res, html);
}
public static sendXmlResponse(
_req: ExpressRequest,
res: ExpressResponse,

View File

@ -54,7 +54,7 @@ const MarkdownViewer: FunctionComponent<ComponentProps> = (
pre: ({ ...props }: any) => {
return (
<pre
className="bg-gray-50 text-gray-600 p-3 mt-4 mb-2 rounded text-sm text-sm overflow-x-auto"
className="bg-gray-50 text-gray-600 p-3 mt-4 mb-2 rounded text-sm text-sm overflow-x-auto flex"
{...props}
/>
);

View File

@ -0,0 +1,33 @@
import React, { FunctionComponent, ReactElement } from "react";
import Alert, { AlertType } from "CommonUI/src/Components/Alerts/Alert";
import OneUptimeDate from "Common/Types/Date";
export interface ComponentProps {
lastRunAt?: undefined | Date;
}
const CopilotLastRunAt: FunctionComponent<ComponentProps> = (
props: ComponentProps,
): ReactElement => {
return (
<>
{props.lastRunAt && (
<Alert
type={AlertType.INFO}
strongTitle="Last Run At: "
title={`${OneUptimeDate.getDateAsLocalFormattedString(props.lastRunAt)}.`}
/>
)}
{!props.lastRunAt && (
<Alert
type={AlertType.INFO}
strongTitle="Copilot Did Not Run Yet"
title={`Please run the copilot to fix and improve your code.`}
/>
)}
</>
);
};
export default CopilotLastRunAt;

View File

@ -0,0 +1,126 @@
import ObjectID from "Common/Types/ObjectID";
import Card from "CommonUI/src/Components/Card/Card";
import React, {
Fragment,
FunctionComponent,
ReactElement,
useEffect,
useState,
} from "react";
import PageComponentProps from "../../../PageComponentProps";
import Navigation from "CommonUI/src/Utils/Navigation";
import CopilotCodeRepository from "Model/Models/CopilotCodeRepository";
import { PromiseVoidFunction } from "Common/Types/FunctionTypes";
import ModelAPI from "CommonUI/src/Utils/ModelAPI/ModelAPI";
import API from "CommonUI/src/Utils/API/API";
import PageLoader from "CommonUI/src/Components/Loader/PageLoader";
import ErrorMessage from "CommonUI/src/Components/ErrorMessage/ErrorMessage";
import MarkdownViewer from "CommonUI/src/Components/Markdown.tsx/MarkdownViewer";
import URL from "Common/Types/API/URL";
import { DOCS_URL } from "CommonUI/src/Config";
import HTTPErrorResponse from "Common/Types/API/HTTPErrorResponse";
import HTTPResponse from "Common/Types/API/HTTPResponse";
import { JSONObject } from "Common/Types/JSON";
const CopilotDocuementationPage: FunctionComponent<
PageComponentProps
> = (): ReactElement => {
const codeRepositoryId: ObjectID = Navigation.getLastParamAsObjectID(1);
const [documentation, setDocumentation] = useState<string | null>(null);
// get code repository
const [codeRepository, setCodeRepository] =
useState<CopilotCodeRepository | null>(null);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [error, setError] = useState<string | null>(null);
const fetchCodeRepositoryAndDocumentation: PromiseVoidFunction =
async (): Promise<void> => {
// get item.
setIsLoading(true);
setError("");
try {
const item: CopilotCodeRepository | null = await ModelAPI.getItem({
modelType: CopilotCodeRepository,
id: codeRepositoryId,
select: {
repositoryHostedAt: true,
repositoryName: true,
organizationName: true,
lastCopilotRunDateTime: true,
},
});
if (!item) {
setError(`Code Repository not found`);
return;
}
// Send api request to get documentation
// http://localhost/docs/copilot/introduction
const documentation: HTTPErrorResponse | HTTPResponse<JSONObject> =
(await API.get(
URL.fromString(DOCS_URL.toString()).addRoute(
"/as-markdown/copilot/introduction",
),
)) as HTTPErrorResponse | HTTPResponse<JSONObject>;
if (documentation instanceof HTTPErrorResponse) {
setError(API.getFriendlyMessage(documentation));
}
if (documentation.data && documentation.data["data"]) {
setDocumentation(
(documentation.data as JSONObject)["data"] as string,
);
}
setCodeRepository(item);
} catch (err) {
setError(API.getFriendlyMessage(err));
}
setIsLoading(false);
};
useEffect(() => {
fetchCodeRepositoryAndDocumentation().catch((err: Error) => {
setError(API.getFriendlyMessage(err));
});
}, []);
if (isLoading) {
return <PageLoader isVisible={true} />;
}
if (error) {
return <ErrorMessage error={error} />;
}
if (!codeRepository) {
return <ErrorMessage error={"Code Repository not found"} />;
}
if (!documentation) {
return <ErrorMessage error={"Documentation not found"} />;
}
return (
<Fragment>
<Card
title={``}
description={
<div className="space-y-2 w-full mt-5">
<MarkdownViewer text={documentation || ""} />
</div>
}
/>
</Fragment>
);
};
export default CopilotDocuementationPage;

View File

@ -1,9 +1,7 @@
import LabelsElement from "../../../../Components/Label/Labels";
import PageComponentProps from "../../../PageComponentProps";
import CodeRepositoryType from "Common/Types/CodeRepository/CodeRepositoryType";
import OneUptimeDate from "Common/Types/Date";
import ObjectID from "Common/Types/ObjectID";
import Alert, { AlertType } from "CommonUI/src/Components/Alerts/Alert";
import FormFieldSchemaType from "CommonUI/src/Components/Forms/Types/FormFieldSchemaType";
import CardModelDetail from "CommonUI/src/Components/ModelDetail/CardModelDetail";
import FieldType from "CommonUI/src/Components/Types/FieldType";
@ -17,6 +15,7 @@ import React, {
ReactElement,
useState,
} from "react";
import CopilotLastRunAt from "../../../../Components/Copilot/LastRunMessage";
const StatusPageView: FunctionComponent<
PageComponentProps
@ -30,21 +29,7 @@ const StatusPageView: FunctionComponent<
<Fragment>
{/* CopilotCodeRepository View */}
{codeRepository && codeRepository.lastCopilotRunDateTime && (
<Alert
type={AlertType.INFO}
strongTitle="Last Run At: "
title={`${OneUptimeDate.getDateAsLocalFormattedString(codeRepository.lastCopilotRunDateTime)}. Please re-run copilot to update data.`}
/>
)}
{codeRepository && !codeRepository.lastCopilotRunDateTime && (
<Alert
type={AlertType.INFO}
strongTitle="Last Run At: "
title={`No copilot run has been executed for this code repository. Please run copilot to update data.`}
/>
)}
<CopilotLastRunAt lastRunAt={codeRepository?.lastCopilotRunDateTime} />
<CardModelDetail<CopilotCodeRepository>
name="Git Repository > Repository Details"
@ -160,7 +145,9 @@ const StatusPageView: FunctionComponent<
lastCopilotRunDateTime: true,
},
onItemLoaded: (item: CopilotCodeRepository) => {
setCodeRepository(item);
if (!codeRepository) {
setCodeRepository(item);
}
},
showDetailsInNumberOfColumns: 2,
modelType: CopilotCodeRepository,

View File

@ -21,9 +21,8 @@ import ErrorMessage from "CommonUI/src/Components/ErrorMessage/ErrorMessage";
import ModelAPI from "CommonUI/src/Utils/ModelAPI/ModelAPI";
import API from "CommonUI/src/Utils/API/API";
import PullRequestViewElement from "../../../../Components/CodeRepository/PullRequestView";
import Alert, { AlertType } from "CommonUI/src/Components/Alerts/Alert";
import OneUptimeDate from "Common/Types/Date";
import { PromiseVoidFunction } from "Common/Types/FunctionTypes";
import CopilotLastRunAt from "../../../../Components/Copilot/LastRunMessage";
const CopilotPullRequestPage: FunctionComponent<
PageComponentProps
@ -85,21 +84,7 @@ const CopilotPullRequestPage: FunctionComponent<
return (
<Fragment>
{codeRepository.lastCopilotRunDateTime && (
<Alert
type={AlertType.INFO}
strongTitle="Last Run At: "
title={`${OneUptimeDate.getDateAsLocalFormattedString(codeRepository.lastCopilotRunDateTime)}. Please re-run copilot to update data.`}
/>
)}
{!codeRepository.lastCopilotRunDateTime && (
<Alert
type={AlertType.INFO}
strongTitle="Last Run At: "
title={`No copilot run has been executed for this code repository. Please run copilot to update data.`}
/>
)}
<CopilotLastRunAt lastRunAt={codeRepository?.lastCopilotRunDateTime} />
<ModelTable<CopilotPullRequest>
modelType={CopilotPullRequest}

View File

@ -40,6 +40,19 @@ const DashboardSideMenu: FunctionComponent<ComponentProps> = (
}}
icon={IconProp.SquareStack}
/>
<SideMenuItem
link={{
title: "Documentation",
to: RouteUtil.populateRouteParams(
RouteMap[
PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_DOCUMENTATION
] as Route,
{ modelId: props.modelId },
),
}}
icon={IconProp.Info}
/>
</SideMenuSection>
<SideMenuSection title="Code">

View File

@ -35,6 +35,12 @@ const CodeRepositoryViewPullRequests: LazyExoticComponent<
return import("../Pages/AICopilot/CodeRepository/View/PullRequests");
});
const CodeRepositoryViewDocumentation: LazyExoticComponent<
FunctionComponent<ComponentProps>
> = lazy(() => {
return import("../Pages/AICopilot/CodeRepository/View/Documentation");
});
const CodeRepositoryViewDelete: LazyExoticComponent<
FunctionComponent<ComponentProps>
> = lazy(() => {
@ -108,6 +114,24 @@ const CodeRepositoryRoutes: FunctionComponent<ComponentProps> = (
}
/>
<PageRoute
path={RouteUtil.getLastPathForKey(
PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_DOCUMENTATION,
)}
element={
<Suspense fallback={Loader}>
<CodeRepositoryViewDocumentation
{...props}
pageRoute={
RouteMap[
PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_DOCUMENTATION
] as Route
}
/>
</Suspense>
}
/>
<PageRoute
path={RouteUtil.getLastPathForKey(
PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_DELETE,

View File

@ -30,6 +30,15 @@ export function getCodeRepositoryBreadcrumbs(
"Pull Requests",
],
),
...BuildBreadcrumbLinksByTitles(
PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_DOCUMENTATION,
[
"Project",
"Reliability Copilot",
"View Git Repository",
"Documentation",
],
),
...BuildBreadcrumbLinksByTitles(
PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_SETTINGS,
["Project", "Reliability Copilot", "View Git Repository", "Settings"],

View File

@ -97,6 +97,7 @@ enum PageMap {
AI_COPILOT_CODE_REPOSITORY = "AI_COPILOT_CODE_REPOSITORY",
AI_COPILOT_CODE_REPOSITORY_VIEW = "AI_COPILOT_CODE_REPOSITORY_VIEW",
AI_COPILOT_CODE_REPOSITORY_VIEW_PULL_REQUESTS = "AI_COPILOT_CODE_REPOSITORY_VIEW_PULL_REQUESTS",
AI_COPILOT_CODE_REPOSITORY_VIEW_DOCUMENTATION = "AI_COPILOT_CODE_REPOSITORY_VIEW_DOCUMENTATION",
AI_COPILOT_CODE_REPOSITORY_VIEW_DELETE = "AI_COPILOT_CODE_REPOSITORY_VIEW_DELETE",
AI_COPILOT_CODE_REPOSITORY_VIEW_SETTINGS = "AI_COPILOT_CODE_REPOSITORY_VIEW_SETTINGS",
AI_COPILOT_CODE_REPOSITORY_VIEW_SERVICES = "AI_COPILOT_CODE_REPOSITORY_VIEW_SERVICES",

View File

@ -36,6 +36,7 @@ export const CodeRepositoryRoutePath: Dictionary<string> = {
[PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW]: `code-repository/${RouteParams.ModelID}`,
[PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_DELETE]: `code-repository/${RouteParams.ModelID}/delete`,
[PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_PULL_REQUESTS]: `code-repository/${RouteParams.ModelID}/pull-requests`,
[PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_DOCUMENTATION]: `code-repository/${RouteParams.ModelID}/documentation`,
[PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_SETTINGS]: `code-repository/${RouteParams.ModelID}/settings`,
[PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_SERVICES]: `code-repository/${RouteParams.ModelID}/services`,
};
@ -466,6 +467,14 @@ const RouteMap: Dictionary<Route> = {
}`,
),
[PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_DOCUMENTATION]: new Route(
`/dashboard/${RouteParams.ProjectID}/copilot/${
CodeRepositoryRoutePath[
PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_DOCUMENTATION
]
}`,
),
[PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_DELETE]: new Route(
`/dashboard/${RouteParams.ProjectID}/copilot/${
CodeRepositoryRoutePath[PageMap.AI_COPILOT_CODE_REPOSITORY_VIEW_DELETE]

View File

@ -378,6 +378,7 @@ services:
ONEUPTIME_LLM_SERVER_URL: ${COPILOT_ONEUPTIME_LLM_SERVER_URL}
DISABLE_COPILOT: ${DISABLE_COPILOT}
OPENAI_API_KEY: ${COPILOT_OPENAI_API_KEY}
network_mode: host
logging:
driver: "local"
options: