-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset-trigger
136 lines (117 loc) · 3.64 KB
/
set-trigger
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/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: Mon Mar 27 23:24:29 CST 2017
# Module: oc
# Submodule:
# Command: deploy
###############################################################################
source "${HI_CLI_HOME}/bin/colors"
source "${HI_CLI_HOME}/bin/logging"
###############################################################################
function deploy() {
# deploy(project, app, ver, "dev", "Asia/Shanghai")
if [ "${image_stream}" == "" ]; then
image_stream=s2i-java
fi
if [ "${timezone}" == "" ]; then
timezone=Asia/Shanghai
fi
if [ "${images_profile}" == "" ]; then
images_profile=dev
fi
if [ "${profile}" == "" ]; then
profile=dev
fi
project_profile="${project}-${profile}"
image_tag="latest"
if [ -f ./package.json ]; then
log_debug "found nodejs app"
ver=$(get_nodejs_app_version)
from_dir="dist"
if [ "${build}" == "build" ]; then
[ -f gulpfile.js ] && gulp build --env=${profile} || npm run build:${profile}
create_package_json "dist/package.json"
fi
elif [ -f pom.xml ]; then
from_dir="oc-build"
rm -rf oc-build && mkdir -p oc-build
log_debug "found java app"
ver=$(get_java_app_version)
log_debug "ver: ${ver}"
else
log_error "No app target found!"
exit
fi
log_debug "update trigger: ${project}/${app}, ${ver}, ${project_profile}, ${timezone} ${port}"
# tag for stage or prod
image_tag="${ver}"
log_debug "image_tag: ${image_tag}, ver: ${ver}"
oc project ${project_profile}
# get last image tag
last_image_tag=${project_profile}/$(oc set triggers dc/${app} | grep image | awk '{print $3}')
# remove it
oc set triggers dc/${app} --from-image=${last_image_tag} -c ${app} --remove -n ${project_profile}
# update with new image tag
oc set triggers dc/${app} --from-image=${project_profile}/${app}:latest -c ${app} -n ${project_profile}
# show trigers
oc set triggers dc/${app}
if [ $? != 0 ]; then
log_error "failed to update trigger"
return $?
fi
}
function create_package_json() {
log_debug "create_package_json"
cat > "$1" <<_EOF_
{
"name": "${app}",
"version": "${ver}",
"description": "nodejs http-server",
"scripts": {
"start": "http-server . -p 8080"
},
"author": "John Deng",
"license": "MIT"
}
_EOF_
}
function get_java_app_version() {
echo $(mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version|grep -Ev '(^\[|Download\w+:)')
}
function get_nodejs_app_version() {
echo $(node -p "require('./package.json').version")
}
function is_exist() {
if [ $(oc get $1 -n ${project_profile} | grep ${app} | wc -l) == 0 ]; then
echo "no"
else
echo "yes"
fi
}
function run() {
cli=""
deploy
result=$?
eval $1="\${result}"
eval $2="\${cli}"
}
###############################################################################