-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
90 lines (71 loc) · 2.66 KB
/
Copy pathDockerfile
File metadata and controls
90 lines (71 loc) · 2.66 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# =============================================================================
# Pycelize Dockerfile
# =============================================================================
# Multi-stage build for optimized production image
#
# Usage:
# docker build -t pycelize:latest .
# docker run -p 5050:5050 pycelize:latest
# =============================================================================
# -----------------------------------------------------------------------------
# Stage 1: Builder
# -----------------------------------------------------------------------------
FROM python:3.11-slim as builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Set work directory
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
# -----------------------------------------------------------------------------
# Stage 2: Production
# -----------------------------------------------------------------------------
FROM python:3.11-slim as production
# Labels
LABEL maintainer="arisnguyenit97"
LABEL version="0.0.1"
LABEL description="Pycelize - Professional Flask Application for Excel/CSV Processing"
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV FLASK_ENV=production
ENV FLASK_DEBUG=0
ENV APP_HOME=/app
# Create non-root user for security
RUN groupadd --gid 1000 appgroup \
&& useradd --uid 1000 --gid appgroup --shell /bin/bash --create-home appuser
# Set work directory
WORKDIR $APP_HOME
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq5 \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Copy wheels from builder stage
COPY --from=builder /app/wheels /wheels
COPY --from=builder /app/requirements.txt .
# Install Python packages from wheels
RUN pip install --no-cache-dir /wheels/* \
&& rm -rf /wheels
# Copy application code
COPY --chown=appuser:appgroup . .
# Create required directories with proper permissions
RUN mkdir -p uploads outputs logs \
&& chown -R appuser:appgroup uploads outputs logs
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 5050
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:5050/api/v1/health || exit 1
# Run the application
CMD ["python", "run.py"]