Skip to content

Commit fbb98b9

Browse files
authored
chore: centralize build info for site (#13104)
The build info passed to the frontend via HTML was incorrect.
1 parent 1bda8a0 commit fbb98b9

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

coderd/coderd.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,15 @@ func New(options *Options) *API {
436436

437437
api.AppearanceFetcher.Store(&appearance.DefaultFetcher)
438438
api.PortSharer.Store(&portsharing.DefaultPortSharer)
439+
buildInfo := codersdk.BuildInfoResponse{
440+
ExternalURL: buildinfo.ExternalURL(),
441+
Version: buildinfo.Version(),
442+
AgentAPIVersion: AgentAPIVersionREST,
443+
DashboardURL: api.AccessURL.String(),
444+
WorkspaceProxy: false,
445+
UpgradeMessage: api.DeploymentValues.CLIUpgradeMessage.String(),
446+
DeploymentID: api.DeploymentID,
447+
}
439448
api.SiteHandler = site.New(&site.Options{
440449
BinFS: binFS,
441450
BinHashes: binHashes,
@@ -444,6 +453,7 @@ func New(options *Options) *API {
444453
OAuth2Configs: oauthConfigs,
445454
DocsURL: options.DeploymentValues.DocsURL.String(),
446455
AppearanceFetcher: &api.AppearanceFetcher,
456+
BuildInfo: buildInfo,
447457
})
448458
api.SiteHandler.Experiments.Store(&experiments)
449459

@@ -735,7 +745,7 @@ func New(options *Options) *API {
735745
// All CSP errors will be logged
736746
r.Post("/csp/reports", api.logReportCSPViolations)
737747

738-
r.Get("/buildinfo", buildInfo(api.AccessURL, api.DeploymentValues.CLIUpgradeMessage.String(), api.DeploymentID))
748+
r.Get("/buildinfo", buildInfoHandler(buildInfo))
739749
// /regions is overridden in the enterprise version
740750
r.Group(func(r chi.Router) {
741751
r.Use(apiKeyMiddleware)

coderd/deployment.go

+3-12
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package coderd
22

33
import (
44
"net/http"
5-
"net/url"
65

7-
"github.com/coder/coder/v2/buildinfo"
86
"github.com/coder/coder/v2/coderd/httpapi"
97
"github.com/coder/coder/v2/coderd/rbac"
108
"github.com/coder/coder/v2/codersdk"
@@ -68,17 +66,10 @@ func (api *API) deploymentStats(rw http.ResponseWriter, r *http.Request) {
6866
// @Tags General
6967
// @Success 200 {object} codersdk.BuildInfoResponse
7068
// @Router /buildinfo [get]
71-
func buildInfo(accessURL *url.URL, upgradeMessage, deploymentID string) http.HandlerFunc {
69+
func buildInfoHandler(resp codersdk.BuildInfoResponse) http.HandlerFunc {
70+
// This is in a handler so that we can generate API docs info.
7271
return func(rw http.ResponseWriter, r *http.Request) {
73-
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.BuildInfoResponse{
74-
ExternalURL: buildinfo.ExternalURL(),
75-
Version: buildinfo.Version(),
76-
AgentAPIVersion: AgentAPIVersionREST,
77-
DashboardURL: accessURL.String(),
78-
WorkspaceProxy: false,
79-
UpgradeMessage: upgradeMessage,
80-
DeploymentID: deploymentID,
81-
})
72+
httpapi.Write(r.Context(), rw, http.StatusOK, resp)
8273
}
8374
}
8475

site/site.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"golang.org/x/sync/singleflight"
3535
"golang.org/x/xerrors"
3636

37-
"github.com/coder/coder/v2/buildinfo"
3837
"github.com/coder/coder/v2/coderd/appearance"
3938
"github.com/coder/coder/v2/coderd/database"
4039
"github.com/coder/coder/v2/coderd/database/db2sdk"
@@ -78,6 +77,7 @@ type Options struct {
7877
SiteFS fs.FS
7978
OAuth2Configs *httpmw.OAuth2Configs
8079
DocsURL string
80+
BuildInfo codersdk.BuildInfoResponse
8181
AppearanceFetcher *atomic.Pointer[appearance.Fetcher]
8282
}
8383

@@ -149,12 +149,7 @@ func New(opts *Options) *Handler {
149149
// static files.
150150
OnlyFiles(opts.SiteFS))),
151151
)
152-
153-
buildInfo := codersdk.BuildInfoResponse{
154-
ExternalURL: buildinfo.ExternalURL(),
155-
Version: buildinfo.Version(),
156-
}
157-
buildInfoResponse, err := json.Marshal(buildInfo)
152+
buildInfoResponse, err := json.Marshal(opts.BuildInfo)
158153
if err != nil {
159154
panic("failed to marshal build info: " + err.Error())
160155
}

0 commit comments

Comments
 (0)