多环境jar部署脚本示例
多环境
方法传参
错误处理
容器相关处理
提示信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| #!/bin/bash
function check() { if [[ "$1" != "prod" && "$1" != "stage" && "$1" != "qa" && "$1" != "jzs" ]]; then echo -e "\r\nUsage: sh run.sh $2 qa|stage|prod|jzs"; exit; fi }
function error_exit { echo "$1" 1>&2 exit 1 }
function stop() { check $1 stop; (docker stop $1 && echo "stop $1 success") || echo "stop $1 error"; }
function remove() { check $1 remove; (docker rm $1 && echo "remove $1 success") || echo "remove $1 error"; }
function build() { if [[ "$1" = "prod" || "$1" = "jzs" ]]; then buildWithMaven; else buildWithMavenWrapper; fi }
function buildWithMaven() { (mvn clean install dockerfile:build && echo "build success") || error_exit "build error"; }
function buildWithMavenWrapper() { chmod 777 ./mvnw; (./mvnw clean install dockerfile:build && echo "build success") || error_exit "build error"; }
function start() { check $1 start; docker run --name $1 \ -e "SPRING_PROFILES_ACTIVE=$1" \ -d \ -p $2:$2 \ -v /var/log/hongfund/$1:/var/log/hongfund/$1 \ -e TZ=Asia/Shanghai \ hongfund/efi }
function clean() { (docker rmi $(docker images -aq -f "dangling=true") && echo "clean success") || echo "clean error" }
function qa() { stop qa; remove qa; build qa; start qa 8088; clean; }
function stage() { stop stage; remove stage; build stage; start stage 8089; clean; }
function prod() { stop prod; remove prod; build prod; start prod 8089; clean; }
function jzs() { stop jzs; remove jzs; build jzs; start jzs 8090; clean; }
function show_help() { echo -e "\r\n\t欢迎使用hongfund" echo -e "\r\nUsage: sh run.sh stop|remove|build|start|qa|stage|prod|jzs" exit; }
function main() { Command=$1 case "${Command}" in stop) stop "$2" ;; remove) remove "$2" ;; build) build "$2" ;; start) start "$2" "$3" ;; qa) qa ;; stage) stage ;; prod) prod ;; jzs) jzs ;; clean) clean ;; *) show_help ;; esac } main "$@"
|