Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
107 lines (87 loc) · 3.23 KB
/
Copy pathDockerfile
File metadata and controls
107 lines (87 loc) · 3.23 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# ================================
# Production-ready Dockerfile for Python IMDB Bot
# Optimized for Coolify deployment
# ================================
# ================================
# Builder Stage - Dependencies
# ================================
FROM ghcr.io/astral-sh/uv:bookworm-slim AS builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
curl \
build-essential \
pkg-config \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Set working directory
WORKDIR /app
# Copy dependency files first for better layer caching
COPY pyproject.toml uv.lock ./
# Install dependencies to virtual environment
RUN uv sync --frozen --no-install-project --no-dev
# ================================
# Runtime Stage - Production
# ================================
FROM ghcr.io/astral-sh/uv:bookworm-slim AS runtime
# Build arguments for Coolify customization
ARG BUILD_DATE
ARG VCS_REF
ARG VERSION=0.1.0
# Install minimal runtime system dependencies
RUN apt-get update && apt-get install -y \
# Required for HTTP requests and SSL
ca-certificates \
# Required for timezone handling
tzdata \
# Required for health checks
curl \
# Clean up to reduce image size
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Create non-root user for security
RUN groupadd --gid 1000 botuser && \
useradd --uid 1000 --gid botuser --shell /bin/bash --create-home botuser
# Create necessary directories with proper permissions
RUN mkdir -p /app/logs /app/data && \
chown -R botuser:botuser /app
# Set working directory
WORKDIR /app
# Copy virtual environment from builder stage
COPY --from=builder /app /app
# Copy and set entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Copy application code with proper ownership
COPY --chown=botuser:botuser . .
# Make main.py executable
RUN chmod +x main.py
# Health check optimized for Coolify
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Set Python optimization flags for production
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONOPTIMIZE=1 \
PYTHONPATH=/app \
COOLIFY_URL="" \
COOLIFY_FQDN=""
# Health check port
EXPOSE 8080
# Set entrypoint and default command
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["python", "main.py"]
# ================================
# Labels for Coolify and OCI metadata
# ================================
LABEL org.opencontainers.image.title="Python IMDB Bot" \
org.opencontainers.image.description="Production-ready Discord IMDB bot with reaction-based ratings and health monitoring" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.authors="Ali Fani <alifani1377@gmail.com>" \
org.opencontainers.image.source="https://github.com/alifani1377/python-imdb-bot" \
org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.revision="${VCS_REF}" \
org.opencontainers.image.licenses="MIT" \
# Coolify-specific labels
coolify.service.type="background" \
coolify.service.healthcheck="http://localhost:8080/health" \
coolify.service.restart="unless-stopped"