FROM python:3.13-alpine AS builder

# install rust environment (for rant)
ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo PATH=/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin RUST_VERSION=1.90.0
RUN --mount=type=cache,target=/var/cache/apk apk add --update-cache rustup gcc musl-dev
RUN rustup-init -y --profile minimal

# install rant
RUN --mount=type=cache,target=/root/.cargo \
    --mount=type=cache,target=/usr/local/cargo/git/db \
    --mount=type=cache,target=/usr/local/cargo/registry \
    cargo install --color=never rant --version 4.0.0-alpha.33 --root /opt/rant --features cli

FROM python:3.13-alpine AS app
ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo PATH=/opt/rant/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin RUST_VERSION=1.90.0
COPY --from=builder /opt/rant /opt/rant

# installing app
COPY app/requirements.txt /app/requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip pip install -r /app/requirements.txt
COPY app /app
WORKDIR /app

# wordlist
RUN mkdir -p /lib/wordlist
COPY ext/imsky/wordlists /lib/wordlist
COPY render-wordlists.py /lib/wordlist/render.py
RUN mkdir -p /app/rant
RUN python /lib/wordlist/render.py -o rant /app/rant/wordlist.rant

CMD [ "python", "index.wsgi" ]
EXPOSE 80

FROM app AS dev
#COPY static /app/static
COPY build/basepak /app/basepak
COPY build/dist/seagull.pak /app/seagull.pak