-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathDockerfile
More file actions
52 lines (40 loc) · 1.44 KB
/
Dockerfile
File metadata and controls
52 lines (40 loc) · 1.44 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
FROM python:3.12-slim
WORKDIR /app
# Install system dependencies including WeasyPrint requirements and gosu for privilege dropping
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libffi-dev \
gir1.2-pango-1.0 \
gir1.2-gdkpixbuf-2.0 \
gosu \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first for better caching
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Create non-root user and set up directories
RUN useradd --create-home --shell /bin/bash may \
&& mkdir -p /app/data/uploads \
&& chown -R may:may /app
# Copy and set up entrypoint
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Build args for version info
ARG GIT_SHA=""
ARG BUILD_DATE=""
# Labels for auto-update tools (Watchtower, etc.)
LABEL com.centurylinklabs.watchtower.enable="true"
# Set environment variables
ENV FLASK_APP=run.py
ENV PYTHONUNBUFFERED=1
ENV GIT_SHA=${GIT_SHA}
ENV BUILD_DATE=${BUILD_DATE}
# Expose port
EXPOSE 5050
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD gosu may python -c "import urllib.request; urllib.request.urlopen('http://localhost:5050/health')" || exit 1
# Use entrypoint to fix permissions then run as 'may' user
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["gunicorn", "--bind", "0.0.0.0:5050", "--workers", "2", "--threads", "4", "run:app"]