# Dockerfile

ARG  AWS_ACCOUNT=086679231553
FROM ${AWS_ACCOUNT}.dkr.ecr.us-east-1.amazonaws.com/docker-parent-images:python313 AS base

USER root

# Update and install common packages
RUN apt-get -y update \
    && apt-get -y upgrade \
    && apt-get -y install --no-install-recommends mediainfo ffmpeg locales locales-all \
    && apt-get -y clean \
    && rm -rf /var/lib/apt/lists/*

# Set locale
RUN localedef -c -f UTF-8 -i en_US en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8

WORKDIR /var/app

# Create and configure virtualenv and worker
RUN python3 -m venv /var/app && \
    /var/app/bin/pip install --upgrade pip setuptools && \
    mkdir /var/log/worker && \
    chown -R worker:worker /var/log/worker

FROM base AS deploy

# Install python dependencies
COPY requirements.txt /var/app/
RUN /var/app/bin/pip install -I -r /var/app/requirements.txt

# Add application code
COPY video /var/app/video
COPY conf /var/app/conf
COPY main.py /var/app/

EXPOSE 9001
CMD ["/var/app/bin/supervisord", "-c", "/var/app/conf/supervisord.conf"]

FROM base AS lint-and-test

# Install python dependencies
COPY requirements-dev.txt requirements.txt /var/app/
RUN /var/app/bin/pip install -I -r /var/app/requirements-dev.txt

# Add application and test code
COPY video /var/app/video
COPY conf /var/app/conf
COPY main.py /var/app/
COPY .flake8 lint-and-test.sh /var/app/
COPY tests /var/app/tests
RUN chmod 755 /var/app/lint-and-test.sh

ENTRYPOINT ["bash", "/var/app/lint-and-test.sh"]
