Skip to content

Commit 6448663

Browse files
feat: implement file server for v3 dashboard (#1295)
1 parent 0a6cfd4 commit 6448663

File tree

13 files changed

+161
-10
lines changed

13 files changed

+161
-10
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,16 @@ $(GO_APP_BUILD_TARGETS): build-%:
151151
.PHONY: clean-web-console
152152
clean-web-console:
153153
rm -rf ui/web-v2/dist/*
154+
rm -rf ui/dashboard/build/*
154155
touch ui/web-v2/dist/DONT-EDIT-FILES-IN-THIS-DIRECTORY
156+
touch ui/dashboard/build/DONT-EDIT-FILES-IN-THIS-DIRECTORY
155157

156158
.PHONY: build-web-console
157159
build-web-console:
158160
rm -rf ui/web-v2/dist/*
161+
rm -rf ui/dashboard/build/*
159162
make -C ui/web-v2 install build
163+
make -C ui/dashboard install build
160164

161165
.PHONY: build-go
162166
build-go: $(GO_APP_BUILD_TARGETS)

manifests/bucketeer/charts/web/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ spec:
164164
value: "{{ .Values.env.pushServicePort }}"
165165
- name: BUCKETEER_WEB_WEB_CONSOLE_SERVICE_PORT
166166
value: "{{ .Values.env.webConsoleServicePort }}"
167+
- name: BUCKETEER_WEB_DASHBOARD_SERVICE_PORT
168+
value: "{{ .Values.env.dashboardServicePort }}"
167169
- name: BUCKETEER_WEB_ACCOUNT_SERVICE
168170
value: "{{ .Values.env.accountService }}"
169171
- name: BUCKETEER_WEB_AUTH_SERVICE

manifests/bucketeer/charts/web/templates/envoy-configmap.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,38 @@ data:
435435
explicit_http_config:
436436
http2_protocol_options: {}
437437
ignore_health_on_host_removal: true
438+
- name: dashboard
439+
type: strict_dns
440+
connect_timeout: 5s
441+
dns_lookup_family: V4_ONLY
442+
lb_policy: {{ .Values.envoy.lbPolicy }}
443+
load_assignment:
444+
cluster_name: dashboard
445+
endpoints:
446+
- lb_endpoints:
447+
- endpoint:
448+
address:
449+
socket_address:
450+
address: localhost
451+
port_value: 9103
452+
transport_socket:
453+
name: envoy.transport_sockets.tls
454+
typed_config:
455+
'@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
456+
common_tls_context:
457+
alpn_protocols:
458+
- h2
459+
tls_certificates:
460+
- certificate_chain:
461+
filename: /usr/local/certs/service/tls.crt
462+
private_key:
463+
filename: /usr/local/certs/service/tls.key
464+
typed_extension_protocol_options:
465+
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
466+
'@type': type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
467+
explicit_http_config:
468+
http2_protocol_options: {}
469+
ignore_health_on_host_removal: true
438470
439471
listeners:
440472
- name: grpc-ingress
@@ -851,6 +883,14 @@ data:
851883
retry_policy:
852884
retry_on: 5xx
853885
num_retries: 3
886+
- match:
887+
prefix: /v3
888+
route:
889+
cluster: dashboard
890+
timeout: 15s
891+
retry_policy:
892+
retry_on: 5xx
893+
num_retries: 3
854894
- match:
855895
prefix: /
856896
route:
@@ -1016,3 +1056,5 @@ data:
10161056
'@type': type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
10171057
# We want disable the warning without setting a limit. So, we set a large number.
10181058
max_active_downstream_connections: 100000
1059+
1060+

manifests/bucketeer/charts/web/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ env:
4949
notificationServicePort: 9100
5050
pushServicePort: 9101
5151
webConsoleServicePort: 9102
52+
dashboardServicePort: 9103
5253
metricsPort: 9002
5354
timezone: UTC
5455
emailFilter:

manifests/bucketeer/values.dev.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ web:
7777
clientSecret:
7878
redirectUrls:
7979
- https://localhost:9000/auth/callback
80+
- https://localhost:9000/v3/auth/callback
8081
demoSignIn:
8182
enabled: true
8283
email: demo@bucketeer.io

pkg/web/cmd/server/server.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ type server struct {
111111
notificationServicePort *int
112112
pushServicePort *int
113113
webConsoleServicePort *int
114+
dashboardServicePort *int
114115
// Service
115116
accountService *string
116117
authService *string
@@ -228,6 +229,10 @@ func RegisterCommand(r cli.CommandRegistry, p cli.ParentCommand) cli.Command {
228229
"web-console-service-port",
229230
"Port to bind to console service.",
230231
).Default("9102").Int(),
232+
dashboardServicePort: cmd.Flag(
233+
"dashboard-service-port",
234+
"Port to bind to dashboard service.",
235+
).Default("9103").Int(),
231236
accountService: cmd.Flag(
232237
"account-service",
233238
"bucketeer-account-service address.",
@@ -640,6 +645,14 @@ func (s *server) Run(ctx context.Context, metrics metrics.Metrics, logger *zap.L
640645
rest.WithMetrics(registerer),
641646
)
642647
go webConsoleServer.Run()
648+
dashboardServer := rest.NewServer(
649+
*s.certPath, *s.keyPath,
650+
rest.WithLogger(logger),
651+
rest.WithPort(*s.dashboardServicePort),
652+
rest.WithService(NewDashboardService()),
653+
rest.WithMetrics(registerer),
654+
)
655+
go dashboardServer.Run()
643656
// To detach this pod from Kubernetes Service before the app servers stop, we stop the health check service first.
644657
// Then, after 10 seconds of sleep, the app servers can be shut down, as no new requests are expected to be sent.
645658
// In this case, the Readiness prove must fail within 10 seconds and the pod must be detached.

pkg/web/cmd/server/web_console.go

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,46 @@ package server
1717
import (
1818
"net/http"
1919
"os"
20+
"strings"
2021

22+
"github.com/bucketeer-io/bucketeer/ui/dashboard"
2123
webv2 "github.com/bucketeer-io/bucketeer/ui/web-v2"
2224
)
2325

2426
type spaFileSystem struct {
25-
root http.FileSystem
27+
root http.FileSystem
28+
prefix string
2629
}
2730

31+
// Open method for spaFileSystem
2832
func (fs *spaFileSystem) Open(name string) (http.File, error) {
33+
// First try with original path
2934
f, err := fs.root.Open(name)
30-
if os.IsNotExist(err) {
31-
return fs.root.Open("index.html")
35+
if !os.IsNotExist(err) {
36+
return f, err
3237
}
33-
return f, err
38+
39+
// If file not found and we have a prefix, try stripping it
40+
if fs.prefix != "" && strings.HasPrefix(name, fs.prefix) {
41+
strippedName := strings.TrimPrefix(name, fs.prefix)
42+
f, err = fs.root.Open(strippedName)
43+
if !os.IsNotExist(err) {
44+
return f, err
45+
}
46+
}
47+
48+
// If still not found, return index.html
49+
return fs.root.Open("index.html")
3450
}
3551

52+
// webConsoleHandler returns a http.Handler for the old web console UI.
3653
func webConsoleHandler() http.Handler {
37-
return http.FileServer(&spaFileSystem{http.FS(webv2.FS)})
54+
return http.FileServer(&spaFileSystem{root: http.FS(webv2.FS)})
55+
}
56+
57+
// dashboardHandler returns a http.Handler for the new dashboard UI.
58+
func dashboardHandler() http.Handler {
59+
return http.FileServer(&spaFileSystem{root: http.FS(dashboard.FS), prefix: "/v3/"})
3860
}
3961

4062
func webConsoleEnvJSHandler(path string) http.Handler {
@@ -54,3 +76,14 @@ func (c WebConsoleService) Register(mux *http.ServeMux) {
5476
mux.HandleFunc("/static/js/",
5577
http.StripPrefix("/static/js/", webConsoleEnvJSHandler(c.consoleEnvJSPath)).ServeHTTP)
5678
}
79+
80+
type DashboardService struct {
81+
}
82+
83+
func NewDashboardService() DashboardService {
84+
return DashboardService{}
85+
}
86+
87+
func (d DashboardService) Register(mux *http.ServeMux) {
88+
mux.HandleFunc("/", dashboardHandler().ServeHTTP)
89+
}

ui/dashboard/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ dist-ssr
77
/coverage
88

99
# production
10-
/build
10+
/build/**
11+
!/build/DONT-EDIT-FILES-IN-THIS-DIRECTORY
1112

1213
# misc
1314
.DS_Store

ui/dashboard/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Makefile for the dashboard UI
2+
3+
# Install dependencies
4+
.PHONY: install
5+
install:
6+
yarn install
7+
8+
# Run the development server
9+
.PHONY: dev
10+
dev:
11+
yarn start
12+
13+
# Build for production
14+
.PHONY: build
15+
build:
16+
VITE_RELEASE_CHANNEL=prod \
17+
yarn build

ui/dashboard/build/DONT-EDIT-FILES-IN-THIS-DIRECTORY

Whitespace-only changes.

0 commit comments

Comments
 (0)