FROM public.ecr.aws/lambda/python:3.12 AS wheel_builder

RUN dnf install -y git gcc make gfortran tar xz

WORKDIR /

RUN curl -L https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz | tar -xJ \
 && mv ffmpeg-7.0-amd64-static ffmpeg

RUN mkdir wheels \
 && cd wheels \
 && pip wheel 'git+https://github.com/CPJKU/madmom@0551aa8f48d71a367d92b5d3a347a0cf7cd97cc9#egg=madmom'

FROM public.ecr.aws/lambda/python:3.12 AS output

COPY --from=wheel_builder ffmpeg/ffmpeg ffmpeg/ffprobe /usr/local/bin/

COPY requirements.txt ${LAMBDA_TASK_ROOT}

COPY --from=wheel_builder /wheels/madmom*.whl ./
RUN pip install -r requirements.txt \
 && pip install ./madmom*.whl \
 && rm -f ./*.whl \
 && pip cache purge

COPY lambda_function.py lambda_multiprocessing.py evil.py ${LAMBDA_TASK_ROOT}

CMD [ "lambda_function.handler" ]
