diff --git a/backend/Dockerfile.build b/backend/Dockerfile.build deleted file mode 100644 index 879a0c30720..00000000000 --- a/backend/Dockerfile.build +++ /dev/null @@ -1,18 +0,0 @@ -# Dockerfile -FROM python:3.12-slim - -WORKDIR /app - -COPY . . - -RUN pip install --upgrade pip && \ - pip install 'fastapi[standard]' - -# bash conditional to verify if requirements.txt exists and install dependencies -RUN if [ -f requirements.txt ]; then \ - pip install -r requirements.txt; \ - else \ - echo "No requirements.txt file found, there is not extra dependencies to install"; \ - fi - -CMD ["sh", "-c", "fastapi run --host 0.0.0.0 --port ${PORT:-8000}"] diff --git a/backend/Dockerfile.builder b/backend/Dockerfile.builder index 1adbeaa99d4..69270ba5597 100644 --- a/backend/Dockerfile.builder +++ b/backend/Dockerfile.builder @@ -35,7 +35,9 @@ COPY ./scripts /app/scripts COPY ./pyproject.toml ./uv.lock ./alembic.ini /app/ -COPY Dockerfile.build /app/Dockerfile +COPY Dockerfile.standard /app/Dockerfile.standard +COPY Dockerfile.requirements /app/Dockerfile.requirements + COPY builder_entrypoint.sh /app/builder_entrypoint.sh RUN chmod +x /app/builder_entrypoint.sh diff --git a/backend/Dockerfile.requirements b/backend/Dockerfile.requirements new file mode 100644 index 00000000000..0d759196250 --- /dev/null +++ b/backend/Dockerfile.requirements @@ -0,0 +1,31 @@ +# Dockerfile +FROM python:3.12-slim + +WORKDIR /app + +# Install uv +# Ref: https://docs.astral.sh/uv/guides/integration/docker/#installing-uv +COPY --from=ghcr.io/astral-sh/uv:0.4.15-alpine /usr/local/bin/uv /bin/uv + +# Using uv as pip interface +# Ref: https://docs.astral.sh/uv/guides/integration/docker/#using-the-pip-interface +ENV UV_SYSTEM_PYTHON=1 + +# Compile bytecode +# Ref: https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode +ENV UV_COMPILE_BYTECODE=1 + +# uv Cache +# Ref: https://docs.astral.sh/uv/guides/integration/docker/#caching +ENV UV_LINK_MODE=copy + +COPY requirements.txt . + +# Install dependencies +RUN uv pip install -r requirements.txt + +ENV PYTHONPATH=/app + +COPY . . + +CMD ["sh", "-c", "fastapi run --host 0.0.0.0 --port ${PORT:-8000}"] diff --git a/backend/Dockerfile.standard b/backend/Dockerfile.standard new file mode 100644 index 00000000000..e67f6c4e0c7 --- /dev/null +++ b/backend/Dockerfile.standard @@ -0,0 +1,29 @@ +# Dockerfile +FROM python:3.12-slim + +WORKDIR /app + +# Install uv +# Ref: https://docs.astral.sh/uv/guides/integration/docker/#installing-uv +COPY --from=ghcr.io/astral-sh/uv:0.4.15-alpine /usr/local/bin/uv /bin/uv + +# Using uv as pip interface +# Ref: https://docs.astral.sh/uv/guides/integration/docker/#using-the-pip-interface +ENV UV_SYSTEM_PYTHON=1 + +# Compile bytecode +# Ref: https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode +ENV UV_COMPILE_BYTECODE=1 + +# uv Cache +# Ref: https://docs.astral.sh/uv/guides/integration/docker/#caching +ENV UV_LINK_MODE=copy + +# Install dependencies +RUN uv pip install 'fastapi[standard]' + +ENV PYTHONPATH=/app + +COPY . . + +CMD ["sh", "-c", "fastapi run --host 0.0.0.0 --port ${PORT:-8000}"] diff --git a/backend/app/docker_builder.py b/backend/app/docker_builder.py index 55fdd35737f..4e354250753 100644 --- a/backend/app/docker_builder.py +++ b/backend/app/docker_builder.py @@ -290,7 +290,11 @@ def process_message(message: dict[str, Any], session: SessionDep) -> None: create_ecr_repository(image_tag) # Copy Dockerfile to build context - shutil.copy("/app/Dockerfile", build_context) + build_files = os.listdir(build_context) + if "requirements.txt" in build_files: + shutil.copy("/app/Dockerfile.requirements", f"{build_context}/Dockerfile") + else: + shutil.copy("/app/Dockerfile.standard", f"{build_context}/Dockerfile") # Build and push Docker image sha256 = build_and_push_docker_image(image_tag, build_context, registry_url)