|
1 | 1 | ARG PYTHON_VERSION=3.12 |
| 2 | +ARG BUILDPLATFORM=x86_64 |
2 | 3 |
|
3 | | -FROM public.ecr.aws/lambda/python:${PYTHON_VERSION} |
4 | | -COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ |
| 4 | +FROM --platform=${BUILDPLATFORM} ghcr.io/astral-sh/uv:0.6.6 AS uv |
| 5 | +FROM --platform=${BUILDPLATFORM} public.ecr.aws/lambda/python:${PYTHON_VERSION} AS builder |
5 | 6 |
|
6 | | -# Install required utilities |
7 | | -RUN dnf install -y findutils binutils git && \ |
| 7 | +ENV UV_COMPILE_BYTECODE=1 |
| 8 | +ENV UV_NO_INSTALLER_METADATA=1 |
| 9 | +ENV UV_LINK_MODE=copy |
| 10 | +ENV PATH="/root/.cargo/bin:${PATH}" |
| 11 | +ENV MATURIN_PEP517_ARGS="--features=duckdb-bundled" |
| 12 | + |
| 13 | +RUN dnf install -y findutils binutils git gcc g++ && \ |
8 | 14 | dnf clean all && \ |
9 | 15 | rm -rf /var/cache/dnf |
| 16 | +RUN curl https://sh.rustup.rs -sSf | bash -s -- -y |
10 | 17 |
|
11 | | -WORKDIR /tmp |
12 | | -COPY uv.lock uv.lock |
13 | | -COPY pyproject.toml pyproject.toml |
14 | | -COPY README.md README.md |
15 | | -COPY src/ src/ |
16 | | - |
17 | | -RUN uv pip install --compile-bytecode .[lambda] --target /asset |
18 | | - |
19 | | -# Reduce package size and remove useless files |
| 18 | +RUN --mount=from=uv,source=/uv,target=/bin/uv \ |
| 19 | + --mount=type=cache,target=/root/.cache/uv \ |
| 20 | + --mount=type=bind,source=uv.lock,target=uv.lock \ |
| 21 | + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ |
| 22 | + uv export --frozen --no-emit-workspace --no-dev --no-editable --extra lambda -o requirements.txt && \ |
| 23 | + uv pip install -r requirements.txt --target /asset |
20 | 24 | WORKDIR /asset |
| 25 | +RUN python -c "from stacrs import DuckdbClient; DuckdbClient(use_s3_credential_chain=True, use_azure_credential_chain=False, install_extensions=True, extension_directory='/asset/duckdb-extensions')" |
21 | 26 | RUN find . -type f -name '*.pyc' | while read f; do n=$(echo $f | sed 's/__pycache__\///' | sed 's/.cpython-[0-9]*//'); cp $f $n; done; |
22 | 27 | RUN find . -type d -a -name '__pycache__' -print0 | xargs -0 rm -rf |
23 | 28 | RUN find . -type f -a -name '*.py' -print0 | xargs -0 rm -f |
24 | 29 | RUN find . -type d -a -name 'tests' -print0 | xargs -0 rm -rf |
25 | | - |
26 | | -# Strip debug symbols from compiled C/C++ code |
27 | 30 | RUN find . -type f -name '*.so*' -exec strip --strip-unneeded {} \; |
28 | 31 |
|
| 32 | +FROM --platform=${BUILDPLATFORM} public.ecr.aws/lambda/python:${PYTHON_VERSION} |
| 33 | +WORKDIR /asset |
| 34 | +COPY --from=builder /asset /asset |
29 | 35 | COPY infrastructure/aws/lambda/handler.py /asset/handler.py |
0 commit comments