Skip to content

Commit eefbf05

Browse files
committed
refactor: update Dockerfile for multi-stage build and add static file embedding for improved resource handling
1 parent 5f699bf commit eefbf05

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
# Start by building the application.
2-
FROM golang:1.24-bookworm AS build
2+
FROM node:22-alpine AS build-web
3+
WORKDIR /app
4+
COPY . .
5+
RUN npm install
6+
RUN npm run build
37

8+
FROM golang:1.24-alpine AS build
49
WORKDIR /go/src/kuview
510
COPY . .
11+
COPY --from=build-web /app/dist /go/src/kuview/dist
612

713
ENV CGO_ENABLED=0
8-
RUN go build -o /go/bin/kuview cmd/server/main.go
14+
RUN go build -v -o /go/bin/kuview cmd/server/main.go
15+
916

10-
FROM node:22-alpine AS build-web
11-
WORKDIR /app
12-
COPY . .
13-
RUN npm install
14-
RUN npm run build
1517

1618
# Now copy it into our base image.
1719
FROM gcr.io/distroless/static-debian12
1820
WORKDIR /app
1921
COPY --from=build /go/bin/kuview /app/kuview
20-
COPY --from=build-web /app/dist /app/dist
2122

2223
EXPOSE 8001
2324
CMD ["/app/kuview"]

pkg/server/server.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"sync"
88

9+
"github.com/iwanhae/kuview"
910
"github.com/iwanhae/kuview/pkg/controller"
1011
"github.com/iwanhae/kuview/pkg/server/middleware"
1112
"github.com/labstack/echo/v4"
@@ -62,8 +63,10 @@ func New(cfg *rest.Config) (*Server, error) {
6263
},
6364
}))
6465
static.Use(echomiddleware.StaticWithConfig(echomiddleware.StaticConfig{
65-
Root: "dist",
66-
HTML5: true,
66+
Root: "dist",
67+
HTML5: true,
68+
Browse: true,
69+
Filesystem: http.FS(kuview.DistFS),
6770
}))
6871

6972
s.Use(middleware.RequestID())

static.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package kuview
2+
3+
import "embed"
4+
5+
//go:embed dist
6+
var DistFS embed.FS

0 commit comments

Comments
 (0)