-
Notifications
You must be signed in to change notification settings - Fork 904
feat: Add port forward button #4167
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0732218
feat: Add port forward button
BrunoQuaresma 312ff4f
add initial docs
bpmct 0be1c2d
Apply suggestions from code review
BrunoQuaresma bc04ab7
Merge branch 'main' of github.com:coder/coder into bq/add-portforward…
BrunoQuaresma 7c0376f
Merge branch 'bq/add-portforward-to-ui-2' of github.com:coder/coder i…
BrunoQuaresma 52a122a
add docs screenshot
bpmct 8df3d3d
Update site/src/components/PortForwardButton/PortForwardButton.tsx
BrunoQuaresma 5a62aff
Fix formatting and host test
BrunoQuaresma 1bf36e5
Merge branch 'bq/add-portforward-to-ui-2' of github.com:coder/coder i…
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,10 @@ Port forwarding lets developers securely access processes on their Coder | |
workspace from a local machine. A common use case is testing web | ||
applications in a browser. | ||
|
||
There are two ways to forward ports in Coder: | ||
There are three ways to forward ports in Coder: | ||
|
||
- The `coder port-forward` command | ||
- Dashboard | ||
- SSH | ||
|
||
The `coder port-forward` command is generally more performant. | ||
|
@@ -21,6 +22,16 @@ coder port-forward myworkspace --tcp 8000:8080 | |
|
||
For more examples, see `coder port-forward --help`. | ||
|
||
## Dashboard | ||
|
||
> To enable port forwarding via the dashboard, Coder must be configured with a | ||
> [wildcard access URL](./admin/configure#wildcard-access-url). | ||
|
||
Use the "Port forward" button in the dashboard to access ports | ||
running on your workspace. | ||
|
||
 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Screenshot should read |
||
|
||
## SSH | ||
|
||
First, [configure SSH](../ides.md#ssh-configuration) on your | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
site/src/components/PortForwardButton/PortForwardButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import Button from "@material-ui/core/Button" | ||
import Link from "@material-ui/core/Link" | ||
import Popover from "@material-ui/core/Popover" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import TextField from "@material-ui/core/TextField" | ||
import OpenInNewOutlined from "@material-ui/icons/OpenInNewOutlined" | ||
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne" | ||
import { Stack } from "components/Stack/Stack" | ||
import { useRef, useState } from "react" | ||
import { colors } from "theme/colors" | ||
import { CodeExample } from "../CodeExample/CodeExample" | ||
import { HelpTooltipLink, HelpTooltipLinksGroup, HelpTooltipText } from "../Tooltips/HelpTooltip" | ||
|
||
export interface PortForwardButtonProps { | ||
host: string | ||
username: string | ||
workspaceName: string | ||
agentName: string | ||
} | ||
|
||
const EnabledView: React.FC<PortForwardButtonProps> = (props) => { | ||
const { host, workspaceName, agentName, username } = props | ||
const styles = useStyles() | ||
const [port, setPort] = useState("3000") | ||
const { location } = window | ||
const urlExample = `${location.protocol}//${port}--${agentName}--${workspaceName}--${username}.${host}` | ||
|
||
return ( | ||
<Stack direction="column" spacing={1}> | ||
<HelpTooltipText> | ||
Access ports running on the agent with the <strong>port, agent name, workspace name</strong>{" "} | ||
and <strong>your username</strong> URL schema, as shown below. | ||
</HelpTooltipText> | ||
|
||
<CodeExample code={urlExample} /> | ||
|
||
<HelpTooltipText>Use the form to open applications in a new tab.</HelpTooltipText> | ||
|
||
<Stack direction="row" spacing={1} alignItems="center"> | ||
<TextField | ||
label="Port" | ||
type="number" | ||
value={port} | ||
className={styles.portField} | ||
onChange={(e) => { | ||
setPort(e.currentTarget.value) | ||
}} | ||
/> | ||
<Link | ||
underline="none" | ||
href={urlExample} | ||
target="_blank" | ||
rel="noreferrer" | ||
className={styles.openUrlButton} | ||
> | ||
<Button>Open URL</Button> | ||
</Link> | ||
</Stack> | ||
|
||
<HelpTooltipLinksGroup> | ||
<HelpTooltipLink href="https://coder.com/docs/coder-oss/latest/networking/port-forward#dashboard"> | ||
Learn more about port forward | ||
</HelpTooltipLink> | ||
</HelpTooltipLinksGroup> | ||
</Stack> | ||
) | ||
} | ||
|
||
const DisabledView: React.FC<PortForwardButtonProps> = () => { | ||
return ( | ||
<Stack direction="column" spacing={1}> | ||
<HelpTooltipText> | ||
<strong>Your deployment does not have port forward enabled.</strong> See the docs for more | ||
details. | ||
</HelpTooltipText> | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<HelpTooltipLinksGroup> | ||
<HelpTooltipLink href="https://coder.com/docs/coder-oss/latest/networking/port-forwarding#dashboard"> | ||
Learn more about port forward | ||
</HelpTooltipLink> | ||
</HelpTooltipLinksGroup> | ||
</Stack> | ||
) | ||
} | ||
|
||
export const PortForwardButton: React.FC<PortForwardButtonProps> = (props) => { | ||
const { host } = props | ||
const anchorRef = useRef<HTMLButtonElement>(null) | ||
const [isOpen, setIsOpen] = useState(false) | ||
const id = isOpen ? "schedule-popover" : undefined | ||
const styles = useStyles() | ||
|
||
const onClose = () => { | ||
setIsOpen(false) | ||
} | ||
|
||
return ( | ||
<> | ||
<Button | ||
startIcon={<OpenInNewOutlined />} | ||
size="small" | ||
ref={anchorRef} | ||
onClick={() => { | ||
setIsOpen(true) | ||
}} | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> | ||
Port forward | ||
</Button> | ||
<Popover | ||
classes={{ paper: styles.popoverPaper }} | ||
id={id} | ||
open={isOpen} | ||
anchorEl={anchorRef.current} | ||
onClose={onClose} | ||
anchorOrigin={{ | ||
vertical: "bottom", | ||
horizontal: "left", | ||
}} | ||
transformOrigin={{ | ||
vertical: "top", | ||
horizontal: "left", | ||
}} | ||
> | ||
<ChooseOne> | ||
<Cond condition={host !== ""}> | ||
<EnabledView {...props} /> | ||
</Cond> | ||
<Cond condition={host === ""}> | ||
<DisabledView {...props} /> | ||
bpmct marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Cond> | ||
</ChooseOne> | ||
</Popover> | ||
</> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
popoverPaper: { | ||
padding: `${theme.spacing(2.5)}px ${theme.spacing(3.5)}px ${theme.spacing(3.5)}px`, | ||
width: theme.spacing(46), | ||
color: theme.palette.text.secondary, | ||
marginTop: theme.spacing(0.25), | ||
}, | ||
|
||
openUrlButton: { | ||
flexShrink: 0, | ||
}, | ||
|
||
portField: { | ||
// The default border don't contrast well with the popover | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"& .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline": { | ||
borderColor: colors.gray[10], | ||
}, | ||
}, | ||
})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.