-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
98 lines (82 loc) · 4.79 KB
/
Copy pathDockerfile
File metadata and controls
98 lines (82 loc) · 4.79 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
# =============================================================================
# Gelegram — Docker Image
# =============================================================================
# Multi-stage build:
# Stage 1 (builder) — Install Node.js + Gemini CLI + Python deps
# Stage 2 (runtime) — Slim image with only what's needed at runtime
#
# Usage:
# docker build -t gelegram .
# docker run -d --name gelegram \
# -v gelegram-data:/data \
# -e TELEGRAM_BOT_TOKEN=your-token \
# gelegram
#
# Or use docker-compose.yml (recommended):
# docker compose up -d
#
# First-time Gemini auth:
# docker exec -it gelegram gemini auth
# =============================================================================
# ── Stage 1: Builder ─────────────────────────────────────────────────────────
# Install Node.js, Gemini CLI, and Python dependencies in a throwaway layer
FROM python:3.12-slim AS builder
# Install Node.js 20 (LTS) — needed to install Gemini CLI via npm
RUN apt-get update && \
apt-get install -y --no-install-recommends curl ca-certificates && \
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y --no-install-recommends nodejs && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Install Gemini CLI globally
RUN npm install -g @google/gemini-cli
# Install Python dependencies into a prefix we can copy later
COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir --prefix=/install -r /tmp/requirements.txt
# ── Stage 2: Runtime ─────────────────────────────────────────────────────────
# Slim image with just Python + Node.js runtime + our app
FROM python:3.12-slim
LABEL maintainer="krazyguy"
LABEL org.opencontainers.image.title="Gelegram"
LABEL org.opencontainers.image.description="Personal AI agent — Telegram bot powered by Gemini CLI"
LABEL org.opencontainers.image.source="https://github.com/krazyguy/Gelegram"
LABEL org.opencontainers.image.licenses="MIT"
# Install Node.js runtime (needed for gemini CLI at runtime)
RUN apt-get update && \
apt-get install -y --no-install-recommends curl ca-certificates && \
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y --no-install-recommends nodejs && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Copy Gemini CLI from builder
COPY --from=builder /usr/lib/node_modules /usr/lib/node_modules
RUN ln -sf /usr/lib/node_modules/.bin/gemini /usr/local/bin/gemini
# Copy Python packages from builder
COPY --from=builder /install /usr/local
# ── Application setup ────────────────────────────────────────────────────────
WORKDIR /app
# Copy application source code
COPY bot.py gateway.py scheduler.py workspace_init.py chat.py ./
COPY requirements.txt .env.example ./
# ── Persistent data volume ───────────────────────────────────────────────────
# /data is where the agentic workspace lives (workdir equivalent).
# Mount a Docker volume here to persist memory, skills, transcripts, etc.
# Also stores runtime state: trusted_users.json, bot.pid, logs, etc.
VOLUME /data
# ── Environment defaults ─────────────────────────────────────────────────────
# These can be overridden at runtime via docker run -e or docker-compose.yml
ENV GEMINI_CLI_PATH=gemini \
GEMINI_WORKING_DIR=/data/workdir \
ACP_TIMEOUT=120 \
BOT_PASSWORD="" \
# Ensure Python output is not buffered (important for Docker logging)
PYTHONUNBUFFERED=1 \
# Force UTF-8 everywhere — prevents the cp1252 encoding errors on Windows
PYTHONIOENCODING=utf-8 \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8
# ── Health check ──────────────────────────────────────────────────────────────
# Checks that the gateway process is still running
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD pgrep -f "python.*gateway.py" > /dev/null || exit 1
# ── Entrypoint ────────────────────────────────────────────────────────────────
# Run gateway.py which manages bot.py lifecycle + cron scheduler
CMD ["python", "gateway.py"]