Skip to content

Commit 7b5300d

Browse files
authored
fix: Improve develop script to start tunnel by default (#1409)
This allows for running the development script to actually build workspaces!
1 parent 2091628 commit 7b5300d

File tree

5 files changed

+28
-23
lines changed

5 files changed

+28
-23
lines changed

cli/server.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func server() *cobra.Command {
8080
tlsKeyFile string
8181
tlsMinVersion string
8282
turnRelayAddress string
83-
skipTunnel bool
83+
tunnel bool
8484
stunServers []string
8585
traceDatadog bool
8686
secureAuthCookie bool
@@ -139,7 +139,7 @@ func server() *cobra.Command {
139139
accessURL = localURL.String()
140140
} else {
141141
// If an access URL is specified, always skip tunneling.
142-
skipTunnel = true
142+
tunnel = false
143143
}
144144

145145
var (
@@ -150,20 +150,23 @@ func server() *cobra.Command {
150150

151151
// If we're attempting to tunnel in dev-mode, the access URL
152152
// needs to be changed to use the tunnel.
153-
if dev && !skipTunnel {
153+
if dev && tunnel {
154154
_, _ = fmt.Fprintln(cmd.ErrOrStderr(), cliui.Styles.Wrap.Render(
155155
"Coder requires a URL accessible by workspaces you provision. "+
156156
"A free tunnel can be created for simple setup. This will "+
157157
"expose your Coder deployment to a publicly accessible URL. "+
158158
cliui.Styles.Field.Render("--access-url")+" can be specified instead.\n",
159159
))
160160

161-
_, err = cliui.Prompt(cmd, cliui.PromptOptions{
162-
Text: "Would you like to start a tunnel for simple setup?",
163-
IsConfirm: true,
164-
})
165-
if errors.Is(err, cliui.Canceled) {
166-
return err
161+
// This skips the prompt if the flag is explicitly specified.
162+
if !cmd.Flags().Changed("tunnel") {
163+
_, err = cliui.Prompt(cmd, cliui.PromptOptions{
164+
Text: "Would you like to start a tunnel for simple setup?",
165+
IsConfirm: true,
166+
})
167+
if errors.Is(err, cliui.Canceled) {
168+
return err
169+
}
167170
}
168171
if err == nil {
169172
accessURL, tunnelErrChan, err = devtunnel.New(ctxTunnel, localURL)
@@ -424,7 +427,7 @@ func server() *cobra.Command {
424427
spin.Stop()
425428
}
426429

427-
if dev && !skipTunnel {
430+
if dev && tunnel {
428431
_, _ = fmt.Fprintf(cmd.OutOrStdout(), cliui.Styles.Prompt.String()+"Waiting for dev tunnel to close...\n")
429432
closeTunnel()
430433
<-tunnelErrChan
@@ -472,8 +475,8 @@ func server() *cobra.Command {
472475
"Specifies the path to the private key for the certificate. It requires a PEM-encoded file")
473476
cliflag.StringVarP(root.Flags(), &tlsMinVersion, "tls-min-version", "", "CODER_TLS_MIN_VERSION", "tls12",
474477
`Specifies the minimum supported version of TLS. Accepted values are "tls10", "tls11", "tls12" or "tls13"`)
475-
cliflag.BoolVarP(root.Flags(), &skipTunnel, "skip-tunnel", "", "CODER_DEV_SKIP_TUNNEL", false, "Skip serving dev mode through an exposed tunnel for simple setup.")
476-
_ = root.Flags().MarkHidden("skip-tunnel")
478+
cliflag.BoolVarP(root.Flags(), &tunnel, "tunnel", "", "CODER_DEV_TUNNEL", true,
479+
"Specifies whether the dev tunnel will be enabled or not. If specified, the interactive prompt will not display.")
477480
cliflag.StringArrayVarP(root.Flags(), &stunServers, "stun-server", "", "CODER_STUN_SERVERS", []string{
478481
"stun:stun.l.google.com:19302",
479482
}, "Specify URLs for STUN servers to enable P2P connections.")

cli/server_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestServer(t *testing.T) {
7979

8080
wantEmail := "admin@coder.com"
8181

82-
root, cfg := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0")
82+
root, cfg := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0")
8383
var buf strings.Builder
8484
root.SetOutput(&buf)
8585
var wg sync.WaitGroup
@@ -132,7 +132,7 @@ func TestServer(t *testing.T) {
132132
t.Setenv("CODER_DEV_ADMIN_EMAIL", wantEmail)
133133
t.Setenv("CODER_DEV_ADMIN_PASSWORD", wantPassword)
134134

135-
root, cfg := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0")
135+
root, cfg := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0")
136136
var buf strings.Builder
137137
root.SetOutput(&buf)
138138
var wg sync.WaitGroup
@@ -170,7 +170,7 @@ func TestServer(t *testing.T) {
170170
t.Parallel()
171171
ctx, cancelFunc := context.WithCancel(context.Background())
172172
defer cancelFunc()
173-
root, _ := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0",
173+
root, _ := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0",
174174
"--tls-enable", "--tls-min-version", "tls9")
175175
err := root.ExecuteContext(ctx)
176176
require.Error(t, err)
@@ -179,7 +179,7 @@ func TestServer(t *testing.T) {
179179
t.Parallel()
180180
ctx, cancelFunc := context.WithCancel(context.Background())
181181
defer cancelFunc()
182-
root, _ := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0",
182+
root, _ := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0",
183183
"--tls-enable", "--tls-client-auth", "something")
184184
err := root.ExecuteContext(ctx)
185185
require.Error(t, err)
@@ -188,7 +188,7 @@ func TestServer(t *testing.T) {
188188
t.Parallel()
189189
ctx, cancelFunc := context.WithCancel(context.Background())
190190
defer cancelFunc()
191-
root, _ := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0",
191+
root, _ := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0",
192192
"--tls-enable")
193193
err := root.ExecuteContext(ctx)
194194
require.Error(t, err)
@@ -199,7 +199,7 @@ func TestServer(t *testing.T) {
199199
defer cancelFunc()
200200

201201
certPath, keyPath := generateTLSCertificate(t)
202-
root, cfg := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0",
202+
root, cfg := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0",
203203
"--tls-enable", "--tls-cert-file", certPath, "--tls-key-file", keyPath)
204204
go func() {
205205
err := root.ExecuteContext(ctx)
@@ -235,7 +235,7 @@ func TestServer(t *testing.T) {
235235
}
236236
ctx, cancelFunc := context.WithCancel(context.Background())
237237
defer cancelFunc()
238-
root, cfg := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0", "--provisioner-daemons", "0")
238+
root, cfg := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0", "--provisioner-daemons", "0")
239239
done := make(chan struct{})
240240
go func() {
241241
defer close(done)
@@ -283,7 +283,7 @@ func TestServer(t *testing.T) {
283283
t.Parallel()
284284
ctx, cancelFunc := context.WithCancel(context.Background())
285285
defer cancelFunc()
286-
root, _ := clitest.New(t, "server", "--dev", "--skip-tunnel", "--address", ":0", "--trace-datadog=true")
286+
root, _ := clitest.New(t, "server", "--dev", "--tunnel=false", "--address", ":0", "--trace-datadog=true")
287287
done := make(chan struct{})
288288
go func() {
289289
defer close(done)

develop.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ set -euo pipefail
55
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
66
cd "${PROJECT_ROOT}"
77

8+
echo '== Run "make build" before running this command to build binaries.'
9+
echo '== Without these binaries, workspaces will fail to start!'
10+
811
# Run yarn install, to make sure node_modules are ready to go
912
"$PROJECT_ROOT/scripts/yarn_install.sh"
1013

@@ -18,6 +21,6 @@ export CODER_DEV_ADMIN_PASSWORD=password
1821
(
1922
trap 'kill 0' SIGINT
2023
CODERV2_HOST=http://127.0.0.1:3000 INSPECT_XSTATE=true yarn --cwd=./site dev &
21-
go run cmd/coder/main.go server --dev --skip-tunnel &
24+
go run -tags embed cmd/coder/main.go server --dev --tunnel=true &
2225
wait
2326
)

go.sum

-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,6 @@ github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA
960960
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
961961
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
962962
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
963-
github.com/hashicorp/hc-install v0.3.1 h1:VIjllE6KyAI1A244G8kTaHXy+TL5/XYzvrtFi8po/Yk=
964963
github.com/hashicorp/hc-install v0.3.1/go.mod h1:3LCdWcCDS1gaHC9mhHCGbkYfoY6vdsKohGjugbZdZak=
965964
github.com/hashicorp/hc-install v0.3.2 h1:oiQdJZvXmkNcRcEOOfM5n+VTsvNjWQeOjfAoO6dKSH8=
966965
github.com/hashicorp/hc-install v0.3.2/go.mod h1:xMG6Tr8Fw1WFjlxH0A9v61cW15pFwgEGqEz0V4jisHs=

site/e2e/playwright.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const config: PlaywrightTestConfig = {
2121
command: `go run -tags embed ${path.join(
2222
__dirname,
2323
"../../cmd/coder/main.go",
24-
)} server --dev --skip-tunnel --dev-admin-email ${constants.email} --dev-admin-password ${constants.password}`,
24+
)} server --dev --tunnel=false --dev-admin-email ${constants.email} --dev-admin-password ${constants.password}`,
2525
port: 3000,
2626
timeout: 120 * 10000,
2727
reuseExistingServer: false,

0 commit comments

Comments
 (0)