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

FROM builder as build-venv

WORKDIR /app

COPY ./requirements/ ./requirements/

SHELL ["/bin/bash", "-c"]

RUN python -m venv /venv \
    && source /venv/bin/activate \
    && pip --no-cache-dir install --upgrade pip setuptools wheel \
    && pip --no-cache-dir wheel --wheel-dir=/tmp/wheelhouse -r requirements/base-internal.txt \
    && pip --no-cache-dir wheel --wheel-dir=/tmp/wheelhouse -r requirements/dev.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-internal.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-base as main

COPY ./configs/openssl.cnf /etc/ssl/openssl.cnf

USER ${APP_USER}

COPY ./app/. /app/

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

FROM build-dev as dev

COPY ./configs/openssl.cnf /etc/ssl/openssl.cnf

USER ${APP_USER}

COPY ./app/. /app/

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