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

Commit7a43a2e

Browse files
committed
feat: use custom wireguard reverse proxy for dev tunnel
1 parent89dde21 commit7a43a2e

File tree

5 files changed

+380
-163
lines changed

5 files changed

+380
-163
lines changed

‎cli/server.go

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"golang.org/x/mod/semver"
3434
"golang.org/x/oauth2"
3535
xgithub"golang.org/x/oauth2/github"
36+
"golang.org/x/sync/errgroup"
3637
"golang.org/x/xerrors"
3738
"google.golang.org/api/idtoken"
3839
"google.golang.org/api/option"
@@ -86,7 +87,7 @@ func server() *cobra.Command {
8687
tlsKeyFilestring
8788
tlsMinVersionstring
8889
turnRelayAddressstring
89-
tunnelbool
90+
shouldTunnelbool
9091
stunServers []string
9192
tracebool
9293
secureAuthCookiebool
@@ -165,18 +166,18 @@ func server() *cobra.Command {
165166
accessURL=localURL.String()
166167
}else {
167168
// If an access URL is specified, always skip tunneling.
168-
tunnel=false
169+
shouldTunnel=false
169170
}
170171

171172
var (
172-
tunnelErrChan<-chanerror
173173
ctxTunnel,closeTunnel=context.WithCancel(cmd.Context())
174+
tunnel=&devtunnel.Tunnel{ErrorChan:make(chanerror,1)}
174175
)
175176
defercloseTunnel()
176177

177178
// If we're attempting to tunnel in dev-mode, the access URL
178179
// needs to be changed to use the tunnel.
179-
ifdev&&tunnel {
180+
ifdev&&shouldTunnel {
180181
_,_=fmt.Fprintln(cmd.ErrOrStderr(),cliui.Styles.Wrap.Render(
181182
"Coder requires a URL accessible by workspaces you provision. "+
182183
"A free tunnel can be created for simple setup. This will "+
@@ -195,10 +196,11 @@ func server() *cobra.Command {
195196
}
196197
}
197198
iferr==nil {
198-
accessURL,tunnelErrChan,err=devtunnel.New(ctxTunnel,localURL)
199+
tunnel,err=devtunnel.New(ctxTunnel,logger.Named("devtunnel"))
199200
iferr!=nil {
200201
returnxerrors.Errorf("create tunnel: %w",err)
201202
}
203+
accessURL=tunnel.URL
202204
}
203205
_,_=fmt.Fprintln(cmd.ErrOrStderr())
204206
}
@@ -327,7 +329,25 @@ func server() *cobra.Command {
327329
returnshutdownConnsCtx
328330
},
329331
}
330-
errCh<-server.Serve(listener)
332+
333+
wg:= errgroup.Group{}
334+
wg.Go(func()error {
335+
ifdev&&shouldTunnel {
336+
defertunnel.Listener.Close()
337+
}
338+
339+
returnserver.Serve(listener)
340+
})
341+
342+
ifdev&&shouldTunnel {
343+
wg.Go(func()error {
344+
deferlistener.Close()
345+
346+
returnserver.Serve(tunnel.Listener)
347+
})
348+
}
349+
350+
errCh<-wg.Wait()
331351
}()
332352

333353
config:=createConfig(cmd)
@@ -393,7 +413,7 @@ func server() *cobra.Command {
393413
case<-cmd.Context().Done():
394414
coderAPI.Close()
395415
returncmd.Context().Err()
396-
caseerr:=<-tunnelErrChan:
416+
caseerr:=<-tunnel.ErrorChan:
397417
iferr!=nil {
398418
returnerr
399419
}
@@ -455,10 +475,10 @@ func server() *cobra.Command {
455475
spin.Stop()
456476
}
457477

458-
ifdev&&tunnel {
478+
ifdev&&shouldTunnel {
459479
_,_=fmt.Fprintf(cmd.OutOrStdout(),cliui.Styles.Prompt.String()+"Waiting for dev tunnel to close...\n")
460480
closeTunnel()
461-
<-tunnelErrChan
481+
<-tunnel.ErrorChan
462482
}
463483

464484
_,_=fmt.Fprintf(cmd.OutOrStdout(),cliui.Styles.Prompt.String()+"Waiting for WebSocket connections to close...\n")
@@ -504,7 +524,7 @@ func server() *cobra.Command {
504524
"Specifies the path to the private key for the certificate. It requires a PEM-encoded file")
505525
cliflag.StringVarP(root.Flags(),&tlsMinVersion,"tls-min-version","","CODER_TLS_MIN_VERSION","tls12",
506526
`Specifies the minimum supported version of TLS. Accepted values are "tls10", "tls11", "tls12" or "tls13"`)
507-
cliflag.BoolVarP(root.Flags(),&tunnel,"tunnel","","CODER_DEV_TUNNEL",true,
527+
cliflag.BoolVarP(root.Flags(),&shouldTunnel,"tunnel","","CODER_DEV_TUNNEL",true,
508528
"Specifies whether the dev tunnel will be enabled or not. If specified, the interactive prompt will not display.")
509529
cliflag.StringArrayVarP(root.Flags(),&stunServers,"stun-server","","CODER_STUN_SERVERS", []string{
510530
"stun:stun.l.google.com:19302",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp