This is an automated email from the ASF dual-hosted git repository.

aw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yetus.git


The following commit(s) were added to refs/heads/master by this push:
     new fa965c5  YETUS-799. Use real paths in docker container
fa965c5 is described below

commit fa965c53cb05e2b382d62cdabebc6fd96c645f49
Author: Allen Wittenauer <a...@apache.org>
AuthorDate: Mon Mar 18 10:58:49 2019 -0700

    YETUS-799. Use real paths in docker container
    
    Signed-off-by: Allen Wittenauer <a...@apache.org>
---
 precommit/src/main/shell/core.d/builtin-bugsystem.sh   |  4 ++--
 precommit/src/main/shell/core.d/docker.sh              | 18 +++++++++++++-----
 .../shell/test-patch-docker/Dockerfile.patchspecific   | 16 +++++++++-------
 .../main/shell/test-patch-docker/launch-test-patch.sh  |  8 ++++----
 precommit/src/main/shell/test-patch.d/briefreport.sh   |  4 ++--
 precommit/src/main/shell/test-patch.d/htmlout.sh       |  4 ++--
 6 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/precommit/src/main/shell/core.d/builtin-bugsystem.sh 
b/precommit/src/main/shell/core.d/builtin-bugsystem.sh
index 76ed02c..9ed531d 100755
--- a/precommit/src/main/shell/core.d/builtin-bugsystem.sh
+++ b/precommit/src/main/shell/core.d/builtin-bugsystem.sh
@@ -180,7 +180,7 @@ function console_finalreport
 function console_docker_support
 {
   if [[ -n "${CONSOLE_REPORT_FILE}" ]]; then
-    DOCKER_EXTRAARGS+=("-v" "${CONSOLE_REPORT_FILE}:/testptch/console.txt")
-    USER_PARAMS+=("--console-report-file=/testptch/console.txt")
+    DOCKER_EXTRAARGS+=("-v" 
"${CONSOLE_REPORT_FILE}:${DOCKER_WORK_DIR}/console.txt")
+    USER_PARAMS+=("--console-report-file=${DOCKER_WORK_DIR}/console.txt")
   fi
 }
diff --git a/precommit/src/main/shell/core.d/docker.sh 
b/precommit/src/main/shell/core.d/docker.sh
index d66acdb..57c826d 100755
--- a/precommit/src/main/shell/core.d/docker.sh
+++ b/precommit/src/main/shell/core.d/docker.sh
@@ -28,6 +28,7 @@ DOCKER_TAG=""
 DOCKER_IN_DOCKER=false
 DOCKER_SOCKET="/var/run/docker.sock"
 DOCKER_SOCKET_GID=-1
+DOCKER_WORK_DIR="/precommit"
 
 declare -a DOCKER_EXTRAARGS
 declare -a DOCKER_VERSION
@@ -69,6 +70,7 @@ function docker_usage
     yetus_add_option "--dockerprivd=<bool>" "Run docker in privileged mode 
(default: '${DOCKER_ENABLE_PRIVILEGED}')"
     yetus_add_option "--docker-socket=<socket>" "Mount given socket as 
/var/run/docker.sock into the container when Docker-in-Docker mode is enabled 
(default: '${DOCKER_SOCKET}')"
     yetus_add_option "--docker-tag=<tag>" "Use the given Docker tag as the 
base"
+    yetus_add_option "--docker-work-dir=<directory>" "Disposable, safe dir for 
precommit work (default: ${DOCKER_WORK_DIR}"
   fi
   yetus_add_option "--dockerdelrep" "In Docker mode, only report 
image/container deletions, not act on them"
   if [[ "${DOCKER_CLEANUP_CMD}" == false ]]; then
@@ -128,6 +130,9 @@ function docker_parse_args
       --docker-tag=*)
         DOCKER_TAG=${i#*=}
       ;;
+      --docker-work-dir=*)
+        DOCKER_TAG=${i#*=}
+      ;;
     esac
   done
 }
@@ -709,6 +714,8 @@ function docker_run_image
     fi
   done
 
+  add_docker_env DOCKER_WORK_DIR
+
   # using the base image, make one that is patch specific
   dockercmd build \
     "${dockplat[@]}" \
@@ -718,6 +725,7 @@ function docker_run_image
     --build-arg USER_ID="${USER_ID}" \
     --build-arg USER_NAME="${USER_NAME}" \
     --build-arg DOCKER_SOCKET_GID="${DOCKER_SOCKET_GID}" \
+    --build-arg DOCKER_WORK_DIR="${DOCKER_WORK_DIR}" \
     --label org.apache.yetus=\"\" \
     --label org.apache.yetus.testpatch.patch="tp-${DOCKER_ID}" \
     --label org.apache.yetus.testpatch.project="${PROJECT_NAME}" \
@@ -766,10 +774,10 @@ function docker_run_image
     fi
   fi
 
-  DOCKER_EXTRAARGS+=(-v "${PWD}:/testptch/${PROJECT_NAME}")
+  DOCKER_EXTRAARGS+=(-v "${BASEDIR}:${BASEDIR}")
   DOCKER_EXTRAARGS+=(-u "${USER_NAME}")
-  DOCKER_EXTRAARGS+=(-w "/testptch/${PROJECT_NAME}")
-  DOCKER_EXTRAARGS+=("--env=BASEDIR=/testptch/${PROJECT_NAME}")
+  DOCKER_EXTRAARGS+=(-w "${BASEDIR}")
+  DOCKER_EXTRAARGS+=("--env=BASEDIR=${BASEDIR}")
   DOCKER_EXTRAARGS+=("--env=DOCKER_VERSION_STR=${dockerversion}")
 
   docker_do_env_adds
@@ -782,8 +790,8 @@ function docker_run_image
     dockercmd run --rm=true -i \
       "${dockplat[@]}" \
       "${DOCKER_EXTRAARGS[@]}" \
-      -v "${PATCH_DIR}:/testptch/patchprocess" \
-      --env=PATCH_DIR=/testptch/patchprocess \
+      -v "${PATCH_DIR}:${PATCH_DIR}" \
+      --env=PATCH_DIR="${PATCH_DIR}" \
       "${patchimagename}" &
   else
     dockercmd run --rm=true -i \
diff --git 
a/precommit/src/main/shell/test-patch-docker/Dockerfile.patchspecific 
b/precommit/src/main/shell/test-patch-docker/Dockerfile.patchspecific
index 974acea..18a2007 100644
--- a/precommit/src/main/shell/test-patch-docker/Dockerfile.patchspecific
+++ b/precommit/src/main/shell/test-patch-docker/Dockerfile.patchspecific
@@ -24,6 +24,7 @@ ARG USER_NAME
 ARG GROUP_ID
 ARG USER_ID
 ARG DOCKER_SOCKET_GID
+ARG DOCKER_WORK_DIR
 
 RUN groupadd --non-unique -g "${GROUP_ID}" "${USER_NAME}" || true
 RUN useradd -g "${GROUP_ID}" -u "${USER_ID}" -m "${USER_NAME}" || true
@@ -32,13 +33,14 @@ RUN useradd -g "${GROUP_ID}" -u "${USER_ID}" -m 
"${USER_NAME}" || true
 
 RUN if [ "${DOCKER_SOCKET_GID}" != -1 ]; then (groupadd --non-unique --gid 
${DOCKER_SOCKET_GID} dockersock && adduser "${USER_NAME}" dockersock ) || true; 
fi
 
-RUN mkdir -p /testptch/extras
-RUN chmod a+rwx /testptch/extras
-COPY user_params.txt /testptch/user_params.txt
-COPY launch-test-patch.sh /testptch/launch-test-patch.sh
-RUN chown -R "${USER_NAME}":"${GROUP_ID}" /testptch || true
-RUN chmod a+rx /testptch/launch-test-patch.sh
+RUN mkdir -p ${DOCKER_WORK_DIR}/extras
+RUN chmod a+rwx ${DOCKER_WORK_DIR}/extras
+COPY user_params.txt ${DOCKER_WORK_DIR}/user_params.txt
+COPY launch-test-patch.sh /launch-test-patch.sh
+RUN chown -R "${USER_NAME}":"${GROUP_ID}" ${DOCKER_WORK_DIR} 
/launch-test-patch.sh || true
+RUN chmod a+rx /launch-test-patch.sh
 RUN chown -R "${USER_NAME}" "/home/${USER_NAME}" || true
 ENV HOME "/home/${USER_NAME}"
 USER ${USER_NAME}
-CMD ["/testptch/launch-test-patch.sh"]
\ No newline at end of file
+ENV DOCKER_WORK_DIR ${DOCKER_WORK_DIR}
+CMD ["/launch-test-patch.sh"]
\ No newline at end of file
diff --git a/precommit/src/main/shell/test-patch-docker/launch-test-patch.sh 
b/precommit/src/main/shell/test-patch-docker/launch-test-patch.sh
index 70e0993..e5b9f58 100755
--- a/precommit/src/main/shell/test-patch-docker/launch-test-patch.sh
+++ b/precommit/src/main/shell/test-patch-docker/launch-test-patch.sh
@@ -22,13 +22,13 @@ declare -a OVERWRITEARGS
 #shellcheck disable=SC1090
 source "${PATCH_DIR}/precommit/core.d/00-yetuslib.sh"
 
-if ! yetus_file_to_array OVERWRITEARGS /testptch/user_params.txt; then
+if ! yetus_file_to_array OVERWRITEARGS "${DOCKER_WORK_DIR}/user_params.txt"; 
then
   yetus_error "ERROR: Cannot read user parameters file. Exiting."
   exit 1
 fi
 
 # do not want this archived
-rm -f /testptch/user_params.txt
+rm -f "${DOCKER_WORK_DIR}/user_params.txt"
 
 OVERWRITEARGS+=("--reexec")
 OVERWRITEARGS+=("--dockermode")
@@ -67,8 +67,8 @@ fi
 # system.  So we need to rescue it and then tell
 # test-patch where to find it.
 if [[ "${PATCH_SYSTEM}" = generic ]]; then
-  cp -p "${PATCH_DIR}/patch" /testptch/extras/patch
-  OVERWRITEARGS+=("/testptch/extras/patch")
+  cp -p "${PATCH_DIR}/patch" "${DOCKER_WORK_DIR}/extras/patch"
+  OVERWRITEARGS+=("${DOCKER_WORK_DIR}/extras/patch")
 fi
 
 cd "${PATCH_DIR}/precommit/" || exit 1
diff --git a/precommit/src/main/shell/test-patch.d/briefreport.sh 
b/precommit/src/main/shell/test-patch.d/briefreport.sh
index 2554edb..a764389 100755
--- a/precommit/src/main/shell/test-patch.d/briefreport.sh
+++ b/precommit/src/main/shell/test-patch.d/briefreport.sh
@@ -69,8 +69,8 @@ function briefreport_parse_args
 function briefreport_docker_support
 {
   if [[ -n ${BRIEFOUT_REPORTFILE} ]]; then
-    DOCKER_EXTRAARGS+=("-v" "${BRIEFOUT_REPORTFILE}:/testptch/brief.txt")
-    USER_PARAMS+=("--brief-report-file=/testptch/brief.txt")
+    DOCKER_EXTRAARGS+=("-v" 
"${BRIEFOUT_REPORTFILE}:${DOCKER_WORK_DIR}/brief.txt")
+    USER_PARAMS+=("--brief-report-file=${DOCKER_WORK_DIR}/brief.txt")
   fi
 }
 
diff --git a/precommit/src/main/shell/test-patch.d/htmlout.sh 
b/precommit/src/main/shell/test-patch.d/htmlout.sh
index 9660001..fc896f4 100755
--- a/precommit/src/main/shell/test-patch.d/htmlout.sh
+++ b/precommit/src/main/shell/test-patch.d/htmlout.sh
@@ -59,8 +59,8 @@ function htmlout_parse_args
 function htmlout_docker_support
 {
   if [[ -n ${HTMLOUT_REPORTFILE} ]]; then
-    DOCKER_EXTRAARGS+=("-v" "${HTMLOUT_REPORTFILE}:/testptch/report.htm")
-    USER_PARAMS+=("--html-report-file=/testptch/report.htm")
+    DOCKER_EXTRAARGS+=("-v" 
"${HTMLOUT_REPORTFILE}:${DOCKER_WORK_DIR}/report.htm")
+    USER_PARAMS+=("--html-report-file=${DOCKER_WORK_DIR}/report.htm")
   fi
 }
 

Reply via email to