Introduce a helper for scripts (#1183)
author최형규/동작제어Lab(SR)/Senior Engineer/삼성전자 <hk0110.choi@samsung.com>
Tue, 15 May 2018 03:48:06 +0000 (12:48 +0900)
committer서상민/동작제어Lab(SR)/Senior Engineer/삼성전자 <sangmin7.seo@samsung.com>
Tue, 15 May 2018 03:48:06 +0000 (12:48 +0900)
- Introduce docker_helper for scripts
- Apply docker_helper to docker_run_test.sh as a first use case
- Will apply docker_helper to other scripts later

Signed-off-by: Hyung-Kyu Choi <hk0110.choi@samsung.com>
scripts/command/docker_run_test.sh
scripts/docker_helper [new file with mode: 0644]

index 899820c..d877231 100755 (executable)
@@ -24,15 +24,7 @@ docker run $DOCKER_RUN_OPTS $DOCKER_ENV_VARS $DOCKER_VOLUMES $DOCKER_IMAGE_NAME
 
 BUILD_RESULT=$?
 
-# Newly created files during above docker run can have different ownership.
-# This may cause some problems, for example, some jenkins slaves or developers
-# can't remove built files due to lack of permission.
-# To address this issue, let's change owner of all files
-# in NPU_Compiler to owner of NPU_Compiler.
-NNFW_OWNER_UID=$(stat -c "%u" $HOST_HOME)
-NNFW_OWNER_GID=$(stat -c "%g" $HOST_HOME)
-
-CMD="chown -R $NNFW_OWNER_UID:$NNFW_OWNER_GID $DOCKER_HOME"
-docker run $DOCKER_RUN_OPTS $DOCKER_ENV_VARS $DOCKER_VOLUMES $DOCKER_IMAGE_NAME $CMD
+source $SCRIPT_ROOT/docker_helper
+restore_ownership $HOST_HOME $DOCKER_HOME
 
 exit $BUILD_RESULT
diff --git a/scripts/docker_helper b/scripts/docker_helper
new file mode 100644 (file)
index 0000000..37ec9fc
--- /dev/null
@@ -0,0 +1,33 @@
+# Newly created files during docker run can have different ownership.
+# This may cause some problems, for example, some jenkins slaves or developers
+# can't remove built files due to lack of permission.
+# To address this issue, let's change owner of all files and subdirector
+# to owner of host directory.
+#
+# Parameters:
+#  $1 : host directory
+#  $2 : docker directory
+#
+# Requires following variables defined
+#   DOCKER_RUN_OPTS, DOCKER_ENV_VARS, DOCKER_VOLUMES, DOCKER_IMAGE_NAME 
+function restore_ownership() {
+    if [ -z "$1" ]
+    then
+        echo "Requires host path"
+        exit 1
+    fi
+    _HOST_DIR=$1
+
+    if [ -z "$2" ]
+    then
+        echo "Requires docker path"
+        exit 1
+    fi
+
+    _DOCKER_DIR=$2
+
+    _OWNER_UID=$(stat -c "%u" $_HOST_DIR)
+    _OWNER_GID=$(stat -c "%g" $_HOST_DIR)
+    CMD="chown -R $_OWNER_UID:$_OWNER_GID $_DOCKER_DIR"
+    docker run $DOCKER_RUN_OPTS $DOCKER_ENV_VARS $DOCKER_VOLUMES $DOCKER_IMAGE_NAME $CMD
+}