FROM 483193324480.dkr.ecr.us-east-1.amazonaws.com/python:3.8-alpine3.13-builder as build-deps

FROM build-deps as build-venv

WORKDIR /app

COPY requirements/ /app/requirements/

RUN python -m venv /venv \
    && source /venv/bin/activate \
    && pip --no-cache-dir install --upgrade pip setuptools wheel

FROM build-venv as build-base

RUN source /venv/bin/activate \
    && pip --no-cache-dir install --trusted-host pypi.python.org -r requirements/base.txt

FROM 483193324480.dkr.ecr.us-east-1.amazonaws.com/python:3.8-alpine3.13-runner as main

ARG VERSION
ARG REVISION
ARG BUILDTIME

LABEL com.datadoghq.tags.service=dsp-api
LABEL com.datadoghq.tags.version=${VERSION}
LABEL REVISION=${REVISION}
LABEL BUILDTIME=${BUILDTIME}

ENV DD_SERVICE=apollo-dsp-api
ENV DD_VERSION=${VERSION}
ENV SENTRY_PROJECT=dsp-api

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

USER ${APP_USER}

COPY . /app

WORKDIR /app

# Make port 8000 available to the world outside this container
EXPOSE 8000

# Run application with gunicorn when the container launches
CMD ["/venv/bin/gunicorn", "server.app:main", "-c", "gunicorn_config.py"]

FROM build-base as build-dev

RUN source /venv/bin/activate \
    && pip --no-cache-dir install --trusted-host pypi.python.org -r requirements/dev.txt

FROM build-dev as build-test

RUN source /venv/bin/activate \
    && pip --no-cache-dir install --trusted-host pypi.python.org -r requirements/tests.txt

COPY . /app

WORKDIR /app
