Linux

shell自动发布脚本

2019-04-24  本文已影响0人  王勇1024
#!/bin/bash

function help_info ()
{
    echo "参数说明:
        -b:branch       git分支
        -e:environment  系统环境(prod:生成环境, dev:测试环境)
        -v:version      docker镜像版本号
        -h:help         帮助命令
        -U:update       强制更新maven快照包"
}

echo original parameters=[$*]
echo original OPTIND=[$OPTIND]
while getopts ":b:e:hU" opt
do
    case $opt in
        b)
            echo "this is -b option. OPTARG=[$OPTARG] OPTIND=[$OPTIND]"
            branch=$OPTARG
            ;;
        e)
            echo "this is -e option. OPTARG=[$OPTARG] OPTIND=[$OPTIND]"
            environment=$OPTARG
            ;;
        U)
            echo "this is -U option. OPTARG=[$OPTARG] OPTIND=[$OPTIND]"
            update=-U
            ;;
        h)
            help_info
            exit 0
            ;;
        ?)
            echo "无效的参数"
            help_info
            exit 1
            ;;
    esac
done

module_name=alpha-exptmgr

if [ "$branch" = "" ]
then
 branch=test
fi

if [ "$environment" = "" ]
then
 environment=dev
fi

if [ "$environment" = "prod" ]
then
    version=`date +%Y%m%d`
else
    version=latest
fi

echo "branch name:" ${branch}
echo "image version:" ${version}
echo "environment:" ${environment}
echo "update snapshot:" ${update}
# 切换分支
git checkout -b ${branch}
# 拉取代码
git pull origin ${branch}
# 编译
mvn clean package ${update} -Dmaven.test.skip=true
docker_version=test
sudo docker build -f docker/Dockerfile -t=docker2.yidian.com:5000/centos7/${module_name}-${environment}:${version} .
sudo docker push docker2.yidian.com:5000/centos7/${module_name}-${environment}:${version}
# 重启服务
curl -XPOST -HContent-Type:application/json  -d '{"force":"true"}' http://10.136.130.31:8080/v2/apps/alpha-test/${module_name}/restart

上一篇 下一篇

猜你喜欢

热点阅读