From 201e3a5134bf73b04e02f78ab143b2ca9d770a3a Mon Sep 17 00:00:00 2001 From: PrimeThai Automation Date: Wed, 30 Sep 2026 12:35:34 +0700 Subject: [PATCH] Add Docker deployment with bundled data --- .dockerignore | 14 ++++++++++++++ Dockerfile | 28 ++++++++++++++++++++++++++++ README.md | 12 ++++++++++++ compose.yaml | 18 ++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d8d5656 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +.git/ +.venv/ +.venv-temp/ +.deps/ +**/__pycache__/ +*.py[cod] +.env +.env.* +!.env.example +tests/ +tmp*/ +data/cache/ +data/portfolio/*.sqlite3-shm +data/portfolio/*.sqlite3-wal diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..25eb2e3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM python:3.12-slim + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 + +WORKDIR /app + +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates \ + && rm -rf /var/lib/apt/lists/* \ + && groupadd --gid 10001 primethai \ + && useradd --uid 10001 --gid primethai --create-home --shell /usr/sbin/nologin primethai + +COPY pyproject.toml README.md ./ +COPY primethai/ ./primethai/ +RUN python -m pip install --no-cache-dir . + +COPY --chown=10001:10001 config/ ./config/ +COPY --chown=10001:10001 data/ ./data/ +COPY --chown=10001:10001 reports/ ./reports/ + +USER 10001:10001 + +EXPOSE 18900 + +ENTRYPOINT ["python", "-m", "primethai", "webui"] +CMD ["--host", "0.0.0.0", "--port", "18900"] diff --git a/README.md b/README.md index d5ccfd8..b14e3ac 100644 --- a/README.md +++ b/README.md @@ -263,3 +263,15 @@ The cumulative daily ZIP is saved automatically as `data/raw/siamchart/set-archi The proposed limit reference is the latest EOD close, not a live quote or a guaranteed fill. Signal entries use that close as an estimate until you edit the ledger with the actual fill. The app does not connect to a broker, transmit orders, or automatically reconcile broker holdings. The backtest page is a research simulation, not a validated live record, and does not model market impact, bid/ask spreads, every corporate action, or broker-specific buying power. Verify current quotes, liquidity, order size and cash with the broker before each order. The default dashboard report is written to `reports/primary_union_current`. You can change the local port, date range, starting cash, report folder, or input archives with `--port`, `--start`, `--initial-equity`, `--report-dir`, and `--archives`. + +### Docker deployment + +The Docker image includes the existing `data/` tree (SiamChart archives, imported daily prices, backtest inputs and the initial portfolio database) and `reports/`. It does not need to download the historical archives again. The app still checks for the latest daily EOD session and refreshes it automatically when needed. + +Create `.env` from `.env.example` and set the login credentials and session secret as described above. Then build and start the app: + +```powershell +docker compose up --build -d +``` + +Compose uses named volumes for `/app/data` and `/app/reports`. On first creation, Docker seeds them from the files included in the image; later restarts and image rebuilds keep the server's updated price archive, portfolio database and reports. Use `docker compose down` to stop the app while keeping its data. The port is bound to localhost so an HTTPS reverse proxy can sit in front of it. diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..bf58829 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,18 @@ +services: + primethai: + build: + context: . + image: primethai:local + init: true + restart: unless-stopped + env_file: + - .env + ports: + - "127.0.0.1:18900:18900" + volumes: + - primethai-data:/app/data + - primethai-reports:/app/reports + +volumes: + primethai-data: + primethai-reports: