|
@@ -1,9 +1,9 @@
|
|
|
#!/bin/bash
|
|
|
# Usage:
|
|
|
# deploy with upgrade: --upgrade, DO NOT USE
|
|
|
-# deploy force(rm stack, then deploy) --force (±ØÌî)
|
|
|
-# deploy specify app: --module="ems_server" (±ØÌî)
|
|
|
-# deploy to specify env: --env="powercloud" (±ØÌî)
|
|
|
+# deploy force(rm stack, then deploy) --force (å¿…å¡«)
|
|
|
+# deploy specify app: --module="ems_server" (å¿…å¡«)
|
|
|
+# deploy to specify env: --env="powercloud" (å¿…å¡«)
|
|
|
# deploy with specify git branch, default master --git-branch="dev"
|
|
|
# deploy with specify version, default 0 --compose_version=1
|
|
|
|
|
@@ -60,7 +60,7 @@ fi
|
|
|
# fetch remote tags
|
|
|
git fetch --all
|
|
|
|
|
|
-GIT_BRANCH=`echo $* | xargs -n 1 | grep "\-git\-branch" | awk -F"=" '{print $2}' | tr ',' ' '`
|
|
|
+GIT_BRANCH=`echo $* | xargs -n 1 | grep "\-git\-branch" | awk -F"=" '{print $2}' | tr ',' ' ' | xargs`
|
|
|
GIT_BRANCH=${GIT_BRANCH:-master}
|
|
|
|
|
|
# has branch
|
|
@@ -68,9 +68,10 @@ 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} &>/dev/null
|
|
|
+ git checkout -b ${GIT_BRANCH}
|
|
|
fi
|
|
|
|
|
|
# reset hard the branch
|
|
@@ -79,6 +80,7 @@ if git branch -a | grep -wq "${GIT_BRANCH}"; then
|
|
|
# no branch
|
|
|
else
|
|
|
echo "#####################################"
|
|
|
+ echo "You define the --git-branch=$GIT_BRANCH"
|
|
|
echo "Please specify the right \"--git-branch\", exit!"
|
|
|
echo "#####################################"
|
|
|
exit 1
|
|
@@ -87,7 +89,13 @@ fi
|
|
|
|
|
|
ENV=`echo $* | xargs -n 1 | grep "\-env" | awk -F"=" '{print $2}' | tr ',' ' '`
|
|
|
echo "deploy to env=$ENV"
|
|
|
-if [ "$ENV" == "cs" ]; then
|
|
|
+if [ "$ENV" == "powercloudtest" ]; then
|
|
|
+ RANCHER_ACCESS_KEY=0CA5094E8E4562442D99
|
|
|
+ RANCHER_SECRET_KEY=7TH5j64DSUPFbf6b9cFr4mp7Brq5iUrPBSx6sJxM
|
|
|
+elif [ "$ENV" == "test" ]; then
|
|
|
+ RANCHER_ACCESS_KEY=C98222E5206624BFB807
|
|
|
+ RANCHER_SECRET_KEY=LBg2tF96miU8rBPgN2kR9uXV2qbrKKuQTrTEy5Wq
|
|
|
+elif [ "$ENV" == "cs" ]; then
|
|
|
RANCHER_ACCESS_KEY=344E9FA150DD81B6F254
|
|
|
RANCHER_SECRET_KEY=9tBspbMqp3ny8ZzXbBBTpYNke5fhgLPWfXyvqqTi
|
|
|
|
|
@@ -128,7 +136,7 @@ for module in $APP; do
|
|
|
# if has another process
|
|
|
retry=100
|
|
|
while true; do
|
|
|
- ps_count=`ps -ef | grep "deploy_latest" | grep -q "$module" | wc -l`
|
|
|
+ ps_count=`ps -ef | grep "deploy_latest" | grep "$module" | wc -l`
|
|
|
retry_count=`expr $retry_count + 1`
|
|
|
|
|
|
# 100 times
|
|
@@ -140,13 +148,15 @@ for module in $APP; do
|
|
|
# has other process
|
|
|
if [ $ps_count -ge 2 ] ; then
|
|
|
echo "another process \"$module\" is running, waiting."
|
|
|
- sleep 1
|
|
|
+ sleep 2
|
|
|
+
|
|
|
else
|
|
|
break
|
|
|
fi
|
|
|
|
|
|
done
|
|
|
# prepare the sub dir
|
|
|
+ echo "work directory: $WORKDIR/$module"
|
|
|
mkdir -p $WORKDIR/$module
|
|
|
cd $WORKDIR/$module
|
|
|
|
|
@@ -172,6 +182,7 @@ for module in $APP; do
|
|
|
else
|
|
|
compose_version_number=$COMPOSE_VERSION
|
|
|
fi
|
|
|
+
|
|
|
if ! cd ${WORKDIR}/wisecloud-catalog/templates/$module/${compose_version_number}; then
|
|
|
echo " Maybe you have input the wrong compose_version"
|
|
|
exit 1
|
|
@@ -205,13 +216,16 @@ for module in $APP; do
|
|
|
fi
|
|
|
|
|
|
# rancher-compose pull image
|
|
|
+ echo "pulling the latest image..."
|
|
|
rancher-compose -p ${module} $ENV_ARGS pull
|
|
|
-
|
|
|
+ sleep 5
|
|
|
+ echo "ok, finish pulling the latest image..."
|
|
|
+
|
|
|
# compose up
|
|
|
if echo "$*" | grep -q "\-force"; then
|
|
|
- echo "removing $module..."
|
|
|
+ echo; echo "removing $module..."
|
|
|
rancher-compose -p ${module} $ENV_ARGS rm -f
|
|
|
- sleep 1
|
|
|
+ sleep 2
|
|
|
# try again
|
|
|
rancher-compose -p ${module} $ENV_ARGS rm -f 2>/dev/null
|
|
|
sleep 3
|
|
@@ -244,7 +258,14 @@ for module in $APP; do
|
|
|
fi
|
|
|
fi
|
|
|
|
|
|
-
|
|
|
+
|
|
|
done
|
|
|
-
|
|
|
-
|
|
|
+cat <<'EOF'
|
|
|
+ _ _ _
|
|
|
+ __| | ___ _ __ | | ___ _ _ __| | ___ _ __ ___
|
|
|
+ / _` |/ _ \ '_ \| |/ _ \| | | | / _` |/ _ \| '_ \ / _ \
|
|
|
+| (_| | __/ |_) | | (_) | |_| | | (_| | (_) | | | | __/
|
|
|
+ \__,_|\___| .__/|_|\___/ \__, | \__,_|\___/|_| |_|\___|
|
|
|
+ |_| |___/
|
|
|
+
|
|
|
+EOF
|