FROM debian:buster-slim as git-fetcher

RUN apt update && \
    env DEBIAN_FRONTEND=noninteractive apt install -y git && \
    rm -rf /var/lib/apt/lists/* && \
    mkdir /usr/src/app

COPY .git /usr/src/app/.git
WORKDIR /usr/src/app
RUN git log -1 --pretty="format:{\"commit\": \"%H\", \"commit_short\": \"%h\", \"version\": \"TAIKO_VERSION\"}" > ./version-template.json

FROM python:3.5.9-slim-buster

#RUN sed -i 's/deb.debian.org/mirrors.163.com/g' /etc/apt/sources.list && \
#    sed -i 's/security.debian.org/mirrors.163.com/g' /etc/apt/sources.list 

#dependencies
RUN apt update && \
    env DEBIAN_FRONTEND=noninteractive apt install -y ffmpeg && \
    rm -rf /var/lib/apt/lists/* && \
    mkdir /usr/src/app



# envs
WORKDIR /usr/src/app
COPY ./requirements.txt .
RUN pip install --no-cache -r ./requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

COPY . .
COPY --from=git-fetcher /usr/src/app/version-template.json /usr/src/app/version-template.json


#info
EXPOSE 80
ENV TAIKO_VERSION Nanahira
ENTRYPOINT [ "/usr/src/app/docker/entrypoint.sh" ]
