forked from elliotBraem/efizzybot
-
Notifications
You must be signed in to change notification settings - Fork 7
Migrates plugins to use module federation #63
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0e2901f
Adds module federation support for distributor + transformer plugins …
elliotBraem f9808b3
add necessary dependencies for better-sqlite-3
elliotBraem 55238b5
remove libsql and copy over frontend dist
elliotBraem 30df9c1
install @libsql/client
elliotBraem 8871886
adds externals
elliotBraem 4bcbd39
fmt
elliotBraem 0bc96c7
use node for building
elliotBraem c43d0bc
convert to better-sqlite-3
elliotBraem c9139c4
improve docker image
elliotBraem 22d1314
fmt
elliotBraem 1c16a7d
migrate to hono and node
elliotBraem d229058
clean up
elliotBraem a5c78c6
nodemon
elliotBraem 415dc40
fmt
elliotBraem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,78 +1,83 @@ | ||
| ## NOTE | ||
| # This Dockerfile builds the frontend and backend separately, | ||
| # frontend uses npm and backend requires bun. | ||
| # This separation is a temporary solution for a Bun issue with rsbuild, | ||
| # see: https://github.com/oven-sh/bun/issues/11628 | ||
|
|
||
| # Frontend deps & build stage | ||
| FROM node:20 as frontend-builder | ||
| # Build stage | ||
| FROM node:20 AS builder | ||
| WORKDIR /app | ||
|
|
||
| # Copy frontend package files | ||
| # Install build dependencies | ||
| RUN apt-get update && \ | ||
| apt-get install -y --no-install-recommends \ | ||
| python3 \ | ||
| make \ | ||
| g++ \ | ||
| && rm -rf /var/lib/apt/lists/* && \ | ||
| apt-get clean | ||
|
|
||
| # Copy package files | ||
| COPY package.json ./ | ||
| COPY frontend/package.json ./frontend/ | ||
| COPY backend/package.json ./backend/ | ||
| COPY backend/drizzle.config.ts ./backend/ | ||
|
|
||
| # Install frontend dependencies | ||
| # Install dependencies | ||
| RUN cd frontend && npm install | ||
| RUN cd backend && npm install | ||
|
|
||
| # Copy frontend source code | ||
| # Copy source code | ||
| COPY frontend ./frontend | ||
| COPY backend ./backend | ||
|
|
||
| # Build frontend | ||
| RUN cd frontend && npm run build | ||
|
|
||
| # Backend deps & build stage | ||
| FROM oven/bun as backend-builder | ||
| WORKDIR /app | ||
|
|
||
| # Copy backend package files | ||
| COPY package.json ./ | ||
| COPY backend/package.json ./backend/ | ||
| COPY backend/drizzle.config.ts ./backend/ | ||
|
|
||
| # Install backend dependencies | ||
| RUN cd backend && bun install | ||
|
|
||
| # Copy backend source code | ||
| COPY backend ./backend | ||
|
|
||
| # Build backend (rspack will copy frontend dist to backend/dist/public) | ||
| ENV NODE_ENV="production" | ||
|
|
||
| # Build backend | ||
| RUN cd backend && bun run build | ||
| RUN cd backend && npm run build | ||
|
|
||
| # Production stage | ||
| FROM oven/bun as production | ||
| FROM node:20-slim AS production | ||
| WORKDIR /app | ||
|
|
||
| # Install LiteFS dependencies | ||
| RUN apt-get update -y && apt-get install -y ca-certificates fuse3 sqlite3 | ||
| # Install LiteFS and runtime dependencies | ||
| RUN apt-get update -y && \ | ||
| apt-get install -y --no-install-recommends \ | ||
| ca-certificates \ | ||
| curl \ | ||
| fuse3 \ | ||
| sqlite3 \ | ||
| python3 \ | ||
| make \ | ||
| g++ \ | ||
| && rm -rf /var/lib/apt/lists/* && \ | ||
| apt-get clean | ||
|
|
||
| # Copy LiteFS binary | ||
| COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs | ||
|
|
||
| # Create directories for mounts with correct permissions | ||
| RUN mkdir -p /litefs /var/lib/litefs && \ | ||
| chown -R bun:bun /litefs /var/lib/litefs | ||
| chown -R node:node /litefs /var/lib/litefs | ||
|
|
||
| # Create volume mount points | ||
| # Set environment variables first | ||
| ENV DATABASE_URL="file:/litefs/db" | ||
| ENV FRONTEND_DIST_PATH="/app/frontend/dist" | ||
|
|
||
| # Copy only necessary files from builders | ||
| COPY --from=backend-builder --chown=bun:bun /app/package.json ./ | ||
| COPY --chown=bun:bun curate.config.json ./ | ||
| # Copy application files | ||
| COPY --from=builder --chown=node:node /app/package.json ./ | ||
| COPY --chown=node:node curate.config.json ./ | ||
| COPY --from=builder --chown=node:node /app/backend ./backend | ||
|
|
||
| COPY --from=frontend-builder --chown=bun:bun /app/frontend/dist ./frontend/dist | ||
| COPY --from=backend-builder --chown=bun:bun /app/backend ./backend | ||
| # Install production dependencies and rebuild better-sqlite3 | ||
| RUN cd backend && \ | ||
| npm install && \ | ||
| npm rebuild better-sqlite3 | ||
|
|
||
| RUN cd backend && bun install | ||
| # Copy LiteFS configuration | ||
| COPY --chown=node:node litefs.yml /etc/litefs.yml | ||
|
|
||
| # Expose the port | ||
| EXPOSE 3000 | ||
|
|
||
| # Copy LiteFS configuration | ||
| COPY --chown=bun:bun litefs.yml /etc/litefs.yml | ||
| # Set secure environment defaults | ||
| ENV NODE_ENV=production \ | ||
| NPM_CONFIG_LOGLEVEL=warn | ||
|
|
||
| # Start LiteFS (runs app with distributed file system for SQLite) | ||
| ENTRYPOINT ["litefs", "mount"] |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| require("dotenv").config(); | ||
| const path = require("path"); | ||
| const { rspack } = require("@rspack/core"); | ||
|
|
||
| const isProduction = process.env.NODE_ENV === "production"; | ||
|
|
||
| module.exports = { | ||
| entry: "./src/index", | ||
| mode: isProduction ? "production" : "development", | ||
| target: "async-node", | ||
| devtool: "source-map", | ||
| externals: { | ||
| "better-sqlite3": "commonjs better-sqlite3", | ||
| bufferutil: "commonjs bufferutil", | ||
| }, | ||
| output: { | ||
| path: path.resolve(__dirname, "dist"), | ||
| clean: true, | ||
| }, | ||
| module: { | ||
| rules: [ | ||
| { | ||
| test: /\.tsx?$/, | ||
| use: "builtin:swc-loader", | ||
| exclude: /node_modules/, | ||
| }, | ||
| { | ||
| test: /\.md$/, | ||
| type: "asset/source", | ||
| }, | ||
| ], | ||
| }, | ||
| resolve: { | ||
| extensions: [".tsx", ".ts", ".js"], | ||
| }, | ||
| plugins: [ | ||
| new rspack.CopyRspackPlugin({ | ||
| patterns: [ | ||
| { | ||
| from: "../frontend/dist", | ||
| to: "public", | ||
| noErrorOnMissing: true, // Don't error in development when dist doesn't exist | ||
| }, | ||
| ], | ||
| }), | ||
| // new rspack.container.ModuleFederationPlugin({ | ||
| // name: "host", | ||
| // runtimePlugins: [ | ||
| // require.resolve("@module-federation/node/runtimePlugin"), | ||
| // ], | ||
| // shared: { | ||
| // "@curatedotfun/types": { | ||
| // singleton: true, | ||
| // eager: true | ||
| // }, | ||
| // } | ||
| // }) | ||
| ], | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Complete module federation configuration.
The commented-out module federation plugin configuration suggests incomplete migration. Since the PR title mentions "Migrates plugins to use module federation", this configuration should be completed.
Please uncomment and complete the module federation configuration. I can help you with the implementation if needed.