Browse Source

add pushToRemote.sh.sh

krrish 7 years ago
parent
commit
c0b921b499
2 changed files with 106 additions and 10 deletions
  1. 69 0
      build/pushToRemote.sh.sh
  2. 37 10
      deploy/deploy_latest.sh

+ 69 - 0
build/pushToRemote.sh.sh

@@ -0,0 +1,69 @@
+#!/bin/bash
+
+# check input
+if [ -z "$1" ]; then
+    echo "*****************************************************************"
+    echo 
+    echo "  Please input image like below:"
+    echo "  registry.svicloud.com/powercloud/oms/server:V01R01B18-3043"
+    echo
+    echo "*****************************************************************"
+    echo 
+    exit 1
+fi
+
+# if has another process
+retry=30
+while true; do
+    ps_count=`ps -ef | grep -v grep | grep ${0#./*} | wc -l`
+    retry_count=`expr $retry_count + 1`
+
+    # 30 times
+    if [ "$retry_count" -ge $retry ]; then
+        echo "timeout after 90 seconds, exit."
+        echo 
+        exit 1
+    fi
+
+    # has other process
+    if [ $ps_count -ge 3 ] ; then
+        echo "another process \"${0#./*}\" is running, retry after 3 seconds."
+        sleep 3
+    else
+        break
+    fi
+
+done
+
+# make a host entry
+if ! grep -q "registry.svicloud.com" /etc/hosts; then
+    echo "151.106.8.135 registry.svicloud.com" >>/etc/hosts
+fi
+
+# comment to use local repo
+sed -i "/^[^#].*registry.svicloud.com/s/^/#/" /etc/hosts
+
+# login local repo
+docker login -u admin -p Changeme_123 registry.svicloud.com &>/dev/null || \
+  { echo "docker login to local repo failed" && echo && exit 1; } 
+
+# pull the image
+if docker pull $1; then
+    sed -i "/^[#].*registry.svicloud.com/s/^#//" /etc/hosts
+    sleep 2
+    docker login -u admin -p "Gocm5]WeqaSufg" registry.svicloud.com &>/dev/null || \
+      { echo "docker login to remote repo failed" && echo && exit 1; } 
+    echo
+    if docker push $1; then
+        echo "push success"
+    else
+        echo "push $1 to remote repo failed"
+        echo 
+        exit 1
+    fi
+else
+    echo "pull local image $1 to local server failed"
+    echo 
+    exit 1
+fi
+    

+ 37 - 10
deploy/deploy_latest.sh

@@ -1,11 +1,11 @@
 #!/bin/bash
 # Usage:
-# deploy all(skip installed stack):     ./$1
-# deploy & upgrade:                     ./$1 --upgrade
-# deploy force(rm stack, then deploy)   ./$1 --force
-# deploy specify app:                   ./$1 --module="modle1,module2,module3"
-# deploy to specify env:                ./$1 --env="test"
-
+# deploy all(skip installed stack):                     ./$1
+# deploy & upgrade:                                     ./$1 --upgrade
+# deploy force(rm stack, then deploy)                   ./$1 --force
+# deploy specify app:                                   ./$1 --module="modle1,module2,module3"
+# deploy to specify env:                                ./$1 --env="test"
+# deploy with specify git branch, default master        ./$1 --git-branch="dev"
 
 
 # deploy base dir
@@ -35,7 +35,7 @@ cat <<'EOF'
 EOF
 # if no select, use defult
 [ -n "$DEPLOY_APP" ] && APP=$DEPLOY_APP && \
-      echo "start to deploy app: $APP" && echo
+  echo "start to deploy app: $APP" && echo
 
 
 # git address
@@ -52,13 +52,40 @@ if [ -d ${WORKDIR}/wisecloud-catalog/.git ]; then
     git --no-pager log  --graph \
     --pretty=format:'%h - %d% %s (%cr [%an])' \
     --abbrev-commit --date=relative  -20
-    echo;echo
-    git fetch --all
-    git reset --hard origin/master
+    echo
 else
     git clone $GIT_TEMPLATE_URL ${WORKDIR}/wisecloud-catalog
+    cd ${WORKDIR}/wisecloud-catalog
+fi
+
+# fetch remote tags 
+git fetch --all
+
+GIT_BRANCH=`echo $* | xargs -n 1 | grep "\-git\-branch" | awk -F"=" '{print $2}' | tr ',' ' '`
+GIT_BRANCH=${GIT_BRANCH:-master}
+
+# has branch
+if git branch -a | grep -wq "${GIT_BRANCH}"; then
+
+    # if current branch not the wanted, checkout it
+    current_branch=`git branch | grep "\*" | awk '{print $2}'`
+    if [ "${GIT_BRANCH}" != "${current_branch}" ]; then
+        # checkout 
+        git checkout -b ${GIT_BRANCH}
+    fi
+    
+    # reset hard the branch
+    git reset --hard origin/${GIT_BRANCH}
+    
+# no branch
+else
+    echo "#####################################"
+    echo "Please specify the right \"--git-branch\", exit!"
+    echo "#####################################"
+    exit 1
 fi
 
+
 ENV=`echo $* | xargs -n 1 | grep "\-env" | awk -F"=" '{print $2}' | tr ',' ' '`
 echo "deploy to env=$ENV"
 if [ "$ENV" == "powercloudtest" ]; then