Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54b359e

Browse files
committed
Add TURN server to coder start
1 parent 54d5a59 commit 54b359e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

cli/start.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/briandowns/spinner"
2020
"github.com/coreos/go-systemd/daemon"
21+
"github.com/pion/turn/v2"
2122
"github.com/spf13/cobra"
2223
"golang.org/x/xerrors"
2324
"google.golang.org/api/idtoken"
@@ -34,6 +35,7 @@ import (
3435
"github.com/coder/coder/coderd/database/databasefake"
3536
"github.com/coder/coder/coderd/devtunnel"
3637
"github.com/coder/coder/coderd/gitsshkey"
38+
"github.com/coder/coder/coderd/turnconn"
3739
"github.com/coder/coder/codersdk"
3840
"github.com/coder/coder/provisioner/terraform"
3941
"github.com/coder/coder/provisionerd"
@@ -56,6 +58,7 @@ func start() *cobra.Command {
5658
tlsEnable bool
5759
tlsKeyFile string
5860
tlsMinVersion string
61+
turnRelayAddress string
5962
skipTunnel bool
6063
traceDatadog bool
6164
secureAuthCookie bool
@@ -154,6 +157,14 @@ func start() *cobra.Command {
154157
return xerrors.Errorf("parse ssh keygen algorithm %s: %w", sshKeygenAlgorithmRaw, err)
155158
}
156159

160+
turnServer, err := turnconn.New(&turn.RelayAddressGeneratorStatic{
161+
RelayAddress: net.ParseIP(turnRelayAddress),
162+
Address: turnRelayAddress,
163+
})
164+
if err != nil {
165+
return xerrors.Errorf("create turn server: %w", err)
166+
}
167+
157168
logger := slog.Make(sloghuman.Sink(os.Stderr))
158169
options := &coderd.Options{
159170
AccessURL: accessURLParsed,
@@ -163,6 +174,7 @@ func start() *cobra.Command {
163174
GoogleTokenValidator: validator,
164175
SecureAuthCookie: secureAuthCookie,
165176
SSHKeygenAlgorithm: sshKeygenAlgorithm,
177+
TURNServer: turnServer,
166178
}
167179

168180
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "access-url: %s\n", accessURL)
@@ -375,6 +387,8 @@ func start() *cobra.Command {
375387
cliflag.BoolVarP(root.Flags(), &skipTunnel, "skip-tunnel", "", "CODER_DEV_SKIP_TUNNEL", false, "Skip serving dev mode through an exposed tunnel for simple setup.")
376388
_ = root.Flags().MarkHidden("skip-tunnel")
377389
cliflag.BoolVarP(root.Flags(), &traceDatadog, "trace-datadog", "", "CODER_TRACE_DATADOG", false, "Send tracing data to a datadog agent")
390+
cliflag.StringVarP(root.Flags(), &turnRelayAddress, "turn-relay-address", "", "CODER_TURN_RELAY_ADDRESS", "127.0.0.1",
391+
"Specifies the address to bind TURN connections.")
378392
cliflag.BoolVarP(root.Flags(), &secureAuthCookie, "secure-auth-cookie", "", "CODER_SECURE_AUTH_COOKIE", false, "Specifies if the 'Secure' property is set on browser session cookies")
379393
cliflag.StringVarP(root.Flags(), &sshKeygenAlgorithmRaw, "ssh-keygen-algorithm", "", "CODER_SSH_KEYGEN_ALGORITHM", "ed25519", "Specifies the algorithm to use for generating ssh keys. "+
380394
`Accepted values are "ed25519", "ecdsa", or "rsa4096"`)

0 commit comments

Comments
 (0)