FROM alpine:latest

# https://docs.docker.com/reference/dockerfile/#environment-replacement
# ENV DEBMIRRORURL="https://www.debian.org/mirror/list"

# By default these are scraped
ENV EXTRA_REPOS=True
ENV PROXMOX_REPOS=True
ENV DOCKER_REPOS=True
ENV DEBIAN_REPOS=True
ENV OPNSENSE_REPOS=True

RUN apk update && \
    apk add python3 py3-pip git su-exec curl wget unzip && \
    mkdir -p /etc/debmirror   

WORKDIR /etc/debmirror/

# This will be done in Init script based on what ENV's are configured
# RUN git clone https://tea.shupogaki.org/YuruC3/Repo-IP-lists && \
#     ln -s /etc/debmirror/Repo-IP-lists/MirrorListV4 /etc/debmirror/MirrorListV4 && \
#     ln -s /etc/debmirror/Repo-IP-lists/MirrorListV6 /etc/debmirror/MirrorListV6 && \
#     ln -s /etc/debmirror/Repo-IP-lists/OPNS_MirrorListV4 /etc/debmirror/OPNS_MirrorListV4 && \
#     ln -s /etc/debmirror/Repo-IP-lists/OPNS_MirrorListV6 /etc/debmirror/OPNS_MirrorListV6
# RUN touch /etc/debmirror/MirrorListV6 && \
#     touch /etc/debmirror/MirrorListV4

# Copy code
COPY ./code/main.py /etc/debmirror/
COPY ./code/whatDomain.py /etc/debmirror/


COPY ./entrypoint.sh /
RUN chmod +x /entrypoint.sh

# Copy important files
# COPY ./init.sh /etc/debmirror/

# Install python modules
COPY ./requirements.txt /etc/debmirror/
RUN python3 -m venv venv && \
    venv/bin/python3 -m pip install --upgrade pip && \
    venv/bin/pip3 install -r requirements.txt

# Setup cronjobs
# COPY cron-jobs /etc/crontabs/
# RUN chmod 0644 /etc/crontabs/cron-jobs && \
#     crontab /etc/crontabs/cron-jobs

# Copy and configure git copying script
COPY ./gitPush.sh /etc/debmirror/
RUN chmod +x /etc/debmirror/gitPush.sh

ENTRYPOINT [ "/entrypoint.sh" ]

# Start cron
CMD ["/usr/sbin/crond", "-f"]
