-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
71 lines (56 loc) · 1.86 KB
/
Dockerfile
File metadata and controls
71 lines (56 loc) · 1.86 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
# Build stage
FROM python:3.14-slim as builder
WORKDIR /app
# Install build dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
default-libmysqlclient-dev \
libpq-dev \
pkg-config \
gcc \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Runtime stage
FROM python:3.14-slim
WORKDIR /app
# Install runtime dependencies only
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
gosu \
default-mysql-client \
libpq5 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create application user and group at build time for security hardening
# This supports read-only filesystems and user: directives
RUN groupadd -r -g 1000 appgroup \
&& useradd -r -u 1000 -g appgroup -m -s /bin/bash appuser \
&& mkdir -p /app/instance \
&& chown -R appuser:appgroup /app
# Copy installed packages from builder stage
COPY --from=builder /usr/local/lib/python3.13/site-packages /usr/local/lib/python3.13/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application files and set ownership
COPY --chown=appuser:appgroup . .
# Make entrypoint executable
RUN chmod +x /app/docker-entrypoint.sh
# Create writable directories for read-only filesystem compatibility
RUN mkdir -p /tmp/app-runtime /var/tmp/app /app/instance \
&& chown -R appuser:appgroup /tmp/app-runtime /var/tmp/app /app/instance \
&& chmod 755 /tmp/app-runtime /var/tmp/app \
&& chmod 775 /app/instance
ENV FLASK_APP=run.py \
USER=appuser \
GROUP=appgroup \
UID=1000 \
GID=1000
# Health check configuration
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:5000/health || exit 1
EXPOSE 5000
ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["gunicorn", "-c", "gunicorn.conf.py", "run:app"]