-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
95 lines (69 loc) · 2.73 KB
/
Dockerfile
File metadata and controls
95 lines (69 loc) · 2.73 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# =============================================================================
# Base Stage - Common dependencies for all services
# =============================================================================
FROM oven/bun:1-alpine AS base
WORKDIR /app
# Copy package files
COPY package.json ./
COPY packages/api/package.json ./packages/api/
COPY packages/web/package.json ./packages/web/
COPY packages/db/package.json ./packages/db/
# Install all dependencies
RUN bun install
# Copy source code
COPY packages ./packages
# =============================================================================
# API Production Stage - Final API image
# =============================================================================
FROM oven/bun:1-alpine AS api
WORKDIR /app
# Install production dependencies only
COPY package.json ./
COPY packages/api/package.json ./packages/api/
COPY packages/db/package.json ./packages/db/
RUN bun install
# Copy application code
COPY packages/api ./packages/api
COPY packages/db ./packages/db
# Generate Prisma Client in the final stage
RUN cd packages/db && bun prisma generate
# Create logs directory
RUN mkdir -p /app/logs && \
chown -R bun:bun /app
USER bun
# Expose API port
EXPOSE 3001
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD bun run -e "fetch('http://localhost:3001/api/health').then(r => r.ok ? process.exit(0) : process.exit(1))"
# Run database migrations and start server
WORKDIR /app/packages/api
CMD ["sh", "-c", "cd ../db && bun prisma migrate deploy && cd ../api && bun src/index.ts"]
# =============================================================================
# Web Build Stage - Build frontend with Vite
# =============================================================================
FROM base AS web-builder
WORKDIR /app/packages/web
# Build arguments for environment variables
ARG VITE_API_URL=http://localhost:3001
ENV VITE_API_URL=$VITE_API_URL
# Build the application
RUN bun run build
# =============================================================================
# Web Production Stage - Serve with Nginx
# =============================================================================
FROM nginx:alpine AS web
# Copy built static files
COPY --from=web-builder /app/packages/web/dist /usr/share/nginx/html
# Copy custom nginx configuration
COPY nginx-web.conf /etc/nginx/conf.d/default.conf
# Create nginx user and set permissions
RUN chown -R nginx:nginx /usr/share/nginx/html && \
chmod -R 755 /usr/share/nginx/html
# Expose port 80
EXPOSE 80
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1
# Start nginx
CMD ["nginx", "-g", "daemon off;"]