diff --git a/coderd/coderd.go b/coderd/coderd.go index 6c2f08fcc4..7c9d94620a 100644 --- a/coderd/coderd.go +++ b/coderd/coderd.go @@ -436,6 +436,15 @@ func New(options *Options) *API { api.AppearanceFetcher.Store(&appearance.DefaultFetcher) api.PortSharer.Store(&portsharing.DefaultPortSharer) + buildInfo := codersdk.BuildInfoResponse{ + ExternalURL: buildinfo.ExternalURL(), + Version: buildinfo.Version(), + AgentAPIVersion: AgentAPIVersionREST, + DashboardURL: api.AccessURL.String(), + WorkspaceProxy: false, + UpgradeMessage: api.DeploymentValues.CLIUpgradeMessage.String(), + DeploymentID: api.DeploymentID, + } api.SiteHandler = site.New(&site.Options{ BinFS: binFS, BinHashes: binHashes, @@ -444,6 +453,7 @@ func New(options *Options) *API { OAuth2Configs: oauthConfigs, DocsURL: options.DeploymentValues.DocsURL.String(), AppearanceFetcher: &api.AppearanceFetcher, + BuildInfo: buildInfo, }) api.SiteHandler.Experiments.Store(&experiments) @@ -735,7 +745,7 @@ func New(options *Options) *API { // All CSP errors will be logged r.Post("/csp/reports", api.logReportCSPViolations) - r.Get("/buildinfo", buildInfo(api.AccessURL, api.DeploymentValues.CLIUpgradeMessage.String(), api.DeploymentID)) + r.Get("/buildinfo", buildInfoHandler(buildInfo)) // /regions is overridden in the enterprise version r.Group(func(r chi.Router) { r.Use(apiKeyMiddleware) diff --git a/coderd/deployment.go b/coderd/deployment.go index 7c39c7ea28..d96d6d4388 100644 --- a/coderd/deployment.go +++ b/coderd/deployment.go @@ -2,9 +2,7 @@ package coderd import ( "net/http" - "net/url" - "github.com/coder/coder/v2/buildinfo" "github.com/coder/coder/v2/coderd/httpapi" "github.com/coder/coder/v2/coderd/rbac" "github.com/coder/coder/v2/codersdk" @@ -68,17 +66,10 @@ func (api *API) deploymentStats(rw http.ResponseWriter, r *http.Request) { // @Tags General // @Success 200 {object} codersdk.BuildInfoResponse // @Router /buildinfo [get] -func buildInfo(accessURL *url.URL, upgradeMessage, deploymentID string) http.HandlerFunc { +func buildInfoHandler(resp codersdk.BuildInfoResponse) http.HandlerFunc { + // This is in a handler so that we can generate API docs info. return func(rw http.ResponseWriter, r *http.Request) { - httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.BuildInfoResponse{ - ExternalURL: buildinfo.ExternalURL(), - Version: buildinfo.Version(), - AgentAPIVersion: AgentAPIVersionREST, - DashboardURL: accessURL.String(), - WorkspaceProxy: false, - UpgradeMessage: upgradeMessage, - DeploymentID: deploymentID, - }) + httpapi.Write(r.Context(), rw, http.StatusOK, resp) } } diff --git a/site/site.go b/site/site.go index 1d9d31d5fc..9eee2e66d1 100644 --- a/site/site.go +++ b/site/site.go @@ -34,7 +34,6 @@ import ( "golang.org/x/sync/singleflight" "golang.org/x/xerrors" - "github.com/coder/coder/v2/buildinfo" "github.com/coder/coder/v2/coderd/appearance" "github.com/coder/coder/v2/coderd/database" "github.com/coder/coder/v2/coderd/database/db2sdk" @@ -78,6 +77,7 @@ type Options struct { SiteFS fs.FS OAuth2Configs *httpmw.OAuth2Configs DocsURL string + BuildInfo codersdk.BuildInfoResponse AppearanceFetcher *atomic.Pointer[appearance.Fetcher] } @@ -149,12 +149,7 @@ func New(opts *Options) *Handler { // static files. OnlyFiles(opts.SiteFS))), ) - - buildInfo := codersdk.BuildInfoResponse{ - ExternalURL: buildinfo.ExternalURL(), - Version: buildinfo.Version(), - } - buildInfoResponse, err := json.Marshal(buildInfo) + buildInfoResponse, err := json.Marshal(opts.BuildInfo) if err != nil { panic("failed to marshal build info: " + err.Error()) }