Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
73 lines (57 loc) · 1.81 KB
/
Copy pathDockerfile
File metadata and controls
73 lines (57 loc) · 1.81 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
# 🐳 Production Dockerfile for AD Microservice with Kerberos
# Multi-stage build for optimal size and security
# Stage 1: Build stage
FROM python:3.10-slim as builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
libkrb5-dev \
libffi-dev \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Stage 2: Runtime stage
FROM python:3.10-slim
# Install runtime dependencies for Kerberos
RUN apt-get update && apt-get install -y \
krb5-user \
libkrb5-3 \
libgssapi-krb5-2 \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Copy virtual environment from builder stage
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Create non-root user
RUN groupadd -r appuser && useradd -r -g appuser -u 1000 appuser
# Create directories with proper ownership
RUN mkdir -p /app /etc/krb5 /tmp && \
chown -R appuser:appuser /app /tmp && \
chmod 755 /etc/krb5
# Copy application code
COPY --chown=appuser:appuser . /app
WORKDIR /app
# Create necessary directories for the application
RUN mkdir -p /app/logs && \
chown appuser:appuser /app/logs
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Environment variables
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
# Command to run the application
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]