-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solved caching for building a custom package
- Loading branch information
Showing
3 changed files
with
44 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,39 @@ | ||
FROM ctumrs/mrs_uav_system:robofly | ||
ARG WORKSPACE_PATH | ||
ARG BASE_IMAGE=ctumrs/mrs_uav_system:latest | ||
|
||
ARG WORKSPACE_PATH="/etc/robofly/catkin_workspace" | ||
############################################################################# | ||
|
||
# create catkin workspace | ||
RUN mkdir -p ${WORKSPACE_PATH} && cd ${WORKSPACE_PATH} && rm -rf ./* && mkdir src | ||
RUN cd ${WORKSPACE_PATH} && catkin init | ||
# FIRST STAGE: BUILD THE WORKSPACE | ||
FROM $BASE_IMAGE AS stage_build | ||
|
||
ARG WORKSPACE_PATH | ||
|
||
# set workspace build profile | ||
RUN cd ${WORKSPACE_PATH} && catkin config --profile reldeb --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON && catkin profile set reldeb && catkin config --extend /opt/ros/noetic | ||
COPY ./cache/${WORKSPACE_PATH}/ /${WORKSPACE_PATH}/ | ||
|
||
# create catkin workspace | ||
RUN [ ! -e /${WORKSPACE_PATH}/.catkin_tools ] && cd /${WORKSPACE_PATH} && catkin init && catkin config --profile reldeb --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON && catkin profile set reldeb && catkin config --extend /opt/ros/noetic || echo "[Docker]: catkin workspace already exists" | ||
|
||
# copy the sources from the local subfolder | ||
COPY src/ ${WORKSPACE_PATH}/src/ | ||
COPY src/ /${WORKSPACE_PATH}/src/ | ||
|
||
RUN cd /${WORKSPACE_PATH} && catkin build -s | ||
|
||
############################################################################# | ||
|
||
# SECOND STAGE: COPY THE WORKSPACE TO A BLANK APLINE IMAGE | ||
FROM alpine AS stage_cache_workspace | ||
|
||
ARG WORKSPACE_PATH | ||
|
||
COPY --from=stage_build /${WORKSPACE_PATH} /${WORKSPACE_PATH} | ||
|
||
############################################################################# | ||
|
||
RUN ls ${WORKSPACE_PATH}/src/ | ||
# THIRD STAGE: copy the workspace to a final blank ROS-equipped base image | ||
FROM $BASE_IMAGE AS stage_finalization | ||
|
||
RUN cd ${WORKSPACE_PATH} && catkin build -s | ||
ARG WORKSPACE_PATH | ||
|
||
RUN mkdir -p /etc/robofly/ws && cp -r ${WORKSPACE_PATH}/* /etc/robofly/ws/ | ||
COPY --from=stage_cache_workspace /${WORKSPACE_PATH} /${WORKSPACE_PATH} | ||
|
||
CMD ["bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
#!/bin/bash | ||
|
||
LOCAL_TAG=robofly:custom_package | ||
REGISTRY=fly4future | ||
|
||
docker build . --file Dockerfile --tag $REGISTRY/$LOCAL_TAG --no-cache --progress=plain | ||
ARCH=arm64 | ||
# ARCH=amd64 | ||
|
||
# docker push $REGISTRY/$LOCAL_TAG | ||
WORKSPACE_PATH=etc/catkin_workspace | ||
CACHE_PATH=cache | ||
|
||
# initialize the cache | ||
mkdir -p ./${CACHE_PATH}/${WORKSPACE_PATH} | ||
|
||
# this first build compiles the contents of "src" and storest the intermediate | ||
# catkin workspace in ./cache | ||
docker build . --target stage_cache_workspace --output ./${CACHE_PATH} --build-arg WORKSPACE_PATH=${WORKSPACE_PATH} --file Dockerfile --platform=linux/arm64 | ||
|
||
# this second build takes the resulting workspace and storest in in a final image | ||
# that can be deployed to a drone | ||
docker build . --target stage_finalization --file Dockerfile --build-arg WORKSPACE_PATH=${WORKSPACE_PATH} --tag $LOCAL_TAG --platform=linux/arm64 |
This file was deleted.
Oops, something went wrong.