FROM 483193324480.dkr.ecr.us-east-1.amazonaws.com/python:3.10-slim-builder as builder

FROM builder as build-venv

WORKDIR /app

COPY requirements/ /app/requirements/

RUN python -m venv /venv \
    && . /venv/bin/activate \
    && pip --no-cache-dir install --upgrade pip setuptools wheel \
    && pip --no-cache-dir wheel --wheel-dir=/tmp/wheelhouse -r requirements/base.txt \
    && pip --no-cache-dir wheel --wheel-dir=/tmp/wheelhouse -r requirements/dev.txt \
    && pip --no-cache-dir wheel --wheel-dir=/tmp/wheelhouse -r requirements/tests.txt

FROM build-venv as build-base

RUN . /venv/bin/activate \
    && pip --no-cache-dir install --trusted-host pypi.python.org --no-index --find-links=/tmp/wheelhouse -r requirements/base.txt

FROM build-base as build-dev

RUN . /venv/bin/activate \
    && pip --no-cache-dir install --trusted-host pypi.python.org --no-index --find-links=/tmp/wheelhouse -r requirements/dev.txt

FROM build-dev as build-test

RUN . /venv/bin/activate \
    && pip --no-cache-dir install --trusted-host pypi.python.org --no-index --find-links=/tmp/wheelhouse -r requirements/tests.txt

FROM 483193324480.dkr.ecr.us-east-1.amazonaws.com/python:3.10-slim-runner as main


COPY --from=build-base /venv /venv

USER ${APP_USER}

COPY . /app

WORKDIR /app

EXPOSE 8000

ENV PATH="/venv/bin/:${PATH}"

CMD ["gunicorn", "-b :8000", "-t 120", "src.run:app"]

FROM build-test as test

COPY . /app

WORKDIR /app/

