-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (40 loc) · 1.36 KB
/
Dockerfile
File metadata and controls
56 lines (40 loc) · 1.36 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
# Use mirror.gcr.io to avoid Docker Hub date issues
FROM mirror.gcr.io/library/python:3.10-slim AS builder
# Install system dependencies for Python packages (e.g., sentence-transformers)
RUN apt-get update && apt-get install -y \
gcc g++ make \
libblas-dev liblapack-dev \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /polysensor
# Copy requirements first for better caching
COPY requirements.txt .
# Install Python dependencies in virtual environment
RUN python -m venv /opt/venv && \
/opt/venv/bin/pip install --upgrade pip && \
/opt/venv/bin/pip install --no-cache-dir -r requirements.txt
# Runtime stage
FROM mirror.gcr.io/library/python:3.10-slim
# Install curl for health check
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN useradd -r appuser
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
# Set PATH
ENV PATH="/opt/venv/bin:$PATH"
# Set working directory
WORKDIR /polysensor
# Copy application code
COPY . .
# Change ownership to non-root user
RUN chown -R appuser:appuser /polysensor
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 5000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:5000/health || exit 1
# Run application
CMD ["python", "main.py"]