fix: rewrite Dockerfile

This commit is contained in:
Maxim Slipenko 2024-10-10 02:12:33 +03:00
parent bd3a897557
commit 3434230446
No known key found for this signature in database
GPG Key ID: 6DEA9FA7DE98C7D6

View File

@ -1,25 +1,38 @@
FROM python:3.12-slim as builder FROM python:3.12-slim AS dependencies_installer
RUN pip install poetry 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 && \ COPY ./src/karkas_core/poetry* ./src/karkas_core/pyproject.toml /app/src/karkas_core/
sed -i '/karkas-blocks = {/{s/, develop = true//}' /app/src/altlinux/pyproject.toml && \ COPY ./src/karkas_blocks/poetry* ./src/karkas_blocks/pyproject.toml /app/src/karkas_blocks/
sed -i '/karkas-core = {/{s/, develop = true//}' /app/src/karkas_blocks/pyproject.toml 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 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 ./src/karkas_core /app/src/karkas_core
COPY --from=builder /app/src/gnomik/.venv /app/.venv COPY ./src/karkas_blocks /app/src/karkas_blocks
COPY --from=builder /app/src/gnomik /app 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" ENV PATH="/app/.venv/bin:$PATH"
CMD ["python", "-m", "gnomik"]
CMD ["/bin/bash", "-c", ". .venv/bin/activate && python -m gnomik"]