Skip to content

Commit ef104fb

Browse files
committed
make PIN_SETUPTOOLS optional
1 parent 22e4584 commit ef104fb

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ ENV PATH=/root/.cargo/bin:$PATH
2626
# Install datadog_lambda and dependencies from local
2727
COPY . .
2828

29-
# Constrain setuptools<78 for build isolation environments so that
30-
# pkg_resources is available when building dd-trace-py from source.
31-
RUN echo 'setuptools<78' > /tmp/build-constraints.txt
29+
# When building dd-trace-py from source (older commits), setuptools<78 is needed
30+
# in pip's build isolation environment so that pkg_resources is available.
31+
# An empty constraints file is a no-op for pip.
32+
ARG pin_setuptools=""
33+
RUN if [ -n "$pin_setuptools" ]; then \
34+
echo 'setuptools<78' > /tmp/build-constraints.txt; \
35+
else \
36+
touch /tmp/build-constraints.txt; \
37+
fi
3238
ENV PIP_CONSTRAINT=/tmp/build-constraints.txt
3339

3440
RUN pip install --no-cache-dir . -t ./python/lib/$runtime/site-packages

scripts/build_layers.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# DD_TRACE_COMMIT Specific dd-trace-py commit SHA to build from GitHub.
2121
# DD_TRACE_COMMIT_BRANCH dd-trace-py branch name to build from GitHub.
2222
# DD_TRACE_WHEEL Path to a pre-built ddtrace .whl file.
23+
# PIN_SETUPTOOLS Set to "true" to constrain setuptools<78 in Docker.
24+
# Only needed for old dd-trace-py commits that import pkg_resources.
2325
#
2426
# Examples:
2527
# # Build a single layer for Python 3.12 on arm64
@@ -92,6 +94,7 @@ replace_ddtrace_dep() {
9294
}
9395

9496
# Replace ddtrace source if necessary
97+
DOCKER_BUILD_ARGS=""
9598
if [ -n "$DD_TRACE_COMMIT" ]; then
9699
replace_ddtrace_dep "ddtrace = { git = \"https://github.com/DataDog/dd-trace-py.git\", rev = \"$DD_TRACE_COMMIT\" }"
97100
elif [ -n "$DD_TRACE_COMMIT_BRANCH" ]; then
@@ -100,6 +103,12 @@ elif [ -n "$DD_TRACE_WHEEL" ]; then
100103
replace_ddtrace_dep "ddtrace = { file = \"$DD_TRACE_WHEEL\" }"
101104
fi
102105

106+
# Older dd-trace-py commits import pkg_resources, which was removed in setuptools>=78.
107+
# Set PIN_SETUPTOOLS=true to constrain setuptools<78 in pip's build isolation.
108+
if [ -n "$PIN_SETUPTOOLS" ]; then
109+
DOCKER_BUILD_ARGS="--build-arg pin_setuptools=true"
110+
fi
111+
103112
function make_path_absolute {
104113
echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
105114
}
@@ -118,6 +127,7 @@ function docker_build_zip {
118127
--build-arg runtime=python$1 \
119128
--platform linux/${arch} \
120129
--progress=plain \
130+
$DOCKER_BUILD_ARGS \
121131
-o $temp_dir/python
122132

123133
# Zip to destination, and keep directory structure as based in $temp_dir

0 commit comments

Comments
 (0)