Docker Deployment
Deploying Epochly in containerized environments.
Basic Dockerfile
FROM python:3.12-slimWORKDIR /app# Install EpochlyRUN pip install --no-cache-dir epochly# Copy applicationCOPY . .# Configure EpochlyENV EPOCHLY_LEVEL=2ENV EPOCHLY_MODE=balancedENV EPOCHLY_AUTO_ENABLE=1CMD ["python", "app.py"]
Transparent Activation with sitecustomize
FROM python:3.12-slimWORKDIR /appRUN pip install --no-cache-dir epochly# Install sitecustomize for transparent activationRUN epochly sitecustomize install# Verify installationRUN epochly sitecustomize validateCOPY . .ENV EPOCHLY_LEVEL=2ENV EPOCHLY_MODE=conservativeENV EPOCHLY_MAX_WORKERS=4CMD ["python", "app.py"]
Environment Variable Configuration
Key environment variables for Docker deployments:
# Core configurationENV EPOCHLY_LEVEL=2ENV EPOCHLY_MODE=conservativeENV EPOCHLY_MAX_WORKERS=4# LoggingENV EPOCHLY_LOG_LEVEL=WARNINGENV EPOCHLY_LOG_FILE=/var/log/epochly.log# MonitoringENV EPOCHLY_PROMETHEUS_PORT=9090# Emergency controlsENV EPOCHLY_EMERGENCY_DISABLE=0
GPU Support (Level 4)
FROM nvidia/cuda:12.0-runtime-ubuntu22.04RUN apt-get update && apt-get install -y python3.12 python3-pipRUN pip install epochly cupy-cuda12xWORKDIR /appCOPY . .ENV EPOCHLY_LEVEL=4ENV EPOCHLY_LICENSE_KEY=your-pro-license-keyENV EPOCHLY_MODE=aggressiveCMD ["python3", "app.py"]
Running with GPU
# Run with GPU accessdocker run --gpus all -e EPOCHLY_LEVEL=4 myapp# Run with specific GPUsdocker run --gpus device=0,1 myapp# Check GPU availabilitydocker run --gpus all myapp python -c "import epochly; print(epochly.get_status())"
Multi-Stage Build
# Build stageFROM python:3.12-slim AS builderWORKDIR /buildCOPY requirements.txt .RUN pip install --user --no-cache-dir -r requirements.txt epochly# Runtime stageFROM python:3.12-slimWORKDIR /appCOPY --from=builder /root/.local /root/.localCOPY . .ENV PATH=/root/.local/bin:$PATHENV EPOCHLY_LEVEL=2ENV EPOCHLY_AUTO_ENABLE=1CMD ["python", "app.py"]
Resource Considerations
CPU and Memory Limits
# Run with resource limitsdocker run --cpus="4" --memory="4g" myapp# Match workers to available CPUsdocker run --cpus="2" -e EPOCHLY_MAX_WORKERS=2 myapp
Recommended Resources by Level
| Level | CPUs | Memory | Example Command |
|---|---|---|---|
| 1 | 2 | 2GB | docker run --cpus="2" --memory="2g" |
| 2 | 2-4 | 2-4GB | docker run --cpus="4" --memory="4g" |
| 3 | 4-8 | 4-8GB | docker run --cpus="8" --memory="8g" |
| 4 | 8+ | 8GB+ | docker run --gpus all --memory="16g" |
Docker Compose
version: '3.8'services:app:build: .environment:- EPOCHLY_LEVEL=2- EPOCHLY_MODE=conservative- EPOCHLY_MAX_WORKERS=4- EPOCHLY_LOG_LEVEL=WARNINGdeploy:resources:limits:cpus: '4'memory: 4Greservations:cpus: '2'memory: 2Gvolumes:- ./logs:/var/logports:- "9090:9090" # Prometheus metrics
Health Check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 CMD python -c "import epochly; assert epochly.get_status()['initialized']" || exit 1
Custom Health Endpoint
# Install curl for HTTP health checksRUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*HEALTHCHECK --interval=30s --timeout=5s CMD curl -f http://localhost:8080/health/epochly || exit 1
Logging Configuration
FROM python:3.12-slimWORKDIR /app# Create log directoryRUN mkdir -p /var/log/epochlyRUN pip install --no-cache-dir epochlyCOPY . .# Configure loggingENV EPOCHLY_LOG_LEVEL=WARNINGENV EPOCHLY_LOG_FILE=/var/log/epochly/app.logENV EPOCHLY_LOG_FORMAT=json# Ensure logs are visible in docker logsRUN ln -sf /dev/stdout /var/log/epochly/app.logCMD ["python", "app.py"]
Viewing Logs
# View container logsdocker logs -f myapp# View Epochly-specific logsdocker exec myapp tail -f /var/log/epochly.log# Copy logs from containerdocker cp myapp:/var/log/epochly.log ./epochly.log
Graceful Shutdown Handling
FROM python:3.12-slimWORKDIR /appRUN pip install --no-cache-dir epochlyCOPY . .ENV EPOCHLY_LEVEL=2ENV EPOCHLY_DOCKER_FAST_SHUTDOWN=1# Use SIGTERM for graceful shutdownSTOPSIGNAL SIGTERMCMD ["python", "app.py"]
Application Code
import signalimport epochlydef shutdown_handler(signum, frame):print("Shutting down Epochly...")epochly.shutdown()exit(0)signal.signal(signal.SIGTERM, shutdown_handler)signal.signal(signal.SIGINT, shutdown_handler)# Your application code
Debugging Tips
Enable Debug Logging
docker run -e EPOCHLY_LOG_LEVEL=DEBUG myapp
Interactive Debugging
# Run container interactivelydocker run -it myapp /bin/bash# Inside containerepochly doctorpython -c "import epochly; print(epochly.get_status())"
Check Epochly Status
# From outside containerdocker exec myapp python -c "import epochly; print(epochly.get_status())"# View metricsdocker exec myapp curl localhost:9090/metrics | grep epochly
CI/CD Integration
GitHub Actions
name: Build and Test with Epochlyon: [push]jobs:docker:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v2- name: Build Docker imagerun: docker build -t myapp .- name: Test with Epochlyrun: |docker run -e EPOCHLY_LEVEL=2 myapp python -m pytest- name: Verify Epochly healthrun: |docker run myapp python -c "import epochly; assert epochly.get_status()['initialized']"
GitLab CI
docker-build:stage: buildimage: docker:latestservices:- docker:dindscript:- docker build -t myapp .- docker run -e EPOCHLY_LEVEL=2 myapp python -m pytest- docker run myapp epochly doctor
Production Dockerfile Example
# Multi-stage build for productionFROM python:3.12-slim AS builderWORKDIR /buildCOPY requirements.txt .RUN pip install --user --no-cache-dir -r requirements.txt epochly# Runtime stageFROM python:3.12-slim# Create non-root userRUN useradd -m -u 1000 appuserWORKDIR /app# Copy dependencies from builderCOPY --from=builder /root/.local /home/appuser/.localCOPY --chown=appuser:appuser . .# Install sitecustomizeRUN pip install --no-cache-dir epochly && epochly sitecustomize install && epochly sitecustomize validate# Configure EpochlyENV PATH=/home/appuser/.local/bin:$PATHENV EPOCHLY_LEVEL=2ENV EPOCHLY_MODE=conservativeENV EPOCHLY_MAX_WORKERS=4ENV EPOCHLY_LOG_LEVEL=WARNINGENV EPOCHLY_LOG_FILE=/var/log/epochly.logENV EPOCHLY_DOCKER_FAST_SHUTDOWN=1# Health checkHEALTHCHECK --interval=30s --timeout=10s --start-period=60s CMD python -c "import epochly; assert epochly.get_status()['initialized']" || exit 1USER appuserSTOPSIGNAL SIGTERMCMD ["python", "app.py"]