Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): embed and serve UI assets from Burrito binary #191

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Build Burrito UI

FROM docker.io/library/node:20.9.0@sha256:cb7cd40ba6483f37f791e1aace576df449fc5f75332c19ff59e2c6064797160e AS builder-ui

WORKDIR /workspace
# Copy the node modules manifests
COPY ui/package.json ui/yarn.lock ./
# Install build dependencies
RUN yarn install --frozen-lockfile

# Copy the UI source
COPY ui .
# Set the API base URL
ENV VITE_API_BASE_URL=/api
RUN yarn build

# Build the manager binary
FROM docker.io/library/golang:1.20.7@sha256:bc5f0b5e43282627279fe5262ae275fecb3d2eae3b33977a7fd200c7a760d6f1 as builder
ARG TARGETOS
Expand All @@ -20,6 +36,8 @@ COPY main.go main.go
COPY api/ api/
COPY internal/ internal/
COPY cmd/ cmd/
# Copy the UI build artifacts
COPY --from=builder-ui /workspace/dist internal/server/dist

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
Expand Down
Empty file added internal/server/dist/.gitkeep
Empty file.
35 changes: 24 additions & 11 deletions internal/server/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"embed"
"net/http"

"github.com/labstack/echo/v4"
Expand All @@ -18,18 +19,23 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

//go:embed all:dist
var content embed.FS

type Server struct {
config *config.Config
Webhook *webhook.Webhook
API *api.API
client client.Client
config *config.Config
Webhook *webhook.Webhook
API *api.API
staticAssets http.FileSystem
client client.Client
}

func New(c *config.Config) *Server {
return &Server{
config: c,
Webhook: webhook.New(c),
API: api.New(c),
config: c,
Webhook: webhook.New(c),
API: api.New(c),
staticAssets: http.FS(content),
}
}

Expand Down Expand Up @@ -61,11 +67,18 @@ func (s *Server) Exec() {
log.Infof("starting burrito server...")
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.CORS())
e.Use(middleware.StaticWithConfig(
middleware.StaticConfig{
Filesystem: s.staticAssets,
Root: "dist",
Index: "index.html",
HTML5: true,
},
))
e.GET("/healthz", handleHealthz)
e.POST("/webhook", s.Webhook.GetHttpHandler())
e.GET("/layers", s.API.LayersHandler)
e.GET("/repositories", s.API.RepositoriesHandler)
e.POST("/api/webhook", s.Webhook.GetHttpHandler())
e.GET("/api/layers", s.API.LayersHandler)
e.GET("/api/repositories", s.API.RepositoriesHandler)
e.Logger.Fatal(e.Start(s.config.Server.Addr))
log.Infof("burrito server started on addr %s", s.config.Server.Addr)
}
Expand Down