Skip to content

Commit

Permalink
Rebuild ld cache in build (#1903)
Browse files Browse the repository at this point in the history
* Rebuild ld cache in build

* Find all the python related SO’s, and their
corresponding folders and put them in a cog.conf
file in the /etc/ld.so.conf.d folder
* Run ldconfig to rebuild the cache

* Only add the folders to the ld cache

---------

Signed-off-by: Will Sackfield <[email protected]>
  • Loading branch information
8W9aG authored Sep 11, 2024
1 parent de795b3 commit ac53c32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/dockerfile/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ coverage.xml
.pytest_cache
.hypothesis
`
const LDConfigCacheBuildCommand = "RUN find / -type f -name \"*python*.so\" -printf \"%h\\n\" | sort -u > /etc/ld.so.conf.d/cog.conf && ldconfig"
const StripDebugSymbolsCommand = "find / -type f -name \"*python*.so\" -not -name \"*cpython*.so\" -exec strip -S {} \\;"
const CFlags = "ENV CFLAGS=\"-O3 -funroll-loops -fno-strict-aliasing -flto -S\""

Expand Down Expand Up @@ -170,6 +171,7 @@ func (g *Generator) generateInitialSteps() (string, error) {
installPython,
aptInstalls,
g.copyPipPackagesFromInstallStage(),
LDConfigCacheBuildCommand,
runCommands,
}), nil
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/dockerfile/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ ENV PYTHONUNBUFFERED=1
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/usr/local/nvidia/lib64:/usr/local/nvidia/bin
ENV NVIDIA_DRIVER_CAPABILITIES=all
` + testTini() + `COPY --from=deps --link /dep /usr/local/lib/python3.12/site-packages
RUN find / -type f -name "*python*.so" -printf "%h\n" | sort -u > /etc/ld.so.conf.d/cog.conf && ldconfig
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
Expand Down Expand Up @@ -145,6 +146,7 @@ RUN --mount=type=bind,from=deps,source=/dep,target=/dep \
cp -rf /dep/* $(pyenv prefix)/lib/python*/site-packages; \
cp -rf /dep/bin/* $(pyenv prefix)/bin; \
pyenv rehash
RUN find / -type f -name "*python*.so" -printf "%h\n" | sort -u > /etc/ld.so.conf.d/cog.conf && ldconfig
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
Expand Down Expand Up @@ -192,6 +194,7 @@ ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/usr/local/nvidia
ENV NVIDIA_DRIVER_CAPABILITIES=all
` + testTini() + `RUN --mount=type=cache,target=/var/cache/apt,sharing=locked apt-get update -qq && apt-get install -qqy ffmpeg cowsay && rm -rf /var/lib/apt/lists/*
COPY --from=deps --link /dep /usr/local/lib/python3.12/site-packages
RUN find / -type f -name "*python*.so" -printf "%h\n" | sort -u > /etc/ld.so.conf.d/cog.conf && ldconfig
RUN cowsay moo
WORKDIR /src
EXPOSE 5000
Expand Down Expand Up @@ -251,6 +254,7 @@ RUN --mount=type=bind,from=deps,source=/dep,target=/dep \
cp -rf /dep/* $(pyenv prefix)/lib/python*/site-packages; \
cp -rf /dep/bin/* $(pyenv prefix)/bin; \
pyenv rehash
RUN find / -type f -name "*python*.so" -printf "%h\n" | sort -u > /etc/ld.so.conf.d/cog.conf && ldconfig
RUN cowsay moo
WORKDIR /src
EXPOSE 5000
Expand Down Expand Up @@ -296,6 +300,7 @@ ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/usr/local/nvidia
ENV NVIDIA_DRIVER_CAPABILITIES=all
` + testTini() + `RUN --mount=type=cache,target=/var/cache/apt,sharing=locked apt-get update -qq && apt-get install -qqy cowsay && rm -rf /var/lib/apt/lists/*
COPY --from=deps --link /dep /usr/local/lib/python3.12/site-packages
RUN find / -type f -name "*python*.so" -printf "%h\n" | sort -u > /etc/ld.so.conf.d/cog.conf && ldconfig
RUN cowsay moo
WORKDIR /src
EXPOSE 5000
Expand Down Expand Up @@ -413,6 +418,7 @@ RUN --mount=type=bind,from=deps,source=/dep,target=/dep \
cp -rf /dep/* $(pyenv prefix)/lib/python*/site-packages; \
cp -rf /dep/bin/* $(pyenv prefix)/bin; \
pyenv rehash
RUN find / -type f -name "*python*.so" -printf "%h\n" | sort -u > /etc/ld.so.conf.d/cog.conf && ldconfig
RUN cowsay moo
COPY --from=weights --link /src/checkpoints /src/checkpoints
COPY --from=weights --link /src/models /src/models
Expand Down Expand Up @@ -485,6 +491,7 @@ ENV PYTHONUNBUFFERED=1
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/usr/local/nvidia/lib64:/usr/local/nvidia/bin
ENV NVIDIA_DRIVER_CAPABILITIES=all
` + testTini() + `COPY --from=deps --link /dep /usr/local/lib/python3.12/site-packages
RUN find / -type f -name "*python*.so" -printf "%h\n" | sort -u > /etc/ld.so.conf.d/cog.conf && ldconfig
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
Expand Down

0 comments on commit ac53c32

Please sign in to comment.