# Dockerfile for Celery Worker Service FROM python:3.12-slim as builder WORKDIR /build # Install Poetry RUN pip install --no-cache-dir poetry==1.8.0 # Copy dependency files COPY pyproject.toml poetry.lock ./ # Export dependencies RUN poetry config virtualenvs.create false \ && poetry export -f requirements.txt --output requirements.txt --without-hashes # Runtime stage FROM python:3.12-slim LABEL maintainer="automation-team@company.com" LABEL description="Datacenter Documentation Background Worker" # Install system dependencies for network automation RUN apt-get update && apt-get install -y \ gcc \ libpq-dev \ openssh-client \ snmp \ curl \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Copy requirements from builder COPY --from=builder /build/requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy application code and package definition COPY src/ /app/src/ COPY config/ /app/config/ COPY templates/ /app/templates/ COPY pyproject.toml README.md /app/ # Install poetry-core (required for install with pyproject.toml) RUN pip install --no-cache-dir poetry-core # Install the package RUN pip install --no-cache-dir /app # Set PYTHONPATH to ensure module can be imported ENV PYTHONPATH=/app/src:$PYTHONPATH # Create necessary directories RUN mkdir -p /app/logs /app/output # Create non-root user RUN useradd -m -u 1000 appuser && \ chown -R appuser:appuser /app USER appuser # Run the Celery worker with specific queues CMD ["celery", "-A", "datacenter_docs.workers.celery_app", "worker", "--loglevel=info", "--concurrency=4", "-Q", "documentation,auto_remediation,data_collection,maintenance,celery"]