-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
120 lines (85 loc) · 2.85 KB
/
Dockerfile
File metadata and controls
120 lines (85 loc) · 2.85 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Multi-stage build for optimal production image
# ================================
# Build Stage
# ================================
FROM oven/bun:1.3.5-alpine AS builder
# Set working directory
WORKDIR /app
# Copy package files for dependency installation
COPY package.json bun.lock* ./
# Install all dependencies (including devDependencies for build)
RUN bun install --frozen-lockfile
# Copy source code and configuration files
COPY . .
# Generate Prisma client
RUN bunx prisma generate
# Type check the application
# RUN bun run typecheck
# ================================
# Development Stage (for local development)
# ================================
FROM oven/bun:1.3.5-alpine AS development
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Set working directory
WORKDIR /app
# Create non-root user for security
RUN addgroup -g 1001 -S radon && \
adduser -S radon -u 1001
# Copy package files
COPY package.json bun.lock* ./
# Install all dependencies (including dev dependencies)
RUN bun install --frozen-lockfile
# Copy source code
COPY . .
# Generate Prisma client
RUN bunx prisma generate
# Create logs directory
RUN mkdir -p /app/logs
# Change ownership of the app directory to the radon user
RUN chown -R radon:radon /app
# Switch to non-root user
USER radon
# Set environment variables
ENV NODE_ENV=development
# Use dumb-init to handle signals properly
ENTRYPOINT ["dumb-init", "--"]
# Default command for development (can be overridden)
CMD ["bun", "dev"]
# ================================
# Production Stage (FINAL - Railway will use this by default)
# ================================
FROM oven/bun:1.3.5-alpine AS production
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Create app directory
WORKDIR /app
# Create non-root user for security
RUN addgroup -g 1001 -S radon && \
adduser -S radon -u 1001
# Copy package.json and bun.lock for production install
COPY package.json bun.lock* ./
# Install only production dependencies
RUN bun install --frozen-lockfile --production && \
bun pm cache rm
# Copy built application from builder stage
COPY --from=builder /app/src ./src
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/tsconfig.base.json ./tsconfig.base.json
# Create logs directory
RUN mkdir -p /app/logs
# Change ownership of the app directory to the radon user
RUN chown -R radon:radon /app
# Switch to non-root user
USER radon
# Set environment variables
ENV NODE_ENV=production
ENV BUN_ENV=production
# Health check to ensure the bot is running properly
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
CMD pgrep -f "bun" > /dev/null || exit 1
# Use dumb-init to handle signals properly
ENTRYPOINT ["dumb-init", "--"]
# Start the Discord bot
CMD ["bun", "start"]