ops: improve the layering of the docker image
This commit is contained in:
+20
-17
@@ -1,31 +1,34 @@
|
||||
FROM python:3.12-slim-trixie AS builder
|
||||
FROM python:3.12-slim-trixie
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
||||
|
||||
# Set environment variables
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
|
||||
ADD . /app
|
||||
ENV DEBIAN_FRONTEND=noninteractive \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PYTHONDONTWRITEBYTECODE=1
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
# Copy dependency file first for better layer caching
|
||||
COPY pyproject.toml ./
|
||||
|
||||
# Install dependencies only
|
||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
|
||||
uv sync --no-install-project --all-extras --compile-bytecode
|
||||
|
||||
# Install all browsers and their deps
|
||||
RUN uv run playwright install-deps chromium firefox
|
||||
RUN uv run playwright install chromium
|
||||
RUN uv run camoufox fetch --browserforge
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Sync the project
|
||||
# Install browsers and project in one optimized layer
|
||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||
uv sync --all-extras --compile-bytecode
|
||||
|
||||
# Clean up to save space
|
||||
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
--mount=type=cache,target=/var/cache/apt \
|
||||
--mount=type=cache,target=/var/lib/apt \
|
||||
apt-get update && \
|
||||
uv run playwright install-deps chromium firefox && \
|
||||
uv run playwright install chromium && \
|
||||
uv run camoufox fetch --browserforge && \
|
||||
uv sync --all-extras --compile-bytecode && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
|
||||
# Expose port for MCP server HTTP transport
|
||||
EXPOSE 8000
|
||||
|
||||
+2
-4
@@ -4,7 +4,8 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "scrapling"
|
||||
dynamic = ["version"]
|
||||
# Static version instead of dynamic version so we can get better layer caching while building docker, check the docker file to understand
|
||||
version = "0.3.6"
|
||||
description = "Scrapling is an undetectable, powerful, flexible, high-performance Python library that makes Web Scraping easy and effortless as it should be!"
|
||||
readme = {file = "README.md", content-type = "text/markdown"}
|
||||
license = {file = "LICENSE"}
|
||||
@@ -99,9 +100,6 @@ scrapling = "scrapling.cli:main"
|
||||
zip-safe = false
|
||||
include-package-data = true
|
||||
|
||||
[tool.setuptools.dynamic]
|
||||
version = {attr = "scrapling.__version__"}
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
where = ["."]
|
||||
include = ["scrapling*"]
|
||||
Reference in New Issue
Block a user