Skip to content
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
91 changes: 48 additions & 43 deletions Dockerfile
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 removed backend/bun.lockb
Binary file not shown.
33 changes: 18 additions & 15 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
"name": "@curatedotfun/backend",
"version": "0.0.1",
"packageManager": "bun@1.0.27",
"type": "module",
"scripts": {
"build": "bun build ./src/index.ts --target=bun --outdir=dist --format=esm --external './src/external' && cp -r src/external dist/external/",
"start": "bun run dist/index.js",
"dev": "bun run --watch src/index.ts",
"build": "rspack build",
"start": "rspack build && node dist/main.js",
"dev": "NODE_ENV=development nodemon --exec \"rspack build && node dist/main.js\" --watch src",
"test": "bun test",
"test:watch": "bun test --watch",
"db:generate": "bun drizzle-kit generate",
Expand All @@ -30,29 +29,33 @@
]
},
"devDependencies": {
"@module-federation/node": "^2.6.22",
"@rspack/cli": "latest",
"@types/better-sqlite3": "^7.6.9",
"@types/node": "^20.11.24",
"@types/ora": "^3.2.0",
"bun-types": "^1.1.43",
"concurrently": "^9.1.2",
"drizzle-kit": "^0.30.1",
"jest": "^29.7.0",
"jest-mock-extended": "^4.0.0-beta1",
"nodemon": "^3.1.9",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.1",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"wait-on": "^8.0.2",
"zod": "^3.22.4"
},
"dependencies": {
"@elysiajs/cors": "^1.2.0",
"@elysiajs/static": "^1.2.0",
"@elysiajs/swagger": "^1.2.0",
"@libsql/client": "^0.14.0",
"@hono/node-server": "^1.8.2",
"@hono/zod-openapi": "^0.9.5",
"@hono/zod-validator": "^0.1.11",
"@notionhq/client": "^2.2.15",
"@types/cors": "^2.8.17",
"agent-twitter-client": "^0.0.16",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"better-sqlite3": "11.8.1",
"dotenv": "^16.4.7",
"drizzle-orm": "^0.38.3",
"elysia": "^1.2.10",
"elysia-helmet": "^2.0.0",
"express": "^4.18.2",
"hono": "^4.0.5",
"ora": "^8.1.1",
"winston": "^3.17.0",
"winston-console-format": "^1.0.8"
Expand Down
59 changes: 59 additions & 0 deletions backend/rspack.config.js
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
// },
// }
// })
Comment on lines +46 to +57
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

],
};
Loading