From 06bd437f94e196a763da543d7a28c3579b756713 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=B5=9C=ED=98=95=EA=B7=9C/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Senior=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Fri, 20 Apr 2018 09:22:43 +0900 Subject: [PATCH] Add CI script (#31) Add a command to build using docker for CI and local build * Using docker image `nncc` as default * Make use of NNCC_PROJECT_PATH * Use double quotes to prevent possible issues from space * Update comments and variable names to fit for nncc Signed-off-by: Hyung-Kyu Choi --- scripts/command/docker-build | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 scripts/command/docker-build diff --git a/scripts/command/docker-build b/scripts/command/docker-build new file mode 100755 index 0000000..8e463a2 --- /dev/null +++ b/scripts/command/docker-build @@ -0,0 +1,50 @@ +#!/bin/bash + +DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME:-nncc} +echo "Using docker image $DOCKER_IMAGE_NAME" + +if [ -z "`docker images | grep $DOCKER_IMAGE_NAME`" ]; then + echo "Need docker image!" + exit 1 +fi + +HOST_PATH="$NNCC_PROJECT_PATH" +DOCKER_PATH=/home/nncc + +export GIT_SSL_NO_VERIFY=1 + +DOCKER_VOLUMES=" -v $HOST_PATH:$DOCKER_PATH" + +DOCKER_ENV_VARS+=" -e http_proxy" +DOCKER_ENV_VARS+=" -e no_proxy" +DOCKER_ENV_VARS+=" -e GIT_SSL_NO_VERIFY" + +DOCKER_RUN_OPTS="--rm" +DOCKER_RUN_OPTS+=" -w $DOCKER_PATH" + +if [ "$DOCKER_INTERACTIVE" ]; then + DOCKER_RUN_OPTS+=" -it" + CMD="/bin/bash" + docker run $DOCKER_RUN_OPTS $DOCKER_ENV_VARS $DOCKER_VOLUMES $DOCKER_IMAGE_NAME $CMD +else + CMD="./nncc configure" + docker run $DOCKER_RUN_OPTS $DOCKER_ENV_VARS $DOCKER_VOLUMES $DOCKER_IMAGE_NAME $CMD + + CMD="./nncc build" + docker run $DOCKER_RUN_OPTS $DOCKER_ENV_VARS $DOCKER_VOLUMES $DOCKER_IMAGE_NAME $CMD +fi + +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 nncc to owner of nncc. +NNCC_OWNER_UID=$(stat -c "%u" $HOST_PATH) +NNCC_OWNER_GID=$(stat -c "%g" $HOST_PATH) + +CMD="chown -R $NNCC_OWNER_UID:$NNCC_OWNER_GID $DOCKER_PATH" +docker run $DOCKER_RUN_OPTS $DOCKER_ENV_VARS $DOCKER_VOLUMES $DOCKER_IMAGE_NAME $CMD + +exit $BUILD_RESULT -- 2.7.4