From 4fca342935f8b4d33341663f07019ccb5904686f Mon Sep 17 00:00:00 2001 From: Ivan Subotic <400790+subotic@users.noreply.github.com> Date: Thu, 20 Feb 2025 21:40:09 +0100 Subject: [PATCH] build: docker --- .dockerignore | 2 ++ Dockerfile | 35 ++++++++++++++++++++++------------- docker-compose.yml | 1 + 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.dockerignore b/.dockerignore index e502a14..c7623b9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,4 @@ /venv /dist +/target +.venv \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0dcb96f..2a7e441 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,31 +27,40 @@ RUN ls -la dist # ---- Setup Python Service ---- FROM python:3.11-slim AS runtime +COPY --from=ghcr.io/astral-sh/uv:0.6.2 /uv /uvx /bin/ -WORKDIR /app/ark_resolver +WORKDIR /app # Install required dependencies RUN apt-get update && apt-get install -y libssl-dev && rm -rf /var/lib/apt/lists/* -# Create a virtual environment -RUN python -m venv /venv -ENV PATH="/venv/bin:$PATH" +# Enable bytecode compilation +ENV UV_COMPILE_BYTECODE=1 + +# Copy from the cache instead of linking since it's a mounted volume +ENV UV_LINK_MODE=copy + +# Install the project's dependencies using the lockfile and settings +RUN --mount=type=cache,target=/root/.cache/uv \ + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + uv sync --frozen --no-install-project --no-dev -# Install Python dependencies -COPY requirements.txt . -RUN pip install --no-cache-dir --upgrade pip && pip install --no-cache-dir -r requirements.txt +# Then, add the rest of the project source code and install it +# Installing separately from its dependencies allows optimal layer caching +ADD . /app + +# Place executables in the environment at the front of the path +ENV PATH="/app/.venv/bin:$PATH" # Copy the Rust-built Python package and install it COPY --from=builder /app/dist/*.whl . -RUN pip install *.whl && rm -f *.whl +RUN uv pip install *.whl && rm -f *.whl # Verify the installation of the ark_resolver module RUN python -c "import _rust; print('_rust module installed successfully')" -# Copy Python service code -COPY python/src/ark_resolver /app/ark_resolver - -ENV PYTHONPATH="/app" +ENV PYTHONPATH=/app/python/src -ENTRYPOINT ["python3", "/app/ark_resolver/ark.py"] +ENTRYPOINT ["python3", "/app/python/src/ark_resolver/ark.py"] CMD ["-s"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 0215e89..1c0599e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,3 +11,4 @@ services: ARK_NAAN: "99999" ARK_HTTPS_PROXY: false ARK_REGISTRY: "app/python/src/ark_resolver/ark-registry.ini" + PYTHONPATH: "/app/python/src"