diff --git a/cli/server.go b/cli/server.go index 3b2392f51dd9b..628671a8d7e3c 100644 --- a/cli/server.go +++ b/cli/server.go @@ -79,7 +79,7 @@ func server() *cobra.Command { tlsKeyFile string tlsMinVersion string turnRelayAddress string - skipTunnel bool + tunnel bool stunServers []string traceDatadog bool secureAuthCookie bool @@ -138,7 +138,7 @@ func server() *cobra.Command { accessURL = localURL.String() } else { // If an access URL is specified, always skip tunneling. - skipTunnel = true + tunnel = false } var ( @@ -149,7 +149,7 @@ func server() *cobra.Command { // If we're attempting to tunnel in dev-mode, the access URL // needs to be changed to use the tunnel. - if dev && !skipTunnel { + if dev && tunnel { _, _ = fmt.Fprintln(cmd.ErrOrStderr(), cliui.Styles.Wrap.Render( "Coder requires a URL accessible by workspaces you provision. "+ "A free tunnel can be created for simple setup. This will "+ @@ -157,12 +157,15 @@ func server() *cobra.Command { cliui.Styles.Field.Render("--access-url")+" can be specified instead.\n", )) - _, err = cliui.Prompt(cmd, cliui.PromptOptions{ - Text: "Would you like to start a tunnel for simple setup?", - IsConfirm: true, - }) - if errors.Is(err, cliui.Canceled) { - return err + // This skips the prompt if the flag is explicitly specified. + if !cmd.Flags().Changed("tunnel") { + _, err = cliui.Prompt(cmd, cliui.PromptOptions{ + Text: "Would you like to start a tunnel for simple setup?", + IsConfirm: true, + }) + if errors.Is(err, cliui.Canceled) { + return err + } } if err == nil { accessURL, tunnelErrChan, err = devtunnel.New(ctxTunnel, localURL) @@ -418,7 +421,7 @@ func server() *cobra.Command { spin.Stop() } - if dev && !skipTunnel { + if dev && tunnel { _, _ = fmt.Fprintf(cmd.OutOrStdout(), cliui.Styles.Prompt.String()+"Waiting for dev tunnel to close...\n") closeTunnel() <-tunnelErrChan @@ -466,8 +469,8 @@ func server() *cobra.Command { "Specifies the path to the private key for the certificate. It requires a PEM-encoded file") cliflag.StringVarP(root.Flags(), &tlsMinVersion, "tls-min-version", "", "CODER_TLS_MIN_VERSION", "tls12", `Specifies the minimum supported version of TLS. Accepted values are "tls10", "tls11", "tls12" or "tls13"`) - cliflag.BoolVarP(root.Flags(), &skipTunnel, "skip-tunnel", "", "CODER_DEV_SKIP_TUNNEL", false, "Skip serving dev mode through an exposed tunnel for simple setup.") - _ = root.Flags().MarkHidden("skip-tunnel") + cliflag.BoolVarP(root.Flags(), &tunnel, "tunnel", "", "CODER_DEV_TUNNEL", true, + "Specifies whether the dev tunnel will be enabled or not. If specified, the interactive prompt will not display.") cliflag.StringArrayVarP(root.Flags(), &stunServers, "stun-server", "", "CODER_STUN_SERVERS", []string{ "stun:stun.l.google.com:19302", }, "Specify URLs for STUN servers to enable P2P connections.") diff --git a/cli/server_test.go b/cli/server_test.go index 4066cb1e86ea2..f20944367853f 100644 --- a/cli/server_test.go +++ b/cli/server_test.go @@ -79,7 +79,7 @@ func TestServer(t *testing.T) { wantEmail := "admin@coder.com" - root, cfg := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0") + root, cfg := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0") var buf strings.Builder root.SetOutput(&buf) var wg sync.WaitGroup @@ -132,7 +132,7 @@ func TestServer(t *testing.T) { t.Setenv("CODER_DEV_ADMIN_EMAIL", wantEmail) t.Setenv("CODER_DEV_ADMIN_PASSWORD", wantPassword) - root, cfg := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0") + root, cfg := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0") var buf strings.Builder root.SetOutput(&buf) var wg sync.WaitGroup @@ -170,7 +170,7 @@ func TestServer(t *testing.T) { t.Parallel() ctx, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() - root, _ := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0", + root, _ := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0", "--tls-enable", "--tls-min-version", "tls9") err := root.ExecuteContext(ctx) require.Error(t, err) @@ -179,7 +179,7 @@ func TestServer(t *testing.T) { t.Parallel() ctx, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() - root, _ := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0", + root, _ := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0", "--tls-enable", "--tls-client-auth", "something") err := root.ExecuteContext(ctx) require.Error(t, err) @@ -188,7 +188,7 @@ func TestServer(t *testing.T) { t.Parallel() ctx, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() - root, _ := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0", + root, _ := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0", "--tls-enable") err := root.ExecuteContext(ctx) require.Error(t, err) @@ -199,7 +199,7 @@ func TestServer(t *testing.T) { defer cancelFunc() certPath, keyPath := generateTLSCertificate(t) - root, cfg := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0", + root, cfg := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0", "--tls-enable", "--tls-cert-file", certPath, "--tls-key-file", keyPath) go func() { err := root.ExecuteContext(ctx) @@ -235,7 +235,7 @@ func TestServer(t *testing.T) { } ctx, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() - root, cfg := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0", "--provisioner-daemons", "0") + root, cfg := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0", "--provisioner-daemons", "0") done := make(chan struct{}) go func() { defer close(done) @@ -283,7 +283,7 @@ func TestServer(t *testing.T) { t.Parallel() ctx, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() - root, _ := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0", "--trace-datadog=true") + root, _ := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0", "--trace-datadog=true") done := make(chan struct{}) go func() { defer close(done) diff --git a/develop.sh b/develop.sh index d54af068f2165..da481317ad2dc 100755 --- a/develop.sh +++ b/develop.sh @@ -5,6 +5,9 @@ set -euo pipefail PROJECT_ROOT="$(git rev-parse --show-toplevel)" cd "${PROJECT_ROOT}" +echo '== Run "make build" before running this command to build binaries.' +echo '== Without these binaries, workspaces will fail to start!' + # Run yarn install, to make sure node_modules are ready to go "$PROJECT_ROOT/scripts/yarn_install.sh" @@ -18,6 +21,6 @@ export CODER_DEV_ADMIN_PASSWORD=password ( trap 'kill 0' SIGINT CODERV2_HOST=http://127.0.0.1:3000 INSPECT_XSTATE=true yarn --cwd=./site dev & - go run cmd/coder/main.go server --dev --skip-tunnel & + go run -tags embed cmd/coder/main.go server --dev --tunnel=true & wait ) diff --git a/go.sum b/go.sum index d058fc5f0b0e7..99ea1d9935b8f 100644 --- a/go.sum +++ b/go.sum @@ -960,7 +960,6 @@ github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/hashicorp/hc-install v0.3.1 h1:VIjllE6KyAI1A244G8kTaHXy+TL5/XYzvrtFi8po/Yk= github.com/hashicorp/hc-install v0.3.1/go.mod h1:3LCdWcCDS1gaHC9mhHCGbkYfoY6vdsKohGjugbZdZak= github.com/hashicorp/hc-install v0.3.2 h1:oiQdJZvXmkNcRcEOOfM5n+VTsvNjWQeOjfAoO6dKSH8= github.com/hashicorp/hc-install v0.3.2/go.mod h1:xMG6Tr8Fw1WFjlxH0A9v61cW15pFwgEGqEz0V4jisHs= diff --git a/site/e2e/playwright.config.ts b/site/e2e/playwright.config.ts index 365e023d95f3e..a124b9b86d387 100644 --- a/site/e2e/playwright.config.ts +++ b/site/e2e/playwright.config.ts @@ -21,7 +21,7 @@ const config: PlaywrightTestConfig = { command: `go run -tags embed ${path.join( __dirname, "../../cmd/coder/main.go", - )} server --dev --skip-tunnel --dev-admin-email ${constants.email} --dev-admin-password ${constants.password}`, + )} server --dev --tunnel=false --dev-admin-email ${constants.email} --dev-admin-password ${constants.password}`, port: 3000, timeout: 120 * 10000, reuseExistingServer: false,