# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

FROM mcr.microsoft.com/cbl-mariner/base/core:2.0 AS builder


RUN tdnf update -y || echo "Not updating anything..." &&\
    tdnf install -y tar ca-certificates && tdnf clean all

WORKDIR /usr/local

RUN curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba && \
    ln -s /usr/local/bin/micromamba /usr/local/bin/conda && \
    chmod +x /usr/local/bin/micromamba

COPY resources/envs/rest-api_orchestrator.yml /tmp/rest-api.yml
COPY resources/envs/services-requirements.txt /tmp/services-requirements.txt

RUN conda env create -p /opt/conda -f /tmp/rest-api.yml && \
    conda clean --all --yes

ENV CONDA_PREFIX=/opt/conda
RUN /opt/conda/bin/pip install uv && \
    /opt/conda/bin/uv pip install -r /tmp/services-requirements.txt && \
    /opt/conda/bin/uv cache clean && \
    rm -r /root/.cache/pip && \
    rm -rf /root/.mamba && \
    rm -rf /opt/*conda/pkgs && \
    rm -rf /app/docker && \
    find / -type d -name __pycache__ | xargs rm -rf && \
    rm /tmp/rest-api.yml && \
    rm /tmp/services-requirements.txt && \
    rm -fr /var/cache/tdnf && \
    rm -fr /var/cache/conda

ENV PATH "/opt/conda/bin:${PATH}"
