FROM amazon/aws-lambda-python:3.11 as build-base

ARG version
LABEL Version=$version
ENV build_version=$version

RUN yum install -q -y jq gcc

RUN pip install --upgrade pip

COPY src/ ./src
COPY config.py requirements.txt ./

RUN pip install -r requirements.txt


FROM build-base as test

COPY requirements-test.txt ./
RUN pip install -r requirements-test.txt

COPY tests/ ./tests
COPY lint-and-test.sh integration-test.sh .flake8 pyproject.toml docker-compose.yaml ./


FROM build-base as local

CMD [ "src.app.handler" ]


FROM build-base as main

# Run i18n process
ARG POEDITOR_PROJECT_ID
ENV POEDITOR_PROJECT_ID=$POEDITOR_PROJECT_ID
COPY i18n.sh babel.cfg ./
RUN --mount=type=secret,id=poeditor-api-token,env=POEDITOR_API_TOKEN /var/task/i18n.sh

COPY --from=public.ecr.aws/datadog/lambda-extension:84 /opt/extensions/ /opt/extensions

ENV DD_LAMBDA_HANDLER=src.app.handler
CMD [ "datadog_lambda.handler.handler" ]
