# Dockerfile

ARG         AWS_ACCOUNT=086679231553
FROM        ${AWS_ACCOUNT}.dkr.ecr.us-east-1.amazonaws.com/docker-parent-images:python313 AS base

ENV UV_COMPILE_BYTECODE=1 \
    UV_LINK_MODE=copy \
    UV_PYTHON_DOWNLOADS=0 \
    VIRTUAL_ENV="/opt/pysetup/.venv" \
    UV_PROJECT_ENVIRONMENT="/opt/pysetup/.venv" \
    PATH="/opt/pysetup/.venv/bin:$PATH"


USER        root

RUN         mkdir -p /var/app && \
            chown -R worker:worker /var/app

WORKDIR     /var/app
COPY        --from=ghcr.io/astral-sh/uv:0.7.18 /uv /uvx /bin/
COPY        pyproject.toml uv.lock ./
RUN         touch README.md
RUN         uv sync --all-extras

COPY        ./product_staging ./product_staging


# Set ownership of the venv directory to the appuser
RUN         chown -R worker:worker /opt/pysetup/.venv

###########################
### Build image for dev ###
###########################
FROM        base AS dev
USER        root

COPY        dev.py ./
COPY        ./tests ./tests
COPY        ./scripts ./scripts

RUN         uv sync --group dev --all-extras

EXPOSE      5000
USER        worker
CMD         ["uv", "run", "ddtrace-run", "python", "dev.py", "2>&1"]


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


########################################
### Build image for integration-test ###
########################################
FROM        dev AS integration-test

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


##############################
### Build image for deploy ###
##############################
FROM        base AS deploy

# Remove cruft
RUN         rm -rf tests/ scripts/ uv.lock README.md
# Add uvicorn script for fastapi
COPY        uvicorn-start.sh  /

EXPOSE      8080
USER        worker
ENTRYPOINT  ["/uvicorn-start.sh"]
