|
| 1 | +# syntax=docker/dockerfile:1.6 |
| 2 | +# |
| 3 | +# 0pnMatrx gateway image. |
| 4 | +# |
| 5 | +# Multi-stage build: |
| 6 | +# 1. ``builder`` installs Python dependencies into a virtualenv. Build |
| 7 | +# tools (gcc, etc.) live only in this stage so they don't bloat the |
| 8 | +# runtime image. |
| 9 | +# 2. ``runtime`` copies the prebuilt venv plus application code, runs |
| 10 | +# as a non-root user, and exposes the gateway HTTP port. |
| 11 | + |
| 12 | +# ── Stage 1: builder ────────────────────────────────────────────────────────── |
| 13 | +FROM python:3.11-slim AS builder |
| 14 | + |
| 15 | +ENV PYTHONDONTWRITEBYTECODE=1 \ |
| 16 | + PYTHONUNBUFFERED=1 \ |
| 17 | + PIP_NO_CACHE_DIR=1 \ |
| 18 | + PIP_DISABLE_PIP_VERSION_CHECK=1 |
| 19 | + |
| 20 | +# Build deps for native wheels (eth-hash, pynacl, etc.). |
| 21 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 22 | + build-essential \ |
| 23 | + gcc \ |
| 24 | + libssl-dev \ |
| 25 | + libffi-dev \ |
| 26 | + pkg-config \ |
| 27 | + && rm -rf /var/lib/apt/lists/* |
| 28 | + |
| 29 | +WORKDIR /build |
| 30 | +COPY requirements.txt ./ |
| 31 | +RUN python -m venv /opt/venv \ |
| 32 | + && /opt/venv/bin/pip install --upgrade pip setuptools wheel \ |
| 33 | + && /opt/venv/bin/pip install -r requirements.txt |
| 34 | + |
| 35 | +# ── Stage 2: runtime ────────────────────────────────────────────────────────── |
| 36 | +FROM python:3.11-slim AS runtime |
| 37 | + |
| 38 | +ENV PYTHONDONTWRITEBYTECODE=1 \ |
| 39 | + PYTHONUNBUFFERED=1 \ |
| 40 | + PATH="/opt/venv/bin:$PATH" \ |
| 41 | + OPNMATRX_HOME=/app |
| 42 | + |
| 43 | +# Minimal runtime libs (sqlite3 is part of stdlib but the C library is needed |
| 44 | +# at runtime; tini gives us a proper PID 1 for clean shutdown signals). |
| 45 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 46 | + libssl3 \ |
| 47 | + libffi8 \ |
| 48 | + libsqlite3-0 \ |
| 49 | + tini \ |
| 50 | + && rm -rf /var/lib/apt/lists/* |
| 51 | + |
| 52 | +# Non-root user |
| 53 | +RUN groupadd --system --gid 1000 opnmatrx \ |
| 54 | + && useradd --system --uid 1000 --gid opnmatrx --home /app --shell /sbin/nologin opnmatrx |
| 55 | + |
| 56 | +COPY --from=builder /opt/venv /opt/venv |
| 57 | + |
| 58 | +WORKDIR /app |
| 59 | +COPY --chown=opnmatrx:opnmatrx . /app |
| 60 | + |
| 61 | +# Persistent state lives under /app/data — mount this as a volume. |
| 62 | +RUN mkdir -p /app/data /app/data/backups \ |
| 63 | + && chown -R opnmatrx:opnmatrx /app/data |
| 64 | + |
| 65 | +USER opnmatrx |
| 66 | +EXPOSE 18790 |
| 67 | + |
| 68 | +HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ |
| 69 | + CMD python -c "import urllib.request,sys; \ |
| 70 | +sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:18790/health', timeout=3).status==200 else 1)" \ |
| 71 | + || exit 1 |
| 72 | + |
| 73 | +ENTRYPOINT ["/usr/bin/tini", "--"] |
| 74 | +CMD ["python", "-m", "gateway.server"] |
0 commit comments