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/os/alpine.sh
# installs the apk base set and the musl/openblas extras that don't fit the
# cross-distro defaults).
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.
# `test -x` catches the silent-partial-success case (venv exits 0 but
# bin/python is missing/broken) before downstream RUNs depend on it —
# same guard install_script.sh's setup-python.sh applies for native bootstrap.
RUN python3 -m venv --system-site-packages /opt/.venv && \
    test -x /opt/.venv/bin/python
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
