Skip to content

Commit 9fb4eb6

Browse files
committed
feat: add Dockerfile for Railway deployment with Prisma Client generation and database migrations
1 parent fb654b6 commit 9fb4eb6

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Dockerfile for Auralyze API
2+
# Handles Prisma Client generation and database migrations
3+
4+
FROM node:22-slim
5+
6+
# Install OpenSSL for Prisma
7+
RUN apt-get update -y && apt-get install -y openssl && rm -rf /var/lib/apt/lists/*
8+
9+
WORKDIR /app
10+
11+
# Copy package files
12+
COPY package*.json ./
13+
COPY prisma ./prisma/
14+
15+
# Install all dependencies (including dev dependencies for build)
16+
RUN npm ci
17+
18+
# Generate Prisma Client (critical step!)
19+
RUN npx prisma generate
20+
21+
# Copy source code
22+
COPY . .
23+
24+
# Build TypeScript
25+
RUN npm run build
26+
27+
# Remove dev dependencies to reduce image size
28+
# Note: Prisma Client generated files are in node_modules/.prisma and will be kept
29+
RUN npm prune --production
30+
31+
# Verify Prisma Client is still available after prune
32+
RUN node -e "const { PrismaClient } = require('@prisma/client'); console.log('Prisma Client available');"
33+
34+
# Expose port
35+
EXPOSE 8080
36+
37+
# Run database migrations then start server
38+
# This ensures migrations run on every deployment
39+
CMD ["sh", "-c", "npm run db:deploy && npm start"]

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,34 @@ Response: `EngineState` from `@auralyze/engine` with all analysis results. Inclu
117117
- Prisma client handles DB writes; sanitize tokens via environment variables.
118118
- CI/CD should run `npm run ci` and `npx prisma migrate deploy` before `npm start`.
119119

120+
## Docker Build
121+
122+
Build the API service for Railway deployment:
123+
124+
```bash
125+
docker build -t auralyze-api .
126+
docker run -p 8080:8080 --env-file .env auralyze-api
127+
```
128+
129+
The Dockerfile handles:
130+
131+
- **Prisma Client Generation**: Runs `npx prisma generate` during build
132+
- **Database Migrations**: Runs `npm run db:deploy` on container start
133+
- **TypeScript Compilation**: Builds to `dist/` directory
134+
135+
::: tip Railway Deployment
136+
When deploying to Railway as a standalone repository:
137+
138+
1. Ensure `Dockerfile` exists in repo root (Railway auto-detects it)
139+
2. Add database reference: `DATABASE_URL=${{Postgres.DATABASE_URL}}`
140+
3. Configure service references for internal networking:
141+
- `METADATA_SERVICE_URL=https://metadata.railway.internal`
142+
- `ANALYSIS_SERVICE_URL=https://analysis.railway.internal`
143+
4. Generate and set API keys for service authentication
144+
145+
The Dockerfile ensures Prisma Client is generated **before** runtime, preventing `@prisma/client did not initialize` errors.
146+
:::
147+
120148
## Contributing & Support
121149

122150
- Read `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md`, and `SECURITY.md` before submitting changes.

0 commit comments

Comments
 (0)