FROM alpine:3.20 AS base

ARG PROXY_SERVER
ARG PROXY_PORT

RUN apk add --no-cache \
    python3 \
    iptables

ADD https://github.com/semigodking/redsocks/releases/download/release-0.71/redsocks2-x86_64-release-0.71 /bin/redsocks2
RUN chmod +x /bin/redsocks2

COPY redsocks.conf /etc/redsocks.conf
RUN sed -i "s/vPROXY-SERVER/${PROXY_SERVER}/g" /etc/redsocks.conf && \
    sed -i "s/vPROXY-PORT/${PROXY_PORT}/g" /etc/redsocks.conf

RUN mkdir -p /services /var/aniworld
WORKDIR /services

RUN python3 -m venv aniworlddownloader_venv && \
    aniworlddownloader_venv/bin/pip install --no-cache-dir aniworld

WORKDIR /
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["sh", "/entrypoint.sh"]
