This repository was archived by the owner on Aug 30, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork18
Warn if coder-cli is not in PATH on Windows#357
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
2b838a9
Enforce coder-cli in PATH on Windows
deansheather74b7fa4
Warn if coder-cli not in PATH on Windows
deansheather4a7aca7
Use safeexec to get windows path
deansheather3746bf5
Delete GOARCH=386 from windows build
deansheather5da2fc0
Add comment to unset GOARCH
deansheatherFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
14 changes: 7 additions & 7 deletions.github/workflows/release.yaml
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
4 changes: 2 additions & 2 deletionsMakefile
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
19 changes: 13 additions & 6 deletionsci/scripts/build.sh
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 |
---|---|---|
@@ -8,19 +8,26 @@ set -euo pipefail | ||
cd "$(git rev-parse --show-toplevel)/ci/scripts" | ||
tag="$(git describe --tags)" | ||
flavor="$GOOS" | ||
if [[ "$GOOS" == "windows" ]]; then | ||
# GOARCH causes bugs with the safeexec package on Windows. | ||
unset GOARCH | ||
deansheather marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
else | ||
flavor+="-$GOARCH" | ||
fi | ||
echo "--- building coder-cli for $flavor" | ||
tmpdir="$(mktemp -d)" | ||
go build -ldflags "-X cdr.dev/coder-cli/internal/version.Version=${tag}" -o "$tmpdir/coder" ../../cmd/coder | ||
cp ../gon.json $tmpdir/gon.json | ||
pushd "$tmpdir" | ||
case "$GOOS" in | ||
"windows") | ||
artifact="coder-cli-$GOOS.zip" | ||
mv coder coder.exe | ||
zip "$artifact" coder.exe | ||
;; | ||
1 change: 1 addition & 0 deletionsgo.mod
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
2 changes: 2 additions & 0 deletionsgo.sum
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
55 changes: 51 additions & 4 deletionsinternal/cmd/configssh.go
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 |
---|---|---|
@@ -12,13 +12,13 @@ import ( | ||
"sort" | ||
"strings" | ||
"github.com/cli/safeexec" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/xerrors" | ||
"cdr.dev/coder-cli/coder-sdk" | ||
"cdr.dev/coder-cli/internal/coderutil" | ||
"cdr.dev/coder-cli/pkg/clog" | ||
) | ||
const sshStartToken = "# ------------START-CODER-ENTERPRISE-----------" | ||
@@ -114,7 +114,7 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st | ||
return xerrors.New("SSH is disabled or not available for any workspaces in your Coder deployment.") | ||
} | ||
binPath, err :=binPath() | ||
if err != nil { | ||
return xerrors.Errorf("Failed to get executable path: %w", err) | ||
} | ||
@@ -147,6 +147,53 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st | ||
} | ||
} | ||
// binPath returns the path to the coder binary suitable for use in ssh | ||
// ProxyCommand. | ||
func binPath() (string, error) { | ||
exePath, err := os.Executable() | ||
if err != nil { | ||
return "", xerrors.Errorf("get executable path: %w", err) | ||
} | ||
// On Windows, the coder-cli executable must be in $PATH for both Msys2/Git | ||
// Bash and OpenSSH for Windows (used by Powershell and VS Code) to function | ||
// correctly. Check if the current executable is in $PATH, and warn the user | ||
// if it isn't. | ||
if runtime.GOOS == "windows" { | ||
binName := filepath.Base(exePath) | ||
// We use safeexec instead of os/exec because os/exec returns paths in | ||
// the current working directory, which we will run into very often when | ||
// looking for our own path. | ||
pathPath, err := safeexec.LookPath(binName) | ||
deansheather marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if err != nil { | ||
clog.LogWarn( | ||
"The current executable is not in $PATH.", | ||
"This may lead to problems connecting to your workspace via SSH.", | ||
fmt.Sprintf("Please move %q to a location in your $PATH (such as System32) and run `%s config-ssh` again.", binName, binName), | ||
) | ||
// Return the exePath so SSH at least works outside of Msys2. | ||
return exePath, nil | ||
} | ||
// Warn the user if the current executable is not the same as the one in | ||
// $PATH. | ||
if filepath.Clean(pathPath) != filepath.Clean(exePath) { | ||
clog.LogWarn( | ||
"The current executable path does not match the executable path found in $PATH.", | ||
"This may lead to problems connecting to your workspace via SSH.", | ||
fmt.Sprintf("\t Current executable path: %q", exePath), | ||
fmt.Sprintf("\tExecutable path in $PATH: %q", pathPath), | ||
) | ||
} | ||
return binName, nil | ||
} | ||
// On platforms other than Windows we can use the full path to the binary. | ||
return exePath, nil | ||
} | ||
// removeOldConfig removes the old ssh configuration from the user's sshconfig. | ||
// Returns true if the config was modified. | ||
func removeOldConfig(config string) (string, bool) { | ||
@@ -212,7 +259,7 @@ func makeSSHConfig(binPath, host, userName, workspaceName, privateKeyFilepath st | ||
host := fmt.Sprintf( | ||
`Host coder.%s | ||
HostName coder.%s | ||
ProxyCommand"%s" tunnel %s 12213 stdio | ||
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. Do the quotes work on Linux too? Ithought I tried it before... 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. Works on windows, mac and linux from my testing. | ||
StrictHostKeyChecking no | ||
ConnectTimeout=0 | ||
IdentitiesOnly yes | ||
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.