# syntax=docker/dockerfile:1
# DexVerse downloader — bundles Python + dexverse + s5cmd (doc §19).
# Supports all three backends: s5cmd (default), python (boto3), http (presigned URLs).
#
#   docker build -t dexverse/dexverse-dl:latest .
#   docker run --rm -v /data:/out dexverse/dexverse-dl:latest \
#       download --manifest /manifest.json --out /out --backend http
#
# Or with a task id (manifest fetched from the backend inside the container):
#   docker run --rm -v /data:/out -e DEXVERSE_TOKEN=xxx \
#       dexverse/dexverse-dl:latest download --task dl_xxx --out /out \
#       --server https://dexverse.example.com --backend http

FROM python:3.11-slim AS base

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1

# s5cmd (for the high-throughput s5cmd backend; harmless if you only use http/python)
ARG S5CMD_VERSION=v2.3.0
ADD https://github.com/peak/s5cmd/releases/download/${S5CMD_VERSION}/s5cmd_${S5CMD_VERSION}_Linux-64bit.tar.gz /tmp/s5cmd.tar.gz
RUN tar -xzf /tmp/s5cmd.tar.gz -C /usr/local/bin s5cmd && rm /tmp/s5cmd.tar.gz

# The package version comes from pyproject.toml. Keep exactly one built wheel
# in dist/ so Docker never needs a duplicated, hard-coded version number.
COPY dist/dexverse-*.whl /tmp/wheels/
RUN set -- /tmp/wheels/dexverse-*.whl; \
    if [ "$#" -ne 1 ]; then \
        echo "expected exactly one dexverse wheel in dist/, found $#"; \
        exit 1; \
    fi; \
    pip install --no-cache-dir "${1}[s3]"

WORKDIR /work
ENTRYPOINT ["dexverse-dl"]
CMD ["--help"]
