-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
95 lines (76 loc) · 2.85 KB
/
Dockerfile
File metadata and controls
95 lines (76 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
# Stage 1: Builder
# Build the TypeScript application
FROM node:20-bookworm-slim AS builder
WORKDIR /build
# Copy package files
COPY package*.json ./
COPY tsconfig.json ./
# Install dependencies (including devDependencies for build)
RUN npm ci
# Copy source code
COPY src/ ./src/
# Compile TypeScript to JavaScript
RUN npm run build
# Remove dev dependencies
RUN npm prune --production
# Stage 2: Runtime
# Create minimal production image with LibreOffice
FROM debian:bookworm-slim
# Install Node.js 20 from NodeSource repository
RUN apt-get update && \
apt-get install -y ca-certificates curl gnupg && \
mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
# Enable contrib repository for ttf-mscorefonts-installer
RUN echo "deb http://deb.debian.org/debian bookworm contrib" >> /etc/apt/sources.list
# Install runtime dependencies:
# - nodejs: Node.js runtime
# - libreoffice-writer-nogui: LibreOffice without GUI for document conversion
# - libreoffice-java-common: Java support for LibreOffice
# - ghostscript: PDF processing
# - fonts-dejavu fonts-liberation: Common fonts
# - ttf-mscorefonts-installer: Microsoft core fonts (Arial, Times New Roman, etc.)
# - curl: For health checks
RUN apt-get update && \
echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections && \
apt-get install -y \
nodejs \
libreoffice-writer-nogui \
libreoffice-java-common \
ghostscript \
fonts-dejavu \
fonts-liberation \
ttf-mscorefonts-installer \
curl \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Create non-root user with fixed UID/GID
RUN groupadd -r -g 1000 appuser && \
useradd -r -u 1000 -g appuser -m -s /bin/bash appuser
# Set working directory
WORKDIR /app
# Copy compiled code from builder
COPY --from=builder /build/dist ./dist
COPY --from=builder /build/node_modules ./node_modules
COPY --from=builder /build/package*.json ./
# Create /tmp directory and set permissions
# LibreOffice and document conversion need write access to /tmp
RUN mkdir -p /tmp && \
chmod 1777 /tmp && \
chown -R appuser:appuser /app
# Set environment variables
ENV NODE_ENV=production
ENV PORT=8080
ENV TMPDIR=/tmp
# Expose application port
EXPOSE 8080
# Add health check
# Check every 30 seconds, timeout after 10 seconds, start after 60 seconds, allow 3 retries
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/healthz || exit 1
# Switch to non-root user
USER appuser
# Start the application
CMD ["node", "dist/server.js"]