FROM 483193324480.dkr.ecr.us-east-1.amazonaws.com/python:3.8-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.8-slim-runner as main

ARG VERSION
ARG REVISION
ARG BUILDTIME

LABEL com.datadoghq.tags.service=apollo-admin-panel
LABEL com.datadoghq.tags.version=${VERSION}
LABEL REVISION=${REVISION}
LABEL BUILDTIME=${BUILDTIME}

ENV DD_SERVICE=apollo-admin-panel
ENV DD_VERSION=${VERSION}
ENV SENTRY_PROJECT=apollo-admin-panel

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

USER ${APP_USER}

COPY . /app

WORKDIR /app

EXPOSE 8000

CMD ["/venv/bin/ddtrace-run", "/venv/bin/uwsgi", "--ini", "uwsgi.ini"]

FROM build-test as test

COPY . /app

WORKDIR /app
