-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
93 lines (74 loc) · 2.75 KB
/
Copy pathDockerfile
File metadata and controls
93 lines (74 loc) · 2.75 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
# --- Builder Stage ---
FROM python:3.12-slim-bookworm AS builder
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
WORKDIR /app
# Configure uv to install to system location
ENV UV_PROJECT_ENVIRONMENT="/usr/local"
ENV UV_COMPILE_BYTECODE=1
# Step 1: Copy only dependency files (cached layer)
COPY pyproject.toml uv.lock ./
COPY bot/pyproject.toml ./bot/
COPY shared/pyproject.toml ./shared/
COPY webapp/pyproject.toml ./webapp/
# Create minimal package structure for uv workspace resolution
RUN mkdir -p bot/other shared/src/shared webapp && \
touch bot/__init__.py bot/other/__init__.py && \
touch shared/src/shared/__init__.py && \
touch webapp/__init__.py
# Step 2: Install dependencies (cached unless pyproject.toml/uv.lock change)
RUN uv sync --frozen --no-dev --package mmwb-bot
# Step 3: Copy actual source code (invalidates only on code changes)
COPY bot ./bot
COPY shared ./shared
COPY webapp ./webapp
# --- Final Stage ---
FROM python:3.12-slim-bookworm
ARG JUST_VERSION=1.40.0
# Set environment variables
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# Install system dependencies
# libgl1 and libglib2.0-0 are for opencv
# libzbar0 is for pyzbar
# libfbclient2 is for firebird
# fonts-dejavu-core is for PIL ImageFont
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
git \
libgl1 \
libglib2.0-0 \
libzbar0 \
libfbclient2 \
fonts-dejavu-core \
&& rm -rf /var/lib/apt/lists/*
# Install just CLI for in-container operational runbooks
RUN set -eux; \
arch="$(dpkg --print-architecture)"; \
case "$arch" in \
amd64) just_arch="x86_64-unknown-linux-musl" ;; \
arm64) just_arch="aarch64-unknown-linux-musl" ;; \
*) echo "Unsupported architecture: $arch"; exit 1 ;; \
esac; \
curl -fsSL -o /tmp/just.tar.gz "https://github.com/casey/just/releases/download/${JUST_VERSION}/just-${JUST_VERSION}-${just_arch}.tar.gz"; \
tar -xzf /tmp/just.tar.gz -C /tmp just; \
install -m 0755 /tmp/just /usr/local/bin/just; \
rm -f /tmp/just /tmp/just.tar.gz
# Copy installed python packages from builder
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Copy only runtime application code
COPY bot ./bot
COPY shared ./shared
COPY justfile ./justfile
# Create directories for volumes
RUN mkdir -p logs data db && ln -sf /app/justfile /app/bot/justfile
# Set working directory to bot
WORKDIR /app/bot
# Git commit (at the end to not break cache)
ARG GIT_COMMIT=unknown
ENV GIT_COMMIT=${GIT_COMMIT}
LABEL org.opencontainers.image.revision="${GIT_COMMIT}"
# Run the application directly with python
CMD ["python", "start.py"]