56 lines
1.7 KiB
Docker
56 lines
1.7 KiB
Docker
# Multi-stage Dockerfile for Collector service
|
|
# Stages: base -> development, base -> production
|
|
|
|
# =============================================================================
|
|
# Base stage - common dependencies
|
|
# =============================================================================
|
|
FROM python:3.11-slim as base
|
|
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install Python dependencies
|
|
COPY services/collector/requirements.txt /app/requirements.txt
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Copy shared code and proto
|
|
COPY shared /app/shared
|
|
COPY proto /app/proto
|
|
|
|
# Generate gRPC code from proto
|
|
RUN python -m grpc_tools.protoc \
|
|
-I/app/proto \
|
|
--python_out=/app/shared \
|
|
--grpc_python_out=/app/shared \
|
|
/app/proto/metrics.proto
|
|
|
|
# Copy service code
|
|
COPY services/collector /app/services/collector
|
|
|
|
ENV PYTHONPATH=/app
|
|
ENV PYTHONUNBUFFERED=1
|
|
|
|
# =============================================================================
|
|
# Development stage - with hot reload
|
|
# =============================================================================
|
|
FROM base as development
|
|
|
|
RUN pip install --no-cache-dir watchfiles
|
|
|
|
CMD ["python", "-m", "watchfiles", "python services/collector/main.py", "/app/services/collector"]
|
|
|
|
# =============================================================================
|
|
# Production stage - optimized
|
|
# =============================================================================
|
|
FROM base as production
|
|
|
|
# Run as non-root user
|
|
RUN useradd --create-home --shell /bin/bash appuser
|
|
USER appuser
|
|
|
|
CMD ["python", "services/collector/main.py"]
|