Skip to content

Commit

Permalink
build: copy python packages into /usr instead of ~ros2 to avoid permi…
Browse files Browse the repository at this point in the history
…ssion issues
  • Loading branch information
LouisBrunner committed Feb 20, 2024
1 parent d0c5ef7 commit 37f88eb
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,15 @@ COPY --from=install /tmp/communication-interfaces /usr
COPY --chown=${USER}:${USER} ./python /python
RUN --mount=type=cache,target=${HOME}/.cache,id=pip-${TARGETPLATFORM}-${CACHEID},uid=1000 \
python3 -m pip install --prefix=/tmp/python /python
RUN mkdir -p /tmp/python-home/${USER}/.local/lib/python3.10/ \
&& mv /tmp/python/local/lib/python3.10/dist-packages/ /tmp/python-home/${USER}/.local/lib/python3.10/site-packages/
RUN mv /tmp/python/local /tmp/python-usr

FROM build as test
ARG TARGETPLATFORM
ARG CACHEID
RUN --mount=type=cache,target=./build,id=cmake-${TARGETPLATFORM}-${CACHEID},uid=1000 \
cmake -B build -DBUILD_TESTING=ON && cd build && make && CTEST_OUTPUT_ON_FAILURE=1 make test
COPY --from=install /tmp/communication-interfaces /usr/local
COPY --from=python /tmp/python-home/ /home
COPY --from=python /tmp/python-usr /usr
COPY --from=python /python/test /python/test
RUN python3 -m pytest /python/test --verbose

Expand All @@ -98,7 +97,7 @@ ARG TARGETPLATFORM
ARG CACHEID
COPY --from=apt-dependencies /tmp/apt /
COPY --from=install /tmp/communication-interfaces /usr
COPY --from=python /tmp/python-home /home
COPY --from=python /tmp/python-usr /usr
RUN sudo pip install pybind11-stubgen
RUN --mount=type=cache,target=${HOME}/.cache,id=pip-${TARGETPLATFORM}-${CACHEID},uid=1000 \
<<HEREDOC
Expand All @@ -125,11 +124,10 @@ EoF
rm -r ./stubs
fi
HEREDOC
RUN mkdir -p /tmp/python-home/${USER}/.local/lib/python3.10/ \
&& mv /tmp/python/local/lib/python3.10/dist-packages/ /tmp/python-home/${USER}/.local/lib/python3.10/site-packages/
RUN mv /tmp/python/local /tmp/python-usr

FROM scratch as production
COPY --from=apt-dependencies /tmp/apt /
COPY --from=install /tmp/communication-interfaces /usr/local
COPY --from=python /tmp/python-home/ /home
COPY --from=python-stubs /tmp/python-home /home
COPY --from=python /tmp/python-usr /usr
COPY --from=python-stubs /tmp/python-usr /usr

0 comments on commit 37f88eb

Please sign in to comment.