Skip to content
Closed
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
89 changes: 43 additions & 46 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
# syntax=docker/dockerfile:1.4

# Installation stage.
FROM node:22-alpine AS base
WORKDIR /workspace
RUN apk add --update --no-cache openssl python3 make g++
# Install pnpm.
ADD package.json .
# TODO: Remove this once it's no longer needed.
# - https://github.com/pnpm/pnpm/issues/9014#issuecomment-2618565344
# - https://github.com/nodejs/corepack/issues/612
RUN npm install --global corepack@latest
RUN corepack enable && corepack prepare --activate
# Skip prisma code generation during install.
ENV PRISMA_SKIP_POSTINSTALL_GENERATE=true
ENV CI=true
# Fetch all node modules purely based on the pnpm lock file.
COPY pnpm-lock.yaml .
RUN --mount=type=cache,id=workspace,target=/root/.local/share/pnpm/store pnpm fetch
# Copy the entire workspace into the scope and perform the actual installation.
COPY . .
RUN --mount=type=cache,id=workspace,target=/root/.local/share/pnpm/store pnpm install

# Build stage for the server.
FROM base AS build
# TODO: Remove this when we switch to an actual database.
ENV DATABASE_URL="file:./dev.db"
RUN \
# TODO: This initalizes the database. But we should probably remove this later.
pnpm --filter server prisma migrate reset --force && \
# Build the monorepo packages
pnpm build && \
# Generate the prisma client
pnpm --filter server prisma generate && \
# Build the server.
pnpm --filter server build && \
# Create an isolated deployment for the server.
pnpm --filter server deploy --prod deployment --legacy && \
# Move the runtime build artifacts into a separate directory.
mkdir -p deployment/out && mv deployment/dist deployment/prisma deployment/node_modules deployment/package.json deployment/out

# Slim runtime image.
FROM node:22-alpine AS server
# ---- Builder stage ----
FROM node:22-alpine AS build

# 1. Set up pnpm & workspace root
WORKDIR /app
RUN corepack enable && corepack prepare [email protected] --activate

# Copy root manifests first (leverage cache)
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY tsconfig.base.json ./
COPY scripts ./scripts

# Copy workspace packages
COPY packages ./packages
COPY apps ./apps

# 2. Install dependencies
RUN pnpm install --frozen-lockfile

# 3. Build all workspace packages
RUN pnpm --filter @graphprotocol/hypergraph run build
RUN pnpm --filter server run build

# 4. Create a standalone server deployment
RUN pnpm --filter server deploy --legacy dist

# ------------------------------------------------------------
# ---- Runtime stage ----
FROM node:22-alpine AS runtime
WORKDIR /app
COPY --from=build /workspace/deployment/out .
# TODO: Remove this when we switch to an actual database.
ENV NODE_ENV=production

# Copy the standalone deployment from the build stage
COPY --from=build /app/dist .

# Copy the generated Prisma client
COPY --from=build /app/apps/server/generated ./generated

# Copy the SQLite database file and set DATABASE_URL for Prisma
COPY --from=build /app/apps/server/prisma/dev.db ./dev.db

# Point Prisma at the bundled SQLite database
ENV DATABASE_URL="file:./dev.db"

EXPOSE 3030
CMD ["node", "dist/index.js"]
CMD ["node", "dist/index.js"]
8 changes: 8 additions & 0 deletions apps/next-example/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PrismaPlugin } from '@prisma/nextjs-monorepo-workaround-plugin';
import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
Expand All @@ -8,6 +9,13 @@ const nextConfig: NextConfig = {
// '@graphprotocol/hypergraph-react': path.resolve(__dirname, '../../packages/hypergraph-react'),
// },
// },
webpack: (config, { isServer }) => {
if (isServer) {
config.plugins = [...config.plugins, new PrismaPlugin()];
}

return config;
},
};

export default nextConfig;
1 change: 1 addition & 0 deletions apps/next-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@graphprotocol/hypergraph": "workspace:*",
"@graphprotocol/hypergraph-react": "workspace:*",
"@privy-io/react-auth": "^2.13.0",
"@prisma/nextjs-monorepo-workaround-plugin": "^5.22.0",
"next": "15.3.2",
"react": "^19.0.0",
"react-dom": "^19.0.0"
Expand Down
3 changes: 2 additions & 1 deletion apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"dev": "bun run --watch ./src/index.ts",
"prisma": "prisma",
"build": "tsup"
"build": "tsup",
"postinstall": "prisma generate"
},
"dependencies": {
"@graphprotocol/hypergraph": "workspace:*",
Expand Down
6 changes: 3 additions & 3 deletions apps/server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client"
output = "generated/client"
provider = "prisma-client-js"
output = "../generated/client"
moduleFormat = "esm"
binaryTargets = ["native", "linux-musl-openssl-3.0.x"] // linux needed for the deployment
binaryTargets = ["native", "linux-musl-openssl-3.0.x", "rhel-openssl-3.0.x"] // Added rhel for serverless environments
}

datasource db {
Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PrismaClient } from '../prisma/generated/client';
// @ts-ignore – generated at build time, path is correct in Docker
import { PrismaClient } from '../generated/client/index.js';

export const prisma = new PrismaClient();
12 changes: 12 additions & 0 deletions apps/server/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@ export default defineConfig(() => ({
format: ['esm'],
clean: true,
sourcemap: true,
external: [
'@prisma/client',
'../generated/client',
'../generated/client/*',
'node:fs',
'node:path',
'node:os',
'node:crypto',
'node:util',
'node:stream',
'node:url',
],
}));
39 changes: 37 additions & 2 deletions packages/hypergraph/tsconfig.src.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"tsBuildInfoFile": ".tsbuildinfo/src.tsbuildinfo",
"rootDir": "src"
"rootDir": "src",
"strict": true,
"strictNullChecks": true,
"exactOptionalPropertyTypes": true,
"moduleDetection": "force",
"composite": true,
"downlevelIteration": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"declaration": true,
"skipLibCheck": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"types": [],
"isolatedModules": true,
"sourceMap": true,
"declarationMap": true,
"noImplicitReturns": false,
"noUnusedLocals": true,
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": true,
"noEmitOnError": false,
"noErrorTruncation": false,
"allowJs": false,
"checkJs": false,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUncheckedIndexedAccess": false,
"baseUrl": ".",
"incremental": true,
"removeComments": false,
"jsx": "react-jsx"
}
}
Loading
Loading