# Dockerfile

FROM    086679231553.dkr.ecr.us-east-1.amazonaws.com/docker-parent-images:python310 AS base

WORKDIR /var/app

USER    root

# Update and install common packages
RUN     apt-get update && apt-get -y upgrade \
          && apt-get -y install curl gcc git nginx supervisor tar zip \
          && apt-get -y clean \
          && rm -rf /var/lib/apt/lists/*

COPY    requirements.txt ./

ENV     VIRTUAL_ENV /var/venv
RUN     python3 -m venv ${VIRTUAL_ENV}
ENV     PATH "$VIRTUAL_ENV/bin:$PATH"

RUN     pip install --upgrade pip setuptools
RUN     pip install -r requirements.txt

COPY    uwsgi-server.ini /etc/uwsgi-server.ini
COPY    nginx.conf /etc/nginx/nginx.conf
COPY    supervisord.conf /etc/supervisor/supervisord.conf


########################################
### Build image for integration-test ###
########################################
FROM       base as integration-test

# Install test requirements
COPY       test/owslogger-1.1.1.tar.gz ./
COPY       test/scripts/integration.sh ./test/scripts/integration.sh

USER       worker
ENTRYPOINT ["test/scripts/integration.sh"]


########################################
### Build image for deployment ###
########################################
FROM    base as deploy
ARG     VERSION
ARG     REPOSITORY_URL
ARG     GIT_COMMIT

RUN     apt-get -y update \
          && apt-get -y remove --purge gcc git \
          && apt-get -y clean \
          && rm -rf /var/lib/apt/lists/*

# Configure datadog environment variables
ENV     DD_VERSION=$VERSION
ENV     DD_GIT_REPOSITORY_URL=$REPOSITORY_URL
ENV     DD_GIT_COMMIT_SHA=$GIT_COMMIT

CMD     ["/usr/bin/supervisord", "--configuration=/etc/supervisor/supervisord.conf"]

EXPOSE  80
