From 8e0ab0ad9ea59e1c2ccd0b5a89e51b4f7eeb4f08 Mon Sep 17 00:00:00 2001 From: bxvtr Date: Sat, 21 Feb 2026 00:22:00 +0000 Subject: [PATCH] Chore: rework devcontainer setup --- .devcontainer/Dockerfile | 3 +++ .devcontainer/dev.Dockerfile | 27 -------------------------- .devcontainer/devcontainer.json | 28 ++++++++++----------------- Dockerfile | 30 ++++++++++++++++++++--------- argo/workflowtemplate-backtest.yaml | 2 +- docker-compose.override.yaml | 5 ----- docker-compose.yaml | 15 --------------- scripts/post-create.sh | 8 +------- trading_runtime/local/local.json | 10 +++++----- 9 files changed, 41 insertions(+), 87 deletions(-) create mode 100644 .devcontainer/Dockerfile delete mode 100644 .devcontainer/dev.Dockerfile delete mode 100644 docker-compose.override.yaml delete mode 100644 docker-compose.yaml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..0e313f1 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,3 @@ +FROM mcr.microsoft.com/devcontainers/python:3.11 + +RUN pip install --upgrade pip setuptools wheel \ No newline at end of file diff --git a/.devcontainer/dev.Dockerfile b/.devcontainer/dev.Dockerfile deleted file mode 100644 index c24e6f8..0000000 --- a/.devcontainer/dev.Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -# syntax=docker/dockerfile:1.4 - -FROM python:3.11.14-slim-trixie - -# Environment configuration -ENV PYTHONUNBUFFERED=1 \ - VIRTUAL_ENV=/opt/venv \ - PATH="/opt/venv/bin:$PATH" - -# Install system dependencies -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - build-essential \ - curl \ - git \ - ca-certificates && \ - rm -rf /var/lib/apt/lists/* - -# Create and activate virtual environment -RUN python -m venv "$VIRTUAL_ENV" && \ - pip install --upgrade pip - -# Set working directory for trading-runtime -WORKDIR /workspace/trading-runtime - -# Default command for the devcontainer (keeps container alive) -CMD ["sleep", "infinity"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9365885..bf21090 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,26 +1,18 @@ { - "name": "trading-runtime devcontainer", - "dockerComposeFile": [ - "../docker-compose.yaml", - "../docker-compose.override.yaml" - ], - "service": "app", - "workspaceFolder": "/workspace/trading-runtime", - "remoteUser": "root", + "name": "Trading Runtime Dev", + "build": { + "dockerfile": "Dockerfile", + "context": ".." + }, + + "postCreateCommand": "./scripts/post-create.sh", + "customizations": { "vscode": { - "settings": { - "python.defaultInterpreterPath": "/opt/venv/bin/python", - "python.testing.pytestEnabled": true, - "python.testing.pytestArgs": [ - "tests" - ] - }, "extensions": [ "ms-python.python", "ms-python.debugpy" ] } - }, - "postCreateCommand": "/bin/bash scripts/post-create.sh" -} + } +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 5353442..813b348 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,12 +11,13 @@ FROM python:3.11.14-slim-trixie AS build ARG TRADING_RUNTIME_COMMIT -ENV TRADING_RUNTIME_COMMIT=$TRADING_RUNTIME_COMMIT -ENV PATH="/install/bin:$PATH" +ENV TRADING_RUNTIME_COMMIT=${TRADING_RUNTIME_COMMIT} +ENV PATH="/install/bin:${PATH}" ENV PYTHONPATH="/install/lib/python3.11/site-packages" -WORKDIR /workspace/trading-runtime +WORKDIR /workspaces/trading-runtime +# System dependencies for building Python packages & running tests RUN apt-get update && \ apt-get install -y --no-install-recommends \ git \ @@ -24,6 +25,7 @@ RUN apt-get update && \ build-essential && \ rm -rf /var/lib/apt/lists/* +# Install Python dependencies first (maximizes Docker cache) COPY requirements.txt . COPY requirements-dev.txt . @@ -31,13 +33,16 @@ RUN pip install --upgrade pip && \ pip install --prefix=/install -r requirements.txt && \ pip install --prefix=/install -r requirements-dev.txt +# Copy project files COPY pyproject.toml . COPY scripts/check.sh . COPY trading_runtime/ trading_runtime/ COPY tests/ tests/ +# Install the package itself RUN pip install --prefix=/install . +# Run test & quality checks RUN chmod +x check.sh && ./check.sh @@ -50,18 +55,25 @@ ARG GIT_COMMIT ARG GIT_BRANCH ARG GIT_DIRTY -ENV GIT_COMMIT=$GIT_COMMIT \ - GIT_BRANCH=$GIT_BRANCH \ - GIT_DIRTY=$GIT_DIRTY \ +ENV GIT_COMMIT=${GIT_COMMIT} \ + GIT_BRANCH=${GIT_BRANCH} \ + GIT_DIRTY=${GIT_DIRTY} \ PYTHONUNBUFFERED=1 +# Minimal runtime dependencies RUN apt-get update && \ - apt-get install -y --no-install-recommends ca-certificates && \ + apt-get install -y --no-install-recommends \ + ca-certificates && \ rm -rf /var/lib/apt/lists/* +# Create non-root user for production runtime +RUN adduser --disabled-password --gecos '' appuser + +# Copy only installed Python artifacts from build stage COPY --from=build /install /usr/local +# Application directory (mostly symbolic now — no source code needed) WORKDIR /app -COPY trading_runtime/ trading_runtime/ -COPY pyproject.toml . +# Drop privileges +USER appuser diff --git a/argo/workflowtemplate-backtest.yaml b/argo/workflowtemplate-backtest.yaml index 05b6a48..8eaadc3 100644 --- a/argo/workflowtemplate-backtest.yaml +++ b/argo/workflowtemplate-backtest.yaml @@ -20,7 +20,7 @@ spec: - name: experiment-config description: "Path to experiment JSON inside the container" - value: /workspace/trading-runtime/strategies/ + value: /workspaces/trading-runtime/strategies/ - name: scratch-root description: "Scratch root inside the container" diff --git a/docker-compose.override.yaml b/docker-compose.override.yaml deleted file mode 100644 index 62fdcb8..0000000 --- a/docker-compose.override.yaml +++ /dev/null @@ -1,5 +0,0 @@ -services: - app: - volumes: - # SELinux-specific volume mount - - .:/workspace/trading-runtime:Z diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index 3baa2b6..0000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,15 +0,0 @@ -version: "3.8" - -services: - app: - build: - context: . - dockerfile: .devcontainer/dev.Dockerfile - - # Mount both repositories into the container - volumes: - # trading-runtime (this repo) into /workspace/trading-runtime - - .:/workspace/trading-runtime - - # Keep the container running for the devcontainer - command: sleep infinity diff --git a/scripts/post-create.sh b/scripts/post-create.sh index ed42772..2da56f0 100755 --- a/scripts/post-create.sh +++ b/scripts/post-create.sh @@ -1,12 +1,6 @@ #!/usr/bin/env bash set -euo pipefail -echo "[post-create] Using venv at /opt/venv" -# shellcheck disable=SC1091 -source /opt/venv/bin/activate - -cd /workspace/trading-runtime - echo "[post-create] Installing dev requirements..." python -m pip install -r requirements-dev.txt @@ -14,7 +8,7 @@ python -m pip install -r requirements-dev.txt # If this repo is a Python package, install it in editable mode if [ -f pyproject.toml ] || [ -f setup.py ] || [ -f setup.cfg ]; then echo "[post-create] Installing trading-runtime in editable mode..." - python -m pip install -e . + python -m pip install -e .[dev] fi echo "[post-create] Running import-linter..." diff --git a/trading_runtime/local/local.json b/trading_runtime/local/local.json index c8ab91e..b596453 100644 --- a/trading_runtime/local/local.json +++ b/trading_runtime/local/local.json @@ -5,9 +5,9 @@ "engine": { "initial_snapshot": null, "data_files": [ - "/workspace/trading-runtime/tests/data/parts/part-000.npz", - "/workspace/trading-runtime/tests/data/parts/part-001.npz", - "/workspace/trading-runtime/tests/data/parts/part-002.npz" + "/workspaces/trading-runtime/tests/data/parts/part-000.npz", + "/workspaces/trading-runtime/tests/data/parts/part-001.npz", + "/workspaces/trading-runtime/tests/data/parts/part-002.npz" ], "instrument": "BTC_USDC-PERPETUAL", @@ -32,8 +32,8 @@ "roi_lb": 40000, "roi_ub": 80000, - "stats_npz_path": "/workspace/trading-runtime/tests/data/results/stats.npz", - "event_bus_path": "/workspace/trading-runtime/tests/data/results/events.json" + "stats_npz_path": "/workspaces/trading-runtime/tests/data/results/stats.npz", + "event_bus_path": "/workspaces/trading-runtime/tests/data/results/events.json" }, "risk": {