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

WORKDIR     /var/venv
ENV         VIRTUAL_ENV /var/venv
RUN         python3.11 -m venv ${VIRTUAL_ENV}
ENV         PATH "$VIRTUAL_ENV/bin:$PATH"
RUN         pip install --no-cache-dir  --upgrade pip setuptools
WORKDIR     /var/app
COPY        requirements.txt ./
USER        root
RUN         apt-get update && apt-get install -y gcc
USER        worker
RUN         pip install --no-cache-dir -r requirements.txt
USER        root
RUN         apt-get -y remove --purge gcc \
                && apt-get -y autoremove \
                && apt-get -y clean \
                && rm -rf /var/lib/apt/lists/*
USER        worker

#######################################
### Build image for live deployment ###
#######################################
FROM        base AS deploy
COPY        --chown=worker:worker uwsgi-start.sh /
COPY        --chown=worker:worker vector_job_rules ./vector_job_rules
COPY        --chown=worker:worker application.py ./
EXPOSE      8080
ENTRYPOINT  ["/uwsgi-start.sh"]

###########################
### Build image for dev ###
###########################
FROM        base AS dev
COPY        requirements-dev.txt ./
RUN         pip install -r /var/app/requirements-dev.txt
COPY        application.py dev.py  ./
COPY        vector_job_rules ./vector_job_rules
COPY        scripts ./scripts
COPY        tests ./tests
COPY        .flake8 docker-compose.yml
ENV         PYTHONUNBUFFERED 1
EXPOSE      5000
ENTRYPOINT  ["/var/venv/bin/python"]
CMD         ["dev.py", "2>&1"]

#################################
### Build image for unit-lint ###
#################################
FROM        dev AS unit-lint
ENTRYPOINT  ["scripts/unit-lint.sh"]

########################################
### Build image for test-integration ###
########################################
FROM        dev AS test-integration
ENTRYPOINT  [ "scripts/test-integration.sh" ]
