Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add devcontainer in the UI#16800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 10 commits intomainfrombq/devcontainer
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletionssite/src/api/api.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2374,6 +2374,14 @@ class ApiMethods {
);
}
};

getAgentContainers = async (agentId: string) => {
const res =
await this.axios.get<TypesGen.WorkspaceAgentListContainersResponse>(
`/api/v2/workspaceagents/${agentId}/containers`,
);
return res.data;
};
}

// This is a hard coded CSRF token/cookie pair for local development. In prod,
Expand Down
73 changes: 73 additions & 0 deletionssite/src/modules/resources/AgentDevcontainerCard.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
import Link from "@mui/material/Link";
import type { Workspace, WorkspaceAgentDevcontainer } from "api/typesGenerated";
import { ExternalLinkIcon } from "lucide-react";
import type { FC } from "react";
import { portForwardURL } from "utils/portForward";
import { AgentButton } from "./AgentButton";
import { AgentDevcontainerSSHButton } from "./SSHButton/SSHButton";
import { TerminalLink } from "./TerminalLink/TerminalLink";

type AgentDevcontainerCardProps = {
container: WorkspaceAgentDevcontainer;
workspace: Workspace;
host: string;
agentName: string;
};

export const AgentDevcontainerCard: FC<AgentDevcontainerCardProps> = ({
container,
workspace,
agentName,
host,
}) => {
return (
<section
className="border border-border border-dashed rounded p-6 "
key={container.id}
>
<header className="flex justify-between">
<h3 className="m-0 text-xs font-medium text-content-secondary">
{container.name}
</h3>

<AgentDevcontainerSSHButton
workspace={workspace.name}
container={container.name}
/>
</header>

<h4 className="m-0 text-xl font-semibold">Forwarded ports</h4>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What do you think about removing this?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I personally like that. I would think on removing it later on when we have more things to display on the screen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe it could be a little smaller? This is just a nit though, and I'm totally fine with leaving it as-is.


<div className="flex gap-4 flex-wrap mt-4">
<TerminalLink
workspaceName={workspace.name}
agentName={agentName}
containerName={container.name}
userName={workspace.owner_name}
/>
{container.ports.map((port) => {
return (
<Link
key={port.port}
color="inherit"
component={AgentButton}
underline="none"
startIcon={<ExternalLinkIcon className="size-icon-sm" />}
href={portForwardURL(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think we should only showportForwardURL if wildcard hostname is set. Otherwise you get a URL likehttp://localhost:12345 which won't work.

BrunoQuaresma reacted with thumbs up emoji
Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fixed ✅

host,
port.port,
agentName,
workspace.name,
workspace.owner_name,
location.protocol === "https" ? "https" : "http",
Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@johnstcn should we return the port protocol in the response? Here, I'm just using whatever the user is currently using in the UI but maybe, some apps use HTTP instead of HTTPS... I'm not sure if it makes sense tho 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think it's always going to be the same protocol as the Coder deployment?

If not, we can get that fromportAttributes:https://containers.dev/implementors/json_reference/#port-attributes

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think it's always going to be the same protocol as the Coder deployment?

I'm not sure but would be safest to rely in the devcontainer config.

)}
>
{port.process_name ||
`${port.port}/${port.network.toUpperCase()}`}
</Link>
);
})}
</div>
</section>
);
};
29 changes: 27 additions & 2 deletionssite/src/modules/resources/AgentRow.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ import Button from "@mui/material/Button";
import Collapse from "@mui/material/Collapse";
import Divider from "@mui/material/Divider";
import Skeleton from "@mui/material/Skeleton";
import { API } from "api/api";
import { xrayScan } from "api/queries/integrations";
import type {
Template,
Expand All@@ -25,6 +26,7 @@ import {
import { useQuery } from "react-query";
import AutoSizer from "react-virtualized-auto-sizer";
import type { FixedSizeList as List, ListOnScrollProps } from "react-window";
import { AgentDevcontainerCard } from "./AgentDevcontainerCard";
import { AgentLatency } from "./AgentLatency";
import { AGENT_LOG_LINE_HEIGHT } from "./AgentLogs/AgentLogLine";
import { AgentLogs } from "./AgentLogs/AgentLogs";
Expand All@@ -35,7 +37,7 @@ import { AgentVersion } from "./AgentVersion";
import { AppLink } from "./AppLink/AppLink";
import { DownloadAgentLogsButton } from "./DownloadAgentLogsButton";
import { PortForwardButton } from "./PortForwardButton";
import {SSHButton } from "./SSHButton/SSHButton";
import {AgentSSHButton } from "./SSHButton/SSHButton";
import { TerminalLink } from "./TerminalLink/TerminalLink";
import { VSCodeDesktopButton } from "./VSCodeDesktopButton/VSCodeDesktopButton";
import { XRayScanAlert } from "./XRayScanAlert";
Expand DownExpand Up@@ -152,6 +154,13 @@ export const AgentRow: FC<AgentRowProps> = ({
setBottomOfLogs(distanceFromBottom < AGENT_LOG_LINE_HEIGHT);
}, []);

const { data: containers } = useQuery({
queryKey: ["agents", agent.id, "containers"],
queryFn: () => API.getAgentContainers(agent.id),
enabled: agent.status === "connected",
select: (res) => res.containers,
});

return (
<Stack
key={agent.id}
Expand DownExpand Up@@ -191,7 +200,7 @@ export const AgentRow: FC<AgentRowProps> = ({
{showBuiltinApps && (
<div css={{ display: "flex" }}>
{!hideSSHButton && agent.display_apps.includes("ssh_helper") && (
<SSHButton
<AgentSSHButton
workspaceName={workspace.name}
agentName={agent.name}
sshPrefix={sshPrefix}
Expand DownExpand Up@@ -267,6 +276,22 @@ export const AgentRow: FC<AgentRowProps> = ({
</section>
)}

{containers && (
<section>
{containers.map((container) => {
return (
<AgentDevcontainerCard
key={container.id}
container={container}
workspace={workspace}
host={proxy.preferredWildcardHostname}
agentName={agent.name}
/>
);
})}
</section>
)}

<AgentMetadata
storybookMetadata={storybookAgentMetadata}
agent={agent}
Expand Down
10 changes: 5 additions & 5 deletionssite/src/modules/resources/SSHButton/SSHButton.stories.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,15 +2,15 @@ import type { Meta, StoryObj } from "@storybook/react";
import { userEvent, within } from "@storybook/test";
import { MockWorkspace, MockWorkspaceAgent } from "testHelpers/entities";
import { withDesktopViewport } from "testHelpers/storybook";
import {SSHButton } from "./SSHButton";
import {AgentSSHButton } from "./SSHButton";

const meta: Meta<typeofSSHButton> = {
title: "modules/resources/SSHButton",
component:SSHButton,
const meta: Meta<typeofAgentSSHButton> = {
title: "modules/resources/AgentSSHButton",
component:AgentSSHButton,
};

export default meta;
type Story = StoryObj<typeofSSHButton>;
type Story = StoryObj<typeofAgentSSHButton>;

export const Closed: Story = {
args: {
Expand Down
54 changes: 52 additions & 2 deletionssite/src/modules/resources/SSHButton/SSHButton.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,13 @@ import { type ClassName, useClassName } from "hooks/useClassName";
import type { FC } from "react";
import { docs } from "utils/docs";

export interfaceSSHButtonProps {
export interfaceAgentSSHButtonProps {
workspaceName: string;
agentName: string;
sshPrefix?: string;
}

export constSSHButton: FC<SSHButtonProps> = ({
export constAgentSSHButton: FC<AgentSSHButtonProps> = ({
workspaceName,
agentName,
sshPrefix,
Expand DownExpand Up@@ -82,6 +82,56 @@ export const SSHButton: FC<SSHButtonProps> = ({
);
};

export interface AgentDevcontainerSSHButtonProps {
workspace: string;
container: string;
}

export const AgentDevcontainerSSHButton: FC<
AgentDevcontainerSSHButtonProps
> = ({ workspace, container }) => {
const paper = useClassName(classNames.paper, []);

return (
<Popover>
<PopoverTrigger>
<Button
size="small"
variant="text"
endIcon={<KeyboardArrowDown />}
css={{ fontSize: 13, padding: "8px 12px" }}
>
Connect via SSH
</Button>
</PopoverTrigger>

<PopoverContent horizontal="right" classes={{ paper }}>
<HelpTooltipText>
Run the following commands to connect with SSH:
</HelpTooltipText>

<ol style={{ margin: 0, padding: 0 }}>
<Stack spacing={0.5} css={styles.codeExamples}>
<SSHStep
helpText="Connect to the container:"
codeExample={`coder ssh ${workspace} -c ${container}`}
/>
</Stack>
</ol>

<HelpTooltipLinksGroup>
<HelpTooltipLink href={docs("/install")}>
Install Coder CLI
</HelpTooltipLink>
<HelpTooltipLink href={docs("/user-guides/workspace-access#ssh")}>
SSH configuration
</HelpTooltipLink>
</HelpTooltipLinksGroup>
</PopoverContent>
</Popover>
);
};

interface SSHStepProps {
helpText: string;
codeExample: string;
Expand Down
14 changes: 10 additions & 4 deletionssite/src/modules/resources/TerminalLink/TerminalLink.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,9 +11,10 @@ export const Language = {
};

export interface TerminalLinkProps {
agentName?: TypesGen.WorkspaceAgent["name"];
userName?: TypesGen.User["username"];
workspaceName: TypesGen.Workspace["name"];
workspaceName: string;
agentName?: string;
userName?: string;
containerName?: string;
}

/**
Expand All@@ -27,11 +28,16 @@ export const TerminalLink: FC<TerminalLinkProps> = ({
agentName,
userName = "me",
workspaceName,
containerName,
}) => {
const params = new URLSearchParams();
if (containerName) {
params.append("container", containerName);
}
// Always use the primary for the terminal link. This is a relative link.
const href = `/@${userName}/${workspaceName}${
agentName ? `.${agentName}` : ""
}/terminal`;
}/terminal?${params.toString()}`;

return (
<Link
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp