-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff
110 lines (90 loc) · 3.11 KB
/
diff
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
#!/bin/bash
###############################################################################
# Project: hi-cli
# Description: The cross platform development toolkit - hi-cli
# Author: John Deng ([email protected])
#
# Copyright (c) 2014-2017 John Deng ([email protected])
#
# Licensed under the Apache License, Version 2.0 (the License);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an AS IS BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author: John Deng ([email protected])
# Updated: Sat Mar 18 15:33:39 CST 2017
# module: oc
# Action: login
###############################################################################
source "${HI_CLI_HOME}/bin/colors"
#source "${HI_CLI_HOME}/bin/clap"
source "${HI_CLI_HOME}/bin/logging"
###############################################################################
function get_current_project()
{
echo $(oc project | awk '{print $3}'|awk -F'"' '{print $2}')
}
function get_git_deployer()
{
l_app=$1
l_project_profile=$2
echo $(oc env dc/${l_app} -n ${l_project_profile} --list 2> /dev/null | grep DEPLOYER | sed "s/DEPLOYER=//g")
}
function get_git_reversion()
{
l_app=$1
l_project_profile=$2
echo $(oc env dc/${l_app} -n ${l_project_profile} --list 2> /dev/null | grep REVISION | sed "s/REVISION=//g")
}
function is_app_exist()
{
l_app=$1
l_project_profile=$2
if [ "$(oc get dc -n ${l_project_profile} -l app=${l_app} 2> /dev/null)" == "" ]; then
echo "no"
else
echo "yes"
fi
}
function diff_git_reversion_app()
{
l_app=$1
l_project=$2
l_profile1=$3
l_profile2=$4
rev1=$(get_git_reversion ${l_app} ${l_project}-${l_profile1} )
deployer=$(get_git_deployer ${l_app} ${l_project}-${l_profile1})
if [ "$(is_app_exist ${l_app} ${l_project}-${l_profile2})" == "yes" ]; then
rev2=$(get_git_reversion ${l_app} ${l_project}-${l_profile2} )
if [ "${rev1}" != "${rev2}" ]; then
echo "[ ${l_profile1}: ${rev1} ] [ ${l_profile2}: ${rev2} ] [ deployer: ${deployer} ]"
fi
fi
}
function run() {
cli="hi cicd diff"
log_info "get different git revision between ${arg3} and ${arg4}"
l_profile1=${arg3}
l_profile2=${arg4}
oc projects | grep ${l_profile2} | sed "s/\-${l_profile2}//g" | sed 's/\*/ /g' | grep -v Using | while read project; do
log_debug "project: ${project}"
oc get dc -n ${project}-${l_profile1} 2> /dev/null | grep -v NAME | awk '{print $1}' | while read app; do
# log_debug "${app}"
result="$(diff_git_reversion_app ${app} ${project} ${l_profile1} ${l_profile2} )"
if [ "${result}" != "" ]; then
log_warn "[ app: ${app} ] [ project: ${project} ] ${result}"
fi
done
done
result=$?
eval $1=\${result}
eval $2=\${cli}
}
###############################################################################