FROM alpine:3

WORKDIR /workspace

# Bootstrap bash so install_script.sh (bash shebang) can run; apk and awk are
# already provided by busybox.
RUN apk add --no-cache bash

# Install build/test deps via the per-OSNICK installer (.install/install_script.sh
# dispatches to .install/os/<osnick>.sh). musl extras live in lib/packages.sh + os/alpine.sh.
COPY rust-toolchain.toml /workspace/rust-toolchain.toml
COPY .install /workspace/.install
RUN bash /workspace/.install/install_script.sh

# Install Redis (SANITIZER can be 'address' for ASAN builds)
# Empty default: install_redis.sh falls back to pack/ramp.yml (single source of truth)
ARG REDIS_REF=
ARG SANITIZER=

COPY pack/ramp.yml /workspace/pack/ramp.yml
RUN chmod +x /workspace/.install/install_redis.sh && REDIS_REF=${REDIS_REF} SANITIZER=${SANITIZER} /workspace/.install/install_redis.sh

# Use system Python with venv (like the old flow-alpine workflow)
# uv's managed Python has clang-specific flags that cause build issues
# --system-site-packages: expose apk-installed py3-cryptography / py3-numpy /
# py3-psutil (from os/alpine.sh) inside the venv. Building those C-extension
# packages from source on musl is fragile; the apk pre-builts are the fix.
RUN python3 -m venv --system-site-packages /opt/.venv
ENV VIRTUAL_ENV=/opt/.venv
ENV PATH="/opt/.venv/bin:${PATH}"

COPY requirements_docker.txt /workspace/requirements.txt
RUN pip install --upgrade pip setuptools wheel && \
    pip install -r requirements.txt
