
ARG DOCKER_BUILDKIT=1

FROM python:3.14.2-slim as python-base
ENV VIRTUAL_ENV=.venv/
ENV POETRY_VIRTUALENVS_PATH=${VIRTUAL_ENV}
ENV WORK_DIR=/workspaces
WORKDIR ${WORK_DIR}
RUN apt-get update && \
    apt-get install -y make git && \
    apt-get clean autoclean && \
    apt-get autoremove --yes


FROM python-base as py2ecma-base
# Install poetry but clear all .cache in the same layer.
# If this is not done in the same layer it will still persist.
RUN pip install --no-compile --no-cache-dir poetry &&\
    rm -rf /root/.cache/ &&\
    find /usr/local/lib -path '*/__pycache__*' -delete
COPY poetry.lock pyproject.toml Makefile README.md ${WORK_DIR}/
COPY scripts/ ${WORK_DIR}/scripts

FROM py2ecma-base as py2ecma-dev
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
ENV VIRTUAL_ENV=.venv/
RUN make install-ci


# Create requirements.txt file from poetry, check that they are in sync
FROM py2ecma-base as py2ecma-requirements

RUN make freeze

FROM python-base as py2ecma-deploy
COPY --from=py2ecma-requirements ${WORK_DIR}/requirements.txt ${WORK_DIR}/requirements.txt
RUN pip install -r requirements.txt &&\
    rm -rf /root/.cache/ &&\
    find /usr/local/lib -path '*/__pycache__*' -delete
COPY . ${WORK_DIR}

FROM python-base as py2ecma-ci
COPY --from=py2ecma-requirements ${WORK_DIR}/requirements-dev.txt ${WORK_DIR}/requirements.txt
RUN pip install -r requirements.txt &&\
    rm -rf /root/.cache/ &&\
    find /usr/local/lib -path '*/__pycache__*' -delete
COPY . ${WORK_DIR}


