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/
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
||||||
|
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
ENV DEBIAN_FRONTEND=noninteractive
|
ENV DEBIAN_FRONTEND=noninteractive \
|
||||||
ENV PYTHONUNBUFFERED=1
|
PYTHONUNBUFFERED=1 \
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1
|
PYTHONDONTWRITEBYTECODE=1
|
||||||
|
|
||||||
ADD . /app
|
|
||||||
|
|
||||||
WORKDIR /app
|
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 \
|
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
|
uv sync --no-install-project --all-extras --compile-bytecode
|
||||||
|
|
||||||
# Install all browsers and their deps
|
# Copy source code
|
||||||
RUN uv run playwright install-deps chromium firefox
|
COPY . .
|
||||||
RUN uv run playwright install chromium
|
|
||||||
RUN uv run camoufox fetch --browserforge
|
|
||||||
|
|
||||||
# Sync the project
|
# Install browsers and project in one optimized layer
|
||||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||||
uv sync --all-extras --compile-bytecode
|
--mount=type=cache,target=/var/cache/apt \
|
||||||
|
--mount=type=cache,target=/var/lib/apt \
|
||||||
# Clean up to save space
|
apt-get update && \
|
||||||
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
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 port for MCP server HTTP transport
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|||||||
+2
-4
@@ -4,7 +4,8 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "scrapling"
|
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!"
|
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"}
|
readme = {file = "README.md", content-type = "text/markdown"}
|
||||||
license = {file = "LICENSE"}
|
license = {file = "LICENSE"}
|
||||||
@@ -99,9 +100,6 @@ scrapling = "scrapling.cli:main"
|
|||||||
zip-safe = false
|
zip-safe = false
|
||||||
include-package-data = true
|
include-package-data = true
|
||||||
|
|
||||||
[tool.setuptools.dynamic]
|
|
||||||
version = {attr = "scrapling.__version__"}
|
|
||||||
|
|
||||||
[tool.setuptools.packages.find]
|
[tool.setuptools.packages.find]
|
||||||
where = ["."]
|
where = ["."]
|
||||||
include = ["scrapling*"]
|
include = ["scrapling*"]
|
||||||
Reference in New Issue
Block a user