71 lines
1.6 KiB
Docker
71 lines
1.6 KiB
Docker
# Calejo Control Adapter Dockerfile
|
|
# Multi-stage build for optimized production image
|
|
|
|
# Stage 1: Builder stage
|
|
FROM python:3.11-slim as builder
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies for building
|
|
RUN apt-get update && apt-get install -y \
|
|
gcc \
|
|
g++ \
|
|
libpq-dev \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy requirements first for better caching
|
|
COPY requirements.txt .
|
|
|
|
# Install Python dependencies to a temporary directory
|
|
RUN pip install --no-cache-dir --user -r requirements.txt
|
|
|
|
# Stage 2: Runtime stage
|
|
FROM python:3.11-slim
|
|
|
|
# Install runtime dependencies only
|
|
RUN apt-get update && apt-get install -y \
|
|
libpq5 \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& apt-get clean
|
|
|
|
# Create non-root user
|
|
RUN useradd -m -u 1000 calejo
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy Python packages from builder stage
|
|
COPY --from=builder /root/.local /home/calejo/.local
|
|
|
|
# Copy application code (including root-level scripts)
|
|
COPY --chown=calejo:calejo . .
|
|
|
|
# Ensure the user has access to the copied packages
|
|
RUN chown -R calejo:calejo /home/calejo/.local
|
|
|
|
# Switch to non-root user
|
|
USER calejo
|
|
|
|
# Add user's local bin to PATH
|
|
ENV PATH=/home/calejo/.local/bin:$PATH
|
|
|
|
# Expose ports
|
|
# REST API: 8080, OPC UA: 4840, Modbus TCP: 502, Prometheus: 9090
|
|
EXPOSE 8080
|
|
EXPOSE 4840
|
|
EXPOSE 502
|
|
EXPOSE 9090
|
|
|
|
# Health check with curl for REST API
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
|
CMD curl -f http://localhost:8080/health || exit 1
|
|
|
|
# Environment variables for configuration
|
|
ENV PYTHONPATH=/app
|
|
ENV PYTHONUNBUFFERED=1
|
|
|
|
# Run the application
|
|
CMD ["python", "-m", "src.main"] |