-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainerfile
More file actions
97 lines (78 loc) · 2.22 KB
/
Containerfile
File metadata and controls
97 lines (78 loc) · 2.22 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
# Build stage
FROM debian:latest as builder
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app
# Install build dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
python3 \
python3-pip \
python3-venv \
python3-dev \
curl \
gnupg \
&& 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_current nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update \
&& apt-get install -y nodejs \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Create Python virtual environment
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Install Python dependencies
COPY redaction/requirements.txt ./redaction/
RUN pip install --no-cache-dir -r redaction/requirements.txt && \
python -m spacy download en_core_web_sm
# Install Node.js dependencies
COPY server/package*.json ./server/
RUN cd server && npm install
# Runtime stage
FROM debian:latest
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
PATH="/opt/venv/bin:$PATH"
# Install runtime dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
python3 \
tesseract-ocr \
tesseract-ocr-eng \
libmagic1 \
poppler-utils \
libgl1-mesa-glx \
nodejs \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy from builder
COPY --from=builder /opt/venv /opt/venv
COPY --from=builder /app/server/node_modules /app/server/node_modules
# Set working directory
WORKDIR /app
# Copy application code
COPY . .
# Setup directories and permissions
RUN mkdir -p server/uploads && \
chown -R nobody:nogroup /app && \
chmod -R 755 /app && \
chmod 777 server/uploads
# Switch to non-root user
USER nobody
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s \
CMD curl -f http://localhost:3000/ || exit 1
# Start script
COPY <<EOF /app/start.sh
#!/bin/sh
cd /app/server
exec node index.js
EOF
RUN chmod +x /app/start.sh
# Run the service
CMD ["/app/start.sh"]