Skip to content

Commit 7025d14

Browse files
committed
[TRTLLM-9227][infra] Add Dockerfile step to copy sources
In this change we add a new Dockerfile step which copies third-party source files into the container image. This is necessary for compliance with certain open source licenses which require source code availability. Distributing the sources as-used in the container image is a simple and direct way of ensuring the sources are used and mapped to the version that was built in the container. The script to perform this step relies on the C++ third-party process which requires third-party libraries to be integrated with CMake's FetchContent modules. The script scans the _deps/ directory and collects all the *-src directories which are created by FetchContent. It archives these into same-named tarballs and places them in `/third_party_sources/`. Signed-off-by: Josh Bialkowski <1309820+cheshirekow@users.noreply.github.com>
1 parent 9b2abb8 commit 7025d14

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

docker/Dockerfile.multi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ ARG GITHUB_MIRROR=""
128128
ARG BUILD_WHEEL_ARGS="--clean --benchmarks"
129129
ARG BUILD_WHEEL_SCRIPT="scripts/build_wheel.py"
130130
RUN --mount=type=cache,target=/root/.cache/pip --mount=type=cache,target=${CCACHE_DIR} \
131-
GITHUB_MIRROR=$GITHUB_MIRROR python3 ${BUILD_WHEEL_SCRIPT} ${BUILD_WHEEL_ARGS}
131+
GITHUB_MIRROR=$GITHUB_MIRROR python3 ${BUILD_WHEEL_SCRIPT} ${BUILD_WHEEL_ARGS} \
132+
&& python3 scripts/copy_third_party_sources.py \
133+
--deps-dir ./build/_deps \
134+
--output-dir /third-party-sources
132135

133136
FROM ${DEVEL_IMAGE} AS release
134137

@@ -155,6 +158,8 @@ ARG SRC_DIR=/src/tensorrt_llm
155158
COPY --from=wheel ${SRC_DIR}/benchmarks benchmarks
156159
ARG CPP_BUILD_DIR=${SRC_DIR}/cpp/build
157160
COPY --from=wheel \
161+
/third-party-sources \
162+
${CPP_BUILD_DIR}/_deps \
158163
${CPP_BUILD_DIR}/benchmarks/bertBenchmark \
159164
${CPP_BUILD_DIR}/benchmarks/gptManagerBenchmark \
160165
${CPP_BUILD_DIR}/benchmarks/disaggServerBenchmark \
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""Copy third-party sources used in the cmake build to a container directory.
2+
3+
The purpose of this script is to simplify the process of producing third party
4+
sources "as used" in the build. We package up all of the sources we use and
5+
stash them in a location in the container so that they are automatically
6+
distributed alongside the build artifacts ensuring that we comply with the
7+
license requirements in an obvious and transparent manner.
8+
"""
9+
10+
import argparse
11+
import logging
12+
import pathlib
13+
import subprocess
14+
15+
logger = logging.getLogger(__name__)
16+
17+
18+
def main():
19+
parser = argparse.ArgumentParser(description=__doc__)
20+
parser.add_argument(
21+
"--deps-dir",
22+
type=pathlib.Path,
23+
required=True,
24+
help="Path to the third party dependencies directory, e.g. ${CMAKE_BINARY_DIR}/_deps",
25+
)
26+
parser.add_argument(
27+
"--output-dir",
28+
type=pathlib.Path,
29+
required=True,
30+
help="Path to the output directory where third party sources will be copied",
31+
)
32+
33+
args = parser.parse_args()
34+
35+
src_dirs = list(sorted(args.deps_dir.glob("*-src")))
36+
if not src_dirs:
37+
raise ValueError(f"No source directories found in {args.deps_dir}")
38+
39+
for src_dir in src_dirs:
40+
tarball_name = src_dir.name[:-4] + ".tar.gz"
41+
output_path = args.output_dir / tarball_name
42+
logger.info(f"Creating tarball {output_path} from {src_dir}")
43+
args.output_dir.mkdir(parents=True, exist_ok=True)
44+
subprocess.run(
45+
["tar", "-czf", str(output_path), "-C", str(src_dir.parent), src_dir.name], check=True
46+
)
47+
48+
49+
if __name__ == "__main__":
50+
logging.basicConfig(level=logging.INFO)
51+
main()

0 commit comments

Comments
 (0)