Skip to content

Embed React frontend via go:embed and update CI to use make build & make image#14

Merged
ianchen0119 merged 4 commits intomainfrom
copilot/compile-react-embed-backend
Feb 19, 2026
Merged

Embed React frontend via go:embed and update CI to use make build & make image#14
ianchen0119 merged 4 commits intomainfrom
copilot/compile-react-embed-backend

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

The build pipeline had two gaps: the React frontend in web/ was not embedded into the Go binary, and CI was using raw go build instead of the Makefile targets that include the frontend build step.

Frontend embedding (manager mode only)

  • web/embed.go//go:embed all:dist exposes built assets as embed.FS
  • manager/rest/frontend.go — serves embedded SPA with index.html fallback for client-side routing; no-ops gracefully if frontend wasn't built (checks for index.html presence)
  • manager/app/rest_app.go — calls RegisterFrontend(engine) after API routes, so /api/v1/*, /health, /swagger/* take precedence over the GET /* wildcard

Build pipeline

  • Makefile — new build-web target (npm ci && npm run build); build now depends on it
  • Dockerfile — added node:22-alpine stage to build frontend assets before the Go builder stage

CI/CD

  • .github/workflows/ci.yml — replaced go mod download + go build -v ./... with make build + make image; added actions/setup-node@v4 for Node.js 22

Housekeeping

  • web/.gitignore updated to track dist/.gitkeep while ignoring build output
  • web/dist/.gitkeep placeholder so go:embed compiles without a frontend build

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 18, 2026 16:00
- Add web/embed.go with go:embed directive for web/dist
- Add manager/rest/frontend.go to serve embedded SPA with index.html fallback
- Register frontend routes in manager's StartRestApp
- Add Node.js build stage to Dockerfile
- Add build-web target to Makefile
- Update .gitignore for web/dist and web/node_modules

Co-authored-by: ianchen0119 <42661015+ianchen0119@users.noreply.github.com>
Co-authored-by: ianchen0119 <42661015+ianchen0119@users.noreply.github.com>
Copilot AI changed the title [WIP] Compile React frontend and embed in Go backend Embed React frontend into manager binary via go:embed Feb 18, 2026
Copilot AI requested a review from ianchen0119 February 18, 2026 16:05
@ianchen0119 ianchen0119 requested a review from Copilot February 18, 2026 16:26
@ianchen0119 ianchen0119 marked this pull request as ready for review February 18, 2026 16:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements frontend embedding by building the React application in web/ and embedding it into the Go binary using go:embed, allowing the manager to serve the frontend directly without external dependencies. The decision maker service is unaffected by these changes.

Changes:

  • Added go:embed directive in web/embed.go to embed the React build output into the binary
  • Implemented SPA-aware static file serving in manager/rest/frontend.go with fallback to index.html for client-side routing
  • Integrated multi-stage Docker build with Node.js frontend build stage and Makefile build-web target

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
web/embed.go Exports the built frontend assets via go:embed all:dist directive
web/dist/.gitkeep Placeholder file ensuring the dist directory exists for go:embed compilation
web/.gitignore Updated to track .gitkeep while ignoring other dist contents
manager/rest/frontend.go Implements SPA serving logic with static asset handling and client-side routing fallback
manager/rest/frontend_test.go Unit tests for frontend serving with and without index.html
manager/app/rest_app.go Integrates frontend registration into the REST app startup sequence
Makefile Adds build-web target for frontend build and wires it into the main build
Dockerfile Adds Node.js build stage for frontend compilation before Go build

Comment on lines +16 to +19
distFS, err := fs.Sub(web.DistFS, "dist")
if err != nil {
return
}
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error from fs.Sub is silently ignored. This could hide configuration issues or embed problems during startup. Consider logging the error to help with debugging if the frontend fails to load. The codebase uses logger.Logger for similar initialization issues (e.g., in manager/app/rest_app.go and manager/service/strategy_svc.go).

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +29
if !hasIndex {
return
}
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider logging when the frontend is not registered (either because fs.Sub failed or index.html is missing). This would help developers understand whether the frontend is being served or not, especially in development environments. For example, log an info message like "Frontend not registered: index.html not found" when hasIndex is false.

Copilot uses AI. Check for mistakes.
Switch build verification to use Makefile targets:
- Add Node.js setup for frontend build
- Use make build (deps + frontend + Go binary)
- Add make image to verify Docker image builds

Co-authored-by: ianchen0119 <42661015+ianchen0119@users.noreply.github.com>
Copilot AI changed the title Embed React frontend into manager binary via go:embed Embed React frontend via go:embed and update CI to use make build & make image Feb 18, 2026
@ianchen0119 ianchen0119 merged commit 94b50f5 into main Feb 19, 2026
2 checks passed
@ianchen0119 ianchen0119 deleted the copilot/compile-react-embed-backend branch February 19, 2026 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants