@@ -3,15 +3,9 @@ ARG BASE_IMAGE
33ARG BASE_IMAGE_TAG
44FROM ${BASE_IMAGE:?err}:${BASE_IMAGE_TAG:?err} AS package-project-src-code
55
6- ARG DN_PROJECT_DEPLOY_REPO_BRANCH
7- ENV DN_PROJECT_DEPLOY_REPO_BRANCH=${DN_PROJECT_DEPLOY_REPO_BRANCH:?'Build argument needs to be set and non-empty.' }
8-
96ENV DN_PROJECT_SERVICE=project-deploy
107ENV DN_PROJECT_SERVICE_DIR=/dockerized-norlab/project/${DN_PROJECT_SERVICE}
118
12- ARG BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
13- ARG DN_DEV_TESTS=${DN_DEV_TESTS:-false}
14-
159RUN <<EOF
1610 n2st::print_msg "Pre-condition checks..."
1711 {
@@ -25,7 +19,6 @@ RUN <<EOF
2519 test -d ${DN_DEV_WORKSPACE} && \
2620 test -n ${DN_PROJECT_GIT_NAME:?'Env variable need to be set and non-empty.' } && \
2721 test -n ${DN_PROJECT_GIT_DOMAIN:?'Env variable need to be set and non-empty.' } && \
28- test -n ${DN_PROJECT_DEPLOY_REPO_BRANCH:?'Env variable need to be set and non-empty.' } && \
2922 test -n "${DEBIAN_FRONTEND:?'Env variable need to be set and non-empty.'}" && \
3023 [[ "${DEBIAN_FRONTEND}" == "noninteractive" ]];
3124 } || n2st::print_msg_error_and_exit "Failed pre-condition checks!"
@@ -36,139 +29,25 @@ RUN echo "(WARNING) PYTHONUNBUFFERED env variable will be set to 0 for deploymen
3629# Note: Set python to NOT print stdin/sderr in real-time as it affect overall performances
3730ENV PYTHONUNBUFFERED=0
3831
39- # ....Clone or checkout project src code...........................................................
40- # Implementation note: Copying the repository in the container and then checkout is safer for case
41- # where the repository is private. It circumvents the problematic of leaked secret that can persist
42- # in build history and cached layer. Since the repository is already cloned on the host machine
43- # whether it's a personal computer, a robot or a CI server its safer and easier to manage to
44- # delegate the responsibility of secret management to the user.
32+ # ....Clone project src code.......................................................................
33+ ARG BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
4534WORKDIR "${DN_DEV_WORKSPACE}/src"
4635COPY --from=context-dn-project-local-src-path . ${DN_PROJECT_GIT_NAME}
47- # COPY --chown=${DN_PROJECT_USER} --from=context-dn-project-local-src-path . ${DN_PROJECT_GIT_NAME}
4836
4937WORKDIR ${DN_PROJECT_PATH}
5038
5139# Dev note:
5240# - DN_DEV_WORKSPACE: /ros2_ws/src
5341# - DN_PROJECT_PATH: /ros2_ws/src/dockerized-norlab-project-mock
5442RUN <<EOF
55- # ....Debug information (pre-checkout) .........................................................
56- n2st::print_msg "Debug information (pre-checkout) "
43+ # ....Debug information .............. .........................................................
44+ n2st::print_msg "Debug information"
5745 tree -L 2 -a "${DN_DEV_WORKSPACE}/src"
5846 echo
5947 tree -L 3 -a "${DN_PROJECT_PATH}"
6048 echo
61- echo -e "\n cat ${DN_PROJECT_PATH}/.git"
62- cat ${DN_PROJECT_PATH}/.git
63- echo
64- tree -L 2 -a ${DN_PROJECT_PATH}/.git
65-
66- if [[ "${DN_DEV_TESTS}" == "true" ]]; then
67- n2st::print_msg "Development test to validate that the setup for testing git checkout operation is ok (pre)."
68- test "${DN_PROJECT_GIT_NAME}" == "dockerized-norlab-project-mock" || n2st::print_msg_error_and_exit "${DN_PROJECT_GIT_NAME} != dockerized-norlab-project-mock"
69- test "${DN_PROJECT_DEPLOY_REPO_BRANCH}" == "dev" || n2st::print_msg_error_and_exit "${DN_PROJECT_DEPLOY_REPO_BRANCH} != dev"
70- test "$(git branch --show-current)" == "main" || n2st::print_msg_error_and_exit "$(git branch --show-current) != main"
71- test ! -f "src/mock_file.txt" || n2st::print_msg_error_and_exit "mock_file.txt should only exist on the dev branch" # ToDo: TNP-47 fix: mock repo dev branch missing file
72- echo
73- tree -L 2 -a -hug "${DN_PROJECT_PATH}"
74- echo
75- else
76- # ....Sanity check (pre)...................................................................
77- test "$( basename $( git remote get-url origin ) .git )" == "${DN_PROJECT_GIT_NAME}" || n2st::print_msg_error_and_exit "'git remote get-url origin' should point to ${DN_PROJECT_GIT_NAME} but it point to '$( git remote get-url origin )'"
78- test "$( basename $( git rev-parse --show-toplevel ) )" == "${DN_PROJECT_GIT_NAME}" || n2st::print_msg_error_and_exit "'git rev-parse --show-toplevel' should point to ${DN_PROJECT_GIT_NAME} but it point to '$( git rev-parse --show-toplevel )'"
79- fi
80-
81- EOF
82-
83- RUN <<EOF
84- # ....Checkout.................................................................................
85- n2st::print_msg "git status"
86- git status || exit 1
87-
88- n2st::print_msg "List repository branches local and remote"
89- git branch --list --all || exit 1
90-
91- n2st::print_msg "List repository tags"
92- git tag --list || exit 1
93-
94- n2st::print_msg "Checking out branch ${DN_PROJECT_DEPLOY_REPO_BRANCH}"
95- git checkout "${DN_PROJECT_DEPLOY_REPO_BRANCH}" || exit 1
96-
97- n2st::print_msg_warning "Note on git checkout faillure: If you experience problem checking out a tag, use prefix 'tags/<my-tags-name>'
98- e.g.: DN_PROJECT_DEPLOY_REPO_BRANCH=\" tags/v0.0.1\" in your .dockerized_norlab_project/configuration/.env file"
99-
100- EOF
101-
102- RUN <<EOF
103-
104- # ....Debug information (post-checkout)........................................................
105- n2st::print_msg "Debug information (post-checkout)"
106- tree -L 2 -aug "${DN_PROJECT_PATH}"
107-
108- if [[ "${DN_DEV_TESTS}" == "true" ]]; then
109- n2st::print_msg "Development test to validate that the setup for testing git checkout operation is ok (post)."
110- test "$(git branch --show-current)" == "dev" || n2st::print_msg_error_and_exit "$(git branch --show-current) != dev"
111- test -f "src/mock_file.txt" || n2st::print_msg_error_and_exit "mock_file.txt should exist on the dev branch" # ToDo: TNP-47 fix: mock repo dev branch missing file
112- echo
113- tree -L 2 -a -hug "${DN_PROJECT_PATH}"
114- echo
115- else
116- # ....Sanity check (post)..................................................................
117- test "$(git branch --show-current)" == "${DN_PROJECT_DEPLOY_REPO_BRANCH}" || n2st::print_msg_error_and_exit "$(git branch --show-current) != " ${DN_PROJECT_DEPLOY_REPO_BRANCH}""
118- fi
119-
12049EOF
12150
122- # ToDo: validate "dna build deploy" works ok >> on task end >> delete next bloc ↓↓
123- # # ....Project specific ROS setup..................................................................
124- # WORKDIR ${DN_DEV_WORKSPACE}
125- # ARG TARGETPLATFORM
126- # ARG BUILDPLATFORM
127- #
128- # RUN <<EOF
129- # apt-get update
130- #
131- # test -n "$( declare -f dn::source_ros2_underlay_only )" || { echo -e "\033[1;31m[DN error]\033[0m The DN lib is not loaded!" 1>&2 && exit 1; }
132- # dn::source_ros2_underlay_only || exit 1
133- #
134- # n2st::print_msg "Execute rosdep update..."
135- # rosdep update --rosdistro ${ROS_DISTRO} || n2st::print_msg_error_and_exit "Failed rosdep update!"
136- # rosdep fix-permissions
137- #
138- # n2st::print_msg "Execute rosdep install..."
139- # rosdep install \
140- # --ignore-packages-from-source \
141- # --from-path ./src \
142- # --rosdistro ${ROS_DISTRO} \
143- # -q \
144- # -y \
145- # || n2st::print_msg_error_and_exit "Failed rosdep install!"
146- #
147- # COLCON_FLAGS=()
148- # if [[ "${TARGETPLATFORM:?err}" != "${BUILDPLATFORM:?err}" ]]; then
149- # n2st::print_msg "Builder is running in architecture virtualisation"
150- # COLCON_FLAGS+=("--executor" "sequential")
151- # else
152- # n2st::print_msg "Builder is running on native architecture"
153- # COLCON_FLAGS+=("--symlink-install")
154- # fi
155- #
156- # COLCON_FLAGS+=(
157- # "--cmake-clean-cache"
158- # "--cmake-args" "-DCMAKE_BUILD_TYPE=Release"
159- # "--event-handlers" "console_direct+"
160- # )
161- # n2st::print_msg "COLCON_FLAGS=("${COLCON_FLAGS[*]}")"
162- #
163- # n2st::print_msg "Execute colcon build..."
164- # colcon build ${COLCON_FLAGS[@]} || n2st::print_msg_error_and_exit "Failed colcon build!"
165- #
166- # # ....Teardown.................................................................................
167- # apt-get autoremove --assume-yes
168- # apt-get clean
169- # rm -rf /var/lib/apt/lists/*
170- # EOF
171-
17251# ToDo: refactor project-develop/Dockerfile the project-specific-ros-setup stage as a standalone
17352# script that can be executed by project-deploy (ref task NMO-558)
17453
0 commit comments