# Dockerfile
ARG         PARENT_IMAGE=086679231553.dkr.ecr.us-east-1.amazonaws.com/docker-parent-images:python311
FROM        $PARENT_IMAGE AS base

ENV         VIRTUAL_ENV=/var/venv
ENV         PATH="$VIRTUAL_ENV/bin:$PATH"

USER        root

RUN         apt-get update && \
            apt-get -y upgrade

# Install poetry
RUN         python -m venv $VIRTUAL_ENV && \
            pip install --no-cache --upgrade pip setuptools && \
            pip install --no-cache poetry

USER        worker

# Switch to the app directory
WORKDIR     /var/app
COPY        pyproject.toml poetry.lock /var/app/

FROM        base AS deploy

USER        root
RUN         apt-get -y install gcc && \
            poetry install --only main --no-root --no-cache && \
            apt-get purge -y gcc && \
            apt-get -y autoremove

USER        worker

COPY        transcoding /var/app/transcoding
COPY        application.py uwsgi.ini /var/app/
COPY        uwsgi-start.sh /

EXPOSE      8080

ENTRYPOINT  ["/uwsgi-start.sh"]

FROM        base AS dev-base

USER        root
RUN         apt-get -y install gcc && \
            poetry install --extras dev --no-root --no-cache && \
            apt-get purge -y gcc && \
            apt-get -y autoremove

USER        worker

COPY        transcoding /var/app/transcoding
COPY        scripts /var/app/scripts
COPY        application.py dev.py docker-compose.yml /var/app/

FROM        dev-base AS unit-lint

WORKDIR     /var/app

COPY        tests /var/app/tests

ENTRYPOINT  [ "scripts/unit-lint.sh" ]

FROM        dev-base AS dev

EXPOSE      5000
ENTRYPOINT  [ "python", "dev.py" ]

FROM        dev-base AS integration

COPY        tests /var/app/tests

ENTRYPOINT  [ "scripts/integration.sh" ]

FROM        base AS update-lockfile

USER        root
COPY        scripts/update-lockfile.sh /var/app/scripts/

ENTRYPOINT  ["scripts/update-lockfile.sh"]

FROM        dev AS format

COPY        tests /var/app/tests
COPY        scripts/format.sh /var/app/scripts/

USER        worker
ENTRYPOINT  ["scripts/format.sh"]
