-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
69 lines (54 loc) · 1.49 KB
/
Dockerfile
File metadata and controls
69 lines (54 loc) · 1.49 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
# Multi-stage Docker build for production optimization
# Base stage with common dependencies
FROM node:20-alpine AS base
WORKDIR /app
# Install bun for better performance
RUN npm install -g bun
# Copy package files
COPY package.json bun.lock* ./
# Dependencies stage
FROM base AS deps
RUN apk add --no-cache libc6-compat
RUN bun install --frozen-lockfile --production=false
# Build stage
FROM base AS builder
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Set environment variables for build
ENV NODE_ENV=production
ENV NITRO_PRESET=node-server
# Build the application
RUN bun run build
# Production stage
FROM node:20-alpine AS runner
WORKDIR /app
# Create non-root user for security
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nuxtjs
# Copy built application
COPY --from=builder --chown=nuxtjs:nodejs /app/.output ./
# Set environment
ENV NODE_ENV=production
ENV PORT=3000
ENV HOST=0.0.0.0
# Security: don't run as root
USER nuxtjs
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node --input-type=module --eval "
import http from 'http';
const options = {
host: 'localhost',
port: process.env.PORT || 3000,
path: '/api/health',
timeout: 2000,
};
const req = http.request(options, (res) => {
if (res.statusCode === 200) process.exit(0);
else process.exit(1);
});
req.on('error', () => process.exit(1));
req.end();
"
EXPOSE 3000
CMD ["node", "server/index.mjs"]