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
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit961f7dd

Browse files
authored
Warn if coder-cli is not in PATH on Windows (#357)
* Warn if coder-cli not in PATH on Windows* Use safeexec to get windows path* Delete GOARCH=386 from windows build
1 parent6eb1887 commit961f7dd

File tree

6 files changed

+75
-18
lines changed

6 files changed

+75
-18
lines changed

‎.github/workflows/release.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222
-name:Upload windows
2323
uses:actions/upload-artifact@v2
2424
with:
25-
name:coder-cli-windows-386
26-
path:./ci/bin/coder-cli-windows-386.zip
25+
name:coder-cli-windows
26+
path:./ci/bin/coder-cli-windows.zip
2727
build_darwin:
2828
name:Build darwin binary
2929
runs-on:macos-latest
@@ -74,7 +74,7 @@ jobs:
7474
draft:true
7575
prerelease:false
7676
-name:Upload Linux Release
77-
id:upload-linux-release-asset
77+
id:upload-linux-release-asset
7878
uses:actions/upload-release-asset@v1
7979
env:
8080
GITHUB_TOKEN:${{ secrets.GITHUB_TOKEN }}
@@ -84,7 +84,7 @@ jobs:
8484
asset_name:coder-cli-linux-amd64.tar.gz
8585
asset_content_type:application/tar+gzip
8686
-name:Upload MacOS Release
87-
id:upload-macos-release-asset
87+
id:upload-macos-release-asset
8888
uses:actions/upload-release-asset@v1
8989
env:
9090
GITHUB_TOKEN:${{ secrets.GITHUB_TOKEN }}
@@ -94,12 +94,12 @@ jobs:
9494
asset_name:coder-cli-darwin-amd64.zip
9595
asset_content_type:application/zip
9696
-name:Upload Windows Release
97-
id:upload-windows-release-asset
97+
id:upload-windows-release-asset
9898
uses:actions/upload-release-asset@v1
9999
env:
100100
GITHUB_TOKEN:${{ secrets.GITHUB_TOKEN }}
101101
with:
102102
upload_url:${{ steps.create_release.outputs.upload_url }}
103-
asset_path:coder-cli-windows-386/coder-cli-windows-386.zip
104-
asset_name:coder-cli-windows-386.zip
103+
asset_path:coder-cli-windows/coder-cli-windows.zip
104+
asset_name:coder-cli-windows.zip
105105
asset_content_type:application/zip

‎Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ build/macos:
1414
# requires darwin
1515
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 ./ci/scripts/build.sh
1616
build/windows:
17-
CGO_ENABLED=0 GOOS=windowsGOARCH=386./ci/scripts/build.sh
17+
CGO_ENABLED=0 GOOS=windows ./ci/scripts/build.sh
1818
build/linux:
1919
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./ci/scripts/build.sh
2020

‎ci/scripts/build.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,26 @@ set -euo pipefail
88

99
cd"$(git rev-parse --show-toplevel)/ci/scripts"
1010

11-
tag=$(git describe --tags)
12-
13-
echo"--- building coder-cli for$GOOS-$GOARCH"
14-
15-
tmpdir=$(mktemp -d)
11+
tag="$(git describe --tags)"
12+
13+
flavor="$GOOS"
14+
if [["$GOOS"=="windows" ]];then
15+
# GOARCH causes bugs with the safeexec package on Windows.
16+
unset GOARCH
17+
else
18+
flavor+="-$GOARCH"
19+
fi
20+
echo"--- building coder-cli for$flavor"
21+
22+
tmpdir="$(mktemp -d)"
1623
go build -ldflags"-X cdr.dev/coder-cli/internal/version.Version=${tag}" -o"$tmpdir/coder" ../../cmd/coder
1724

1825
cp ../gon.json$tmpdir/gon.json
1926

2027
pushd"$tmpdir"
2128
case"$GOOS"in
2229
"windows")
23-
artifact="coder-cli-$GOOS-$GOARCH.zip"
30+
artifact="coder-cli-$GOOS.zip"
2431
mv coder coder.exe
2532
zip"$artifact" coder.exe
2633
;;

‎go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
cdr.dev/slogv1.4.1
77
cdr.dev/wsepv0.0.0-20200728013649-82316a09813f
88
github.com/briandowns/spinnerv1.16.0
9+
github.com/cli/safeexecv1.0.0
910
github.com/fatih/colorv1.12.0
1011
github.com/google/go-cmpv0.5.6
1112
github.com/gorilla/websocketv1.4.2

‎go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5O
7878
github.com/chzyer/readlinev0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
7979
github.com/chzyer/testv0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
8080
github.com/chzyer/testv0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
81+
github.com/cli/safeexecv1.0.0 h1:0VngyaIyqACHdcMNWfo6+KdUYnqEr2Sg+bSP1pdF+dI=
82+
github.com/cli/safeexecv1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
8183
github.com/client9/misspellv0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
8284
github.com/cncf/udpa/gov0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
8385
github.com/cncf/udpa/gov0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=

‎internal/cmd/configssh.go

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import (
1212
"sort"
1313
"strings"
1414

15-
"cdr.dev/coder-cli/pkg/clog"
16-
15+
"github.com/cli/safeexec"
1716
"github.com/spf13/cobra"
1817
"golang.org/x/xerrors"
1918

2019
"cdr.dev/coder-cli/coder-sdk"
2120
"cdr.dev/coder-cli/internal/coderutil"
21+
"cdr.dev/coder-cli/pkg/clog"
2222
)
2323

2424
constsshStartToken="# ------------START-CODER-ENTERPRISE-----------"
@@ -114,7 +114,7 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
114114
returnxerrors.New("SSH is disabled or not available for any workspaces in your Coder deployment.")
115115
}
116116

117-
binPath,err:=os.Executable()
117+
binPath,err:=binPath()
118118
iferr!=nil {
119119
returnxerrors.Errorf("Failed to get executable path: %w",err)
120120
}
@@ -147,6 +147,53 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
147147
}
148148
}
149149

150+
// binPath returns the path to the coder binary suitable for use in ssh
151+
// ProxyCommand.
152+
funcbinPath() (string,error) {
153+
exePath,err:=os.Executable()
154+
iferr!=nil {
155+
return"",xerrors.Errorf("get executable path: %w",err)
156+
}
157+
158+
// On Windows, the coder-cli executable must be in $PATH for both Msys2/Git
159+
// Bash and OpenSSH for Windows (used by Powershell and VS Code) to function
160+
// correctly. Check if the current executable is in $PATH, and warn the user
161+
// if it isn't.
162+
ifruntime.GOOS=="windows" {
163+
binName:=filepath.Base(exePath)
164+
165+
// We use safeexec instead of os/exec because os/exec returns paths in
166+
// the current working directory, which we will run into very often when
167+
// looking for our own path.
168+
pathPath,err:=safeexec.LookPath(binName)
169+
iferr!=nil {
170+
clog.LogWarn(
171+
"The current executable is not in $PATH.",
172+
"This may lead to problems connecting to your workspace via SSH.",
173+
fmt.Sprintf("Please move %q to a location in your $PATH (such as System32) and run `%s config-ssh` again.",binName,binName),
174+
)
175+
// Return the exePath so SSH at least works outside of Msys2.
176+
returnexePath,nil
177+
}
178+
179+
// Warn the user if the current executable is not the same as the one in
180+
// $PATH.
181+
iffilepath.Clean(pathPath)!=filepath.Clean(exePath) {
182+
clog.LogWarn(
183+
"The current executable path does not match the executable path found in $PATH.",
184+
"This may lead to problems connecting to your workspace via SSH.",
185+
fmt.Sprintf("\t Current executable path: %q",exePath),
186+
fmt.Sprintf("\tExecutable path in $PATH: %q",pathPath),
187+
)
188+
}
189+
190+
returnbinName,nil
191+
}
192+
193+
// On platforms other than Windows we can use the full path to the binary.
194+
returnexePath,nil
195+
}
196+
150197
// removeOldConfig removes the old ssh configuration from the user's sshconfig.
151198
// Returns true if the config was modified.
152199
funcremoveOldConfig(configstring) (string,bool) {
@@ -212,7 +259,7 @@ func makeSSHConfig(binPath, host, userName, workspaceName, privateKeyFilepath st
212259
host:=fmt.Sprintf(
213260
`Host coder.%s
214261
HostName coder.%s
215-
ProxyCommand%s tunnel %s 12213 stdio
262+
ProxyCommand"%s" tunnel %s 12213 stdio
216263
StrictHostKeyChecking no
217264
ConnectTimeout=0
218265
IdentitiesOnly yes

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp