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

Commit550ba6f

Browse files
committed
Fix Windows support
1 parent1c753dc commit550ba6f

File tree

10 files changed

+42
-20
lines changed

10 files changed

+42
-20
lines changed

‎agent/agent.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func (s *agent) init(ctx context.Context) {
185185
gos.run(ctx)
186186
}
187187

188-
func (*agent)handleSSHSession(session ssh.Session)error {
188+
func (a*agent)handleSSHSession(session ssh.Session)error {
189189
var (
190190
commandstring
191191
args= []string{}
@@ -240,7 +240,10 @@ func (*agent) handleSSHSession(session ssh.Session) error {
240240
}
241241
gofunc() {
242242
forwin:=rangewindowSize {
243-
_=ptty.Resize(uint16(win.Width),uint16(win.Height))
243+
err=ptty.Resize(uint16(win.Width),uint16(win.Height))
244+
iferr!=nil {
245+
a.options.Logger.Warn(context.Background(),"failed to resize tty",slog.Error(err))
246+
}
244247
}
245248
}()
246249
gofunc() {

‎cli/cliui/prompt.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cliui
22

33
import (
44
"bufio"
5+
"bytes"
56
"encoding/json"
67
"fmt"
78
"io"
@@ -62,7 +63,11 @@ func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error) {
6263
varrawMessage json.RawMessage
6364
err:=json.NewDecoder(pipeReader).Decode(&rawMessage)
6465
iferr==nil {
65-
line=string(rawMessage)
66+
varbuf bytes.Buffer
67+
err=json.Compact(&buf,rawMessage)
68+
iferr==nil {
69+
line=buf.String()
70+
}
6671
}
6772
}
6873
}

‎cli/cliui/prompt_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ func TestPrompt(t *testing.T) {
9393
ptty.WriteLine(`{
9494
"test": "wow"
9595
}`)
96-
require.Equal(t,`{
97-
"test": "wow"
98-
}`,<-doneChan)
96+
require.Equal(t,`{"test":"wow"}`,<-doneChan)
9997
})
10098
}
10199

‎cli/configssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func configSSH() *cobra.Command {
109109
iferr!=nil {
110110
returnerr
111111
}
112-
_,_=fmt.Fprintf(cmd.OutOrStdout(),"An auto-generated ssh config was written to\"%s\"\n",sshConfigFile)
112+
_,_=fmt.Fprintf(cmd.OutOrStdout(),"An auto-generated ssh config was written to%q\n",sshConfigFile)
113113
_,_=fmt.Fprintln(cmd.OutOrStdout(),"You should now be able to ssh into your workspace")
114114
_,_=fmt.Fprintf(cmd.OutOrStdout(),"For example, try running\n\n\t$ ssh coder.%s\n\n",workspaces[0].Name)
115115
returnnil

‎cli/ssh.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import (
1111
"github.com/pion/webrtc/v3"
1212
"github.com/spf13/cobra"
1313
gossh"golang.org/x/crypto/ssh"
14-
"golang.org/x/crypto/ssh/terminal"
1514
"golang.org/x/xerrors"
1615

1716
"github.com/coder/coder/cli/cliflag"
1817
"github.com/coder/coder/cli/cliui"
1918
"github.com/coder/coder/coderd/database"
2019
"github.com/coder/coder/codersdk"
20+
"golang.org/x/crypto/ssh/terminal"
2121
)
2222

2323
funcssh()*cobra.Command {
@@ -121,18 +121,16 @@ func ssh() *cobra.Command {
121121
}
122122

123123
ifisatty.IsTerminal(os.Stdout.Fd()) {
124-
state,err:=terminal.MakeRaw(int(os.Stdout.Fd()))
124+
state,err:=terminal.MakeRaw(int(os.Stdin.Fd()))
125125
iferr!=nil {
126126
returnerr
127127
}
128128
deferfunc() {
129-
_=terminal.Restore(int(os.Stdout.Fd()),state)
129+
_=terminal.Restore(int(os.Stdin.Fd()),state)
130130
}()
131131
}
132132

133-
err=sshSession.RequestPty("xterm-256color",128,128, gossh.TerminalModes{
134-
gossh.OCRNL:1,
135-
})
133+
err=sshSession.RequestPty("xterm-256color",128,128, gossh.TerminalModes{})
136134
iferr!=nil {
137135
returnerr
138136
}

‎cli/start.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func start() *cobra.Command {
314314
cliflag.StringVarP(root.Flags(),&accessURL,"access-url","","CODER_ACCESS_URL","","Specifies the external URL to access Coder")
315315
cliflag.StringVarP(root.Flags(),&address,"address","a","CODER_ADDRESS","127.0.0.1:3000","The address to serve the API and dashboard")
316316
// systemd uses the CACHE_DIRECTORY environment variable!
317-
cliflag.StringVarP(root.Flags(),&cacheDir,"cache-dir","","CACHE_DIRECTORY",filepath.Join(os.TempDir(),".coder-cache"),"Specifies a directory to cache binaries for provision operations.")
317+
cliflag.StringVarP(root.Flags(),&cacheDir,"cache-dir","","CACHE_DIRECTORY",filepath.Join(os.TempDir(),"coder-cache"),"Specifies a directory to cache binaries for provision operations.")
318318
cliflag.BoolVarP(root.Flags(),&dev,"dev","","CODER_DEV_MODE",false,"Serve Coder in dev mode for tinkering")
319319
cliflag.StringVarP(root.Flags(),&postgresURL,"postgres-url","","CODER_PG_CONNECTION_URL","","URL of a PostgreSQL database to connect to")
320320
cliflag.Uint8VarP(root.Flags(),&provisionerDaemonCount,"provisioner-daemons","","CODER_PROVISIONER_DAEMONS",1,"The amount of provisioner daemons to create on start.")
@@ -370,6 +370,11 @@ func createFirstUser(cmd *cobra.Command, client *codersdk.Client, cfg config.Roo
370370
}
371371

372372
funcnewProvisionerDaemon(ctx context.Context,client*codersdk.Client,logger slog.Logger,cacheDirstring) (*provisionerd.Server,error) {
373+
err:=os.MkdirAll(cacheDir,0700)
374+
iferr!=nil {
375+
returnnil,xerrors.Errorf("mkdir %q: %w",cacheDir,err)
376+
}
377+
373378
terraformClient,terraformServer:=provisionersdk.TransportPipe()
374379
gofunc() {
375380
err:=terraform.Serve(ctx,&terraform.ServeOptions{

‎examples/gcp-linux/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Coder requires a Google Cloud Service Account to provision workspaces.
1818
- Service Account User
1919
3. Click on the created key, and navigate to the "Keys" tab.
2020
4. Click "Add key", then "Create new key".
21-
5. Generate a JSON private key, and paste the contentsin \'\' quotesbelow.
21+
5. Generate a JSON private key, and paste the contents below.
2222
EOF
2323
sensitive=true
2424
}

‎examples/gcp-windows/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Coder requires a Google Cloud Service Account to provision workspaces.
1818
- Service Account User
1919
3. Click on the created key, and navigate to the "Keys" tab.
2020
4. Click "Add key", then "Create new key".
21-
5. Generate a JSON private key, and paste the contentsin \'\' quotesbelow.
21+
5. Generate a JSON private key, and paste the contents below.
2222
EOF
2323
sensitive=true
2424
}

‎provisioner/terraform/provision.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"os/exec"
1111
"path/filepath"
12+
"runtime"
1213
"strings"
1314

1415
"github.com/awalterschulze/gographviz"
@@ -87,7 +88,9 @@ func (t *terraform) Provision(stream proto.DRPCProvisioner_ProvisionStream) erro
8788
})
8889
}
8990
}()
90-
ift.cachePath!="" {
91+
// Windows doesn't work with a plugin cache directory.
92+
// The cause is unknown, but it should work.
93+
ift.cachePath!=""&&runtime.GOOS!="windows" {
9194
err=terraform.SetEnv(map[string]string{
9295
"TF_PLUGIN_CACHE_DIR":t.cachePath,
9396
})

‎provisioner/terraform/serve.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package terraform
22

33
import (
44
"context"
5-
"os/exec"
5+
"path/filepath"
66

77
"github.com/hashicorp/go-version"
88
"golang.org/x/xerrors"
99

1010
"cdr.dev/slog"
1111

12+
"github.com/cli/safeexec"
1213
"github.com/coder/coder/provisionersdk"
1314

1415
"github.com/hashicorp/hc-install/product"
@@ -41,7 +42,7 @@ type ServeOptions struct {
4142
// Serve starts a dRPC server on the provided transport speaking Terraform provisioner.
4243
funcServe(ctx context.Context,options*ServeOptions)error {
4344
ifoptions.BinaryPath=="" {
44-
binaryPath,err:=exec.LookPath("terraform")
45+
binaryPath,err:=safeexec.LookPath("terraform")
4546
iferr!=nil {
4647
installer:=&releases.ExactVersion{
4748
InstallDir:options.CachePath,
@@ -55,7 +56,16 @@ func Serve(ctx context.Context, options *ServeOptions) error {
5556
}
5657
options.BinaryPath=execPath
5758
}else {
58-
options.BinaryPath=binaryPath
59+
// If the "coder" binary is in the same directory as
60+
// the "terraform" binary, "terraform" is returned.
61+
//
62+
// We must resolve the absolute path for other processes
63+
// to execute this properly!
64+
absoluteBinary,err:=filepath.Abs(binaryPath)
65+
iferr!=nil {
66+
returnxerrors.Errorf("absolute: %w",err)
67+
}
68+
options.BinaryPath=absoluteBinary
5969
}
6070
}
6171
returnprovisionersdk.Serve(ctx,&terraform{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp