# Dockerfile

ARG         AWS_ACCOUNT=086679231553
ARG         UV_VERSION=0.8.18
ARG         PARENT_IMAGE_TAG=lambda-python313
FROM        ghcr.io/astral-sh/uv:${UV_VERSION} AS uv
FROM        ${AWS_ACCOUNT}.dkr.ecr.us-east-1.amazonaws.com/docker-parent-images:${PARENT_IMAGE_TAG} AS base

ENV         PYTHONUNBUFFERED=1 \
            UV_COMPILE_BYTECODE=1 \
            UV_LINK_MODE=copy \
            UV_PYTHON_DOWNLOADS=never \
            UV_CACHE_DIR="/tmp/uv_cache"

USER        root

WORKDIR     /var/task

COPY        --from=uv /uv /uvx /bin/

# Copy workspace dependencies
COPY        pyproject.toml uv.lock ./
COPY        common common


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

# Provide locale and cache settings for linting and test tooling executed via uv.
ENV         LC_ALL=en_US.utf-8 \
            LC_CTYPE=en_US.UTF-8 \
            PYTHONPYCACHEPREFIX=/tmp/pycache \
            XDG_CACHE_HOME=${LAMBDA_TASK_ROOT}/.cache \
            PYTEST_ADDOPTS=--basetemp=/tmp/pytest \
            COVERAGE_FILE=/tmp/.coverage

WORKDIR     /var/task/sfn/integration_tests
COPY        sfn/integration_tests/pyproject.toml ./

RUN         --mount=type=cache,target=$UV_CACHE_DIR \
            uv sync

COPY        sfn/integration_tests/src/ ./src/
COPY        sfn/integration_tests/tests/ ./tests/

USER        worker

# Prevent unnecessary resyncs when mounting the project directory.
ENV         UV_NO_SYNC=1

ENTRYPOINT  []
CMD         ["/bin/sh"]


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

USER        root

WORKDIR     /var/task/sfn/integration_tests

COPY        sfn/integration_tests/tests ./tests/
COPY        sfn/integration_tests/scripts ./scripts/


# Re-enable syncing and install dev dependencies
ENV         UV_NO_SYNC=0
RUN         --mount=type=cache,target=$UV_CACHE_DIR \
            uv sync

ENTRYPOINT  ["scripts/integration.sh"]
