Skip to content

Commit 4e6cd58

Browse files
JacobCoffeeclaude
andauthored
feat: Phase 1.2 - Extract Bot Service from Monolith (#111)
Co-authored-by: Claude <[email protected]>
1 parent d93e861 commit 4e6cd58

File tree

6 files changed

+455
-121
lines changed

6 files changed

+455
-121
lines changed

.prek-config.yaml

Lines changed: 0 additions & 102 deletions
This file was deleted.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ install-backend: ## Install the backend dependencies
5858
@echo "=> Backend dependencies installed"
5959

6060
.PHONY: install
61-
install: clean destroy ## Install the project, dependencies, and pre-commit for local development
61+
install: clean destroy ## Install the project, dependencies, and prek for local development
6262
@if ! $(UV) --version > /dev/null; then $(MAKE) install-uv; fi
6363
@$(MAKE) install-backend
6464
@$(MAKE) install-frontend

services/bot/Dockerfile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# ============================================================================
4+
# Builder Stage: Install dependencies and build virtual environment
5+
# ============================================================================
6+
FROM python:3.12-slim AS builder
7+
8+
# Set working directory
9+
WORKDIR /app
10+
11+
# Install system dependencies required for building Python packages
12+
RUN apt-get update && apt-get install -y \
13+
gcc \
14+
g++ \
15+
make \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
# Copy uv binary from official image
19+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
20+
21+
# Set uv environment variables for optimal performance
22+
ENV UV_SYSTEM_PYTHON=1 \
23+
UV_COMPILE_BYTECODE=1 \
24+
UV_LINK_MODE=copy
25+
26+
# Copy workspace configuration files
27+
COPY pyproject.toml uv.lock ./
28+
29+
# Copy shared packages and service code
30+
COPY packages/byte-common ./packages/byte-common
31+
COPY services/bot ./services/bot
32+
33+
# Install dependencies with frozen lockfile (no dev dependencies)
34+
# This creates a .venv directory with all dependencies
35+
RUN uv sync --frozen --no-dev --no-editable
36+
37+
# ============================================================================
38+
# Runtime Stage: Minimal production image
39+
# ============================================================================
40+
FROM python:3.12-slim
41+
42+
# Set working directory
43+
WORKDIR /app
44+
45+
# Create non-root user for security
46+
RUN groupadd -r botuser && \
47+
useradd -r -g botuser -u 1000 -d /app -s /sbin/nologin botuser
48+
49+
# Copy virtual environment from builder stage
50+
COPY --from=builder --chown=botuser:botuser /app/.venv /app/.venv
51+
52+
# Copy application code from builder stage
53+
COPY --from=builder --chown=botuser:botuser /app/services/bot /app/services/bot
54+
COPY --from=builder --chown=botuser:botuser /app/packages/byte-common /app/packages/byte-common
55+
56+
# Copy workspace configuration (needed for uv run commands)
57+
COPY --from=builder --chown=botuser:botuser /app/pyproject.toml /app/uv.lock ./
58+
59+
# Set PATH to use virtual environment binaries
60+
ENV PATH="/app/.venv/bin:$PATH" \
61+
PYTHONUNBUFFERED=1 \
62+
PYTHONDONTWRITEBYTECODE=1 \
63+
PYTHONPATH="/app"
64+
65+
# Switch to non-root user
66+
USER botuser
67+
68+
# Run the Discord bot
69+
CMD ["python", "-m", "byte_bot"]

0 commit comments

Comments
 (0)