-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
58 lines (46 loc) · 2.04 KB
/
Dockerfile
File metadata and controls
58 lines (46 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File: Dockerfile
# Purpose: Build and run the full-stack app (Express API + Vite React client) on Railway using a multi-stage Docker build.
# How it works: Stage 1 installs deps and runs `npm run build` to produce the client at `dist/public`.
# Stage 2 copies built assets and TS server sources, then starts with `tsx server/index.ts` (no esbuild bundling).
# How the project uses it: Railway detects this Dockerfile (via railway.json builder) and deploys a single container serving API and static UI.
# Author: Cascade (Windsurf)
# Multi-stage Dockerfile for Railway deployment
# Stage 1: Build (install dev deps and build client+server)
FROM node:20-slim AS builder
WORKDIR /app
# Install dependencies first for layer caching
COPY package.json package-lock.json* ./
# Prefer clean reproducible installs; fall back to install if lockfile absent
RUN npm ci || npm install
# Copy source
COPY tsconfig.json ./
COPY vite.config.ts ./
COPY client ./client
COPY server ./server
COPY shared ./shared
COPY attached_assets ./attached_assets
COPY tailwind.config.ts ./
COPY postcss.config.js ./
COPY components.json ./
# Accept build-time environment variables (Railway will pass these automatically)
ARG VITE_STRIPE_PUBLIC_KEY
ENV VITE_STRIPE_PUBLIC_KEY=$VITE_STRIPE_PUBLIC_KEY
# Build: produces client at dist/public and server bundle at dist/index.js
ENV NODE_ENV=production
RUN npm run build
# Stage 2: Runtime (only required files)
FROM node:20-slim AS runner
ENV NODE_ENV=production
WORKDIR /app
# Copy only the production node_modules and built artifacts
COPY --from=builder /app/node_modules ./node_modules
# No additional runtime dependencies needed for compiled JS
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/server ./server
COPY --from=builder /app/shared ./shared
COPY --from=builder /app/client/public/docs ./client/public/docs
# Document default port; Railway will inject its own PORT
EXPOSE 5000
# Start the bundled server; serves API + static from one port
CMD ["node", "dist/index.js"]