From 0f410daac1924421cd52270deb0427a5974cb5bd Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Mon, 30 Sep 2024 08:03:12 +0000 Subject: [PATCH 1/2] chore: add site flag to buildinfo --- buildinfo/buildinfo.go | 8 ++++++++ buildinfo/buildinfo_site.go | 7 +++++++ cli/server.go | 4 +++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 buildinfo/buildinfo_site.go diff --git a/buildinfo/buildinfo.go b/buildinfo/buildinfo.go index e1fd90fe2fadb..b23c4890955bc 100644 --- a/buildinfo/buildinfo.go +++ b/buildinfo/buildinfo.go @@ -24,6 +24,9 @@ var ( // Updated by buildinfo_slim.go on start. slim bool + // Updated by buildinfo_site.go on start. + site bool + // Injected with ldflags at build, see scripts/build_go.sh tag string agpl string // either "true" or "false", ldflags does not support bools @@ -95,6 +98,11 @@ func IsSlim() bool { return slim } +// HasSite returns true if the frontend is embedded in the build. +func HasSite() bool { + return site +} + // IsAGPL returns true if this is an AGPL build. func IsAGPL() bool { return strings.Contains(agpl, "t") diff --git a/buildinfo/buildinfo_site.go b/buildinfo/buildinfo_site.go new file mode 100644 index 0000000000000..d4c4ea9497142 --- /dev/null +++ b/buildinfo/buildinfo_site.go @@ -0,0 +1,7 @@ +//go:build embed + +package buildinfo + +func init() { + site = true +} diff --git a/cli/server.go b/cli/server.go index 561c1bac16375..659bf82a95e15 100644 --- a/cli/server.go +++ b/cli/server.go @@ -492,7 +492,9 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd. BorderForeground(lipgloss.Color("12")). Render(fmt.Sprintf("View the Web UI:\n%s", pretty.Sprint(cliui.DefaultStyles.Hyperlink, accessURL)))) - _ = openURL(inv, accessURL) + if buildinfo.HasSite() { + _ = openURL(inv, accessURL) + } // Used for zero-trust instance identity with Google Cloud. googleTokenValidator, err := idtoken.NewValidator(ctx, option.WithoutAuthentication()) From 9075bf9cabc3e10ac1bc49b78ddfc6de87d2ea8d Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Mon, 30 Sep 2024 12:32:04 +0000 Subject: [PATCH 2/2] mention `--no-open` in logs --- cli/root.go | 2 +- cli/server.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/root.go b/cli/root.go index 2b6cc2c19c8ec..5d9ed5590f3a3 100644 --- a/cli/root.go +++ b/cli/root.go @@ -411,7 +411,7 @@ func (r *RootCmd) Command(subcommands []*serpent.Command) (*serpent.Command, err { Flag: varNoOpen, Env: "CODER_NO_OPEN", - Description: "Suppress opening the browser after logging in.", + Description: "Suppress opening the browser when logging in, or starting the server.", Value: serpent.BoolOf(&r.noOpen), Hidden: true, Group: globalGroup, diff --git a/cli/server.go b/cli/server.go index 659bf82a95e15..52364f5093d04 100644 --- a/cli/server.go +++ b/cli/server.go @@ -493,7 +493,10 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd. Render(fmt.Sprintf("View the Web UI:\n%s", pretty.Sprint(cliui.DefaultStyles.Hyperlink, accessURL)))) if buildinfo.HasSite() { - _ = openURL(inv, accessURL) + err = openURL(inv, accessURL) + if err == nil { + cliui.Infof(inv.Stdout, "Opening local browser... You can disable this by passing --no-open.\n") + } } // Used for zero-trust instance identity with Google Cloud.