Skip to content

Commit 58f6328

Browse files
committed
static plugin
1 parent 9025b21 commit 58f6328

10 files changed

+444
-381
lines changed

.mk/static.mk

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
##@ Static
2+
3+
.PHONY: build-frontend-static
4+
build-frontend-static: install-frontend fmt-frontend ## Run npm install, format and build static frontend
5+
@echo "### Building static frontend"
6+
cd web && npm run build:static

Dockerfile.cypress

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ COPY mocks mocks
1919
WORKDIR /opt/app-root/web
2020
RUN npm run format-all
2121
RUN npm run build$BUILDSCRIPT
22+
RUN npm run build:static
2223

2324
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.23 as go-builder
2425

Dockerfile.front

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ COPY mocks mocks
1717
WORKDIR /opt/app-root/web
1818
RUN npm run format-all
1919
RUN npm run build$BUILDSCRIPT
20+
RUN npm run build:static
2021

2122
FROM scratch
2223

Dockerfile.front.downstream

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ COPY --chown=default mocks mocks
1616
WORKDIR /opt/app-root/web
1717
RUN npm run format-all
1818
RUN npm run build$BUILDSCRIPT
19+
RUN npm run build:static
1920

2021
FROM scratch
2122

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,4 @@ endif
223223
include .mk/cypress.mk
224224
include .mk/shortcuts.mk
225225
include .mk/standalone.mk
226+
include .mk/static.mk

pkg/config/config.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,15 @@ type Config struct {
146146
Frontend Frontend `yaml:"frontend" json:"frontend"`
147147
Server Server `yaml:"server,omitempty" json:"server,omitempty"`
148148
Path string `yaml:"-" json:"-"`
149+
Static bool
149150
}
150151

151152
func ReadFile(version, date, filename string) (*Config, error) {
153+
isStatic := len(filename) == 0
152154
// set default values
153155
cfg := Config{
154-
Path: filename,
156+
Path: filename,
157+
Static: isStatic,
155158
Server: Server{
156159
Port: 9001,
157160
MetricsPort: 9002,
@@ -193,7 +196,10 @@ func ReadFile(version, date, filename string) (*Config, error) {
193196
PromLabels: []string{},
194197
},
195198
}
196-
if len(filename) == 0 {
199+
if isStatic {
200+
// Force TLS
201+
cfg.Server.CertPath = "/var/serving-cert/tls.crt"
202+
cfg.Server.KeyPath = "/var/serving-cert/tls.key"
197203
return &cfg, nil
198204
}
199205
yamlFile, err := os.ReadFile(filename)
@@ -243,7 +249,7 @@ func (c *Config) IsPromEnabled() bool {
243249
}
244250

245251
func (c *Config) Validate() error {
246-
if !c.IsLokiEnabled() && !c.IsPromEnabled() {
252+
if !c.Static && !c.IsLokiEnabled() && !c.IsPromEnabled() {
247253
return errors.New("neither Loki nor Prometheus is configured; at least one of them should have a URL defined")
248254
}
249255

pkg/server/routes.go

+24-18
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,34 @@ func setupRoutes(ctx context.Context, cfg *config.Config, authChecker auth.Check
4141
})
4242
})
4343

44-
// Server status
44+
// Server status and config
4545
api.HandleFunc("/status", h.Status(ctx))
46+
api.HandleFunc("/frontend-config", h.GetFrontendConfig())
4647

47-
// Loki endpoints
48-
api.HandleFunc("/loki/ready", h.LokiReady())
49-
api.HandleFunc("/loki/metrics", forceCheckAdmin(authChecker, h.LokiMetrics()))
50-
api.HandleFunc("/loki/buildinfo", forceCheckAdmin(authChecker, h.LokiBuildInfos()))
51-
api.HandleFunc("/loki/config/limits", forceCheckAdmin(authChecker, h.LokiLimits()))
52-
api.HandleFunc("/loki/flow/records", h.GetFlows(ctx))
53-
api.HandleFunc("/loki/export", h.ExportFlows(ctx))
48+
if cfg.Static {
49+
// Expose static files only
50+
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./web/dist/static")))
51+
} else {
52+
// Loki endpoints
53+
api.HandleFunc("/loki/ready", h.LokiReady())
54+
api.HandleFunc("/loki/metrics", forceCheckAdmin(authChecker, h.LokiMetrics()))
55+
api.HandleFunc("/loki/buildinfo", forceCheckAdmin(authChecker, h.LokiBuildInfos()))
56+
api.HandleFunc("/loki/config/limits", forceCheckAdmin(authChecker, h.LokiLimits()))
57+
api.HandleFunc("/loki/flow/records", h.GetFlows(ctx))
58+
api.HandleFunc("/loki/export", h.ExportFlows(ctx))
5459

55-
// Common endpoints
56-
api.HandleFunc("/flow/metrics", h.GetTopology(ctx))
57-
api.HandleFunc("/resources/clusters", h.GetClusters(ctx))
58-
api.HandleFunc("/resources/udns", h.GetUDNs(ctx))
59-
api.HandleFunc("/resources/zones", h.GetZones(ctx))
60-
api.HandleFunc("/resources/namespaces", h.GetNamespaces(ctx))
61-
api.HandleFunc("/resources/names", h.GetNames(ctx))
60+
// Common endpoints
61+
api.HandleFunc("/flow/metrics", h.GetTopology(ctx))
62+
api.HandleFunc("/resources/clusters", h.GetClusters(ctx))
63+
api.HandleFunc("/resources/udns", h.GetUDNs(ctx))
64+
api.HandleFunc("/resources/zones", h.GetZones(ctx))
65+
api.HandleFunc("/resources/namespaces", h.GetNamespaces(ctx))
66+
api.HandleFunc("/resources/names", h.GetNames(ctx))
67+
68+
// Frontend files
69+
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./web/dist/")))
70+
}
6271

63-
// Frontend files
64-
api.HandleFunc("/frontend-config", h.GetFrontendConfig())
65-
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./web/dist/")))
6672
return r
6773
}
6874

0 commit comments

Comments
 (0)