From 34342304463cde2e4e2f73e030d9369fc04e5793 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Thu, 10 Oct 2024 02:12:33 +0300 Subject: [PATCH] fix: rewrite Dockerfile --- src/gnomik/Dockerfile | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/gnomik/Dockerfile b/src/gnomik/Dockerfile index 102c751..ea0124f 100644 --- a/src/gnomik/Dockerfile +++ b/src/gnomik/Dockerfile @@ -1,25 +1,38 @@ -FROM python:3.12-slim as builder +FROM python:3.12-slim AS dependencies_installer RUN pip install poetry -RUN mkdir -p /app -COPY . /app -# Fix +WORKDIR /app -RUN sed -i '/karkas-core = {/{s/, develop = true//}' /app/src/altlinux/pyproject.toml && \ - sed -i '/karkas-blocks = {/{s/, develop = true//}' /app/src/altlinux/pyproject.toml && \ - sed -i '/karkas-core = {/{s/, develop = true//}' /app/src/karkas_blocks/pyproject.toml +COPY ./src/karkas_core/poetry* ./src/karkas_core/pyproject.toml /app/src/karkas_core/ +COPY ./src/karkas_blocks/poetry* ./src/karkas_blocks/pyproject.toml /app/src/karkas_blocks/ +COPY ./src/karkas_piccolo/poetry* ./src/karkas_piccolo/pyproject.toml /app/src/karkas_piccolo/ +COPY ./src/gnomik/poetry* ./src/gnomik/pyproject.toml /app/src/gnomik/ WORKDIR /app/src/gnomik -RUN poetry lock && poetry install +RUN poetry install --no-root --no-directory -FROM python:3.12-slim as base +FROM python:3.12-slim AS src -# Copy the virtual environment separately to improve caching -COPY --from=builder /app/src/gnomik/.venv /app/.venv -COPY --from=builder /app/src/gnomik /app +COPY ./src/karkas_core /app/src/karkas_core +COPY ./src/karkas_blocks /app/src/karkas_blocks +COPY ./src/karkas_piccolo /app/src/karkas_piccolo +COPY ./src/gnomik /app/src/gnomik -WORKDIR /app +FROM python:3.12-slim AS local_dependencies_installer + +RUN pip install poetry + +COPY --from=dependencies_installer /app/src/gnomik/.venv /app/src/gnomik/.venv +COPY --from=src /app/src/ /app/src/ +WORKDIR /app/src/gnomik +RUN poetry install + +FROM python:3.12-slim AS base +COPY --from=local_dependencies_installer /app/src/gnomik/.venv /app/src/gnomik/.venv +COPY --from=src /app/src/ /app/src/ +WORKDIR /app/src/gnomik ENV PATH="/app/.venv/bin:$PATH" -CMD ["python", "-m", "gnomik"] + +CMD ["/bin/bash", "-c", ". .venv/bin/activate && python -m gnomik"]