-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmanage
220 lines (191 loc) · 6.55 KB
/
manage
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/bin/bash
export MSYS_NO_PATHCONV=1
set -e
SCRIPT_HOME="$( cd "$( dirname "$0" )" && pwd )"
# =================================================================================================================
# Usage:
# -----------------------------------------------------------------------------------------------------------------
usage () {
cat <<-EOF
Allows you to manage certain aspects of the application environment.
Usage:
$0 [options] [commands]
buildandtag <tag/>
- Build the image(s) for the project in OCP using the local working copy of the code.
- Tags the built images with the specified tag.
Example;
$0 -e tools buildAndTag dev
build [<image/>]
- Build the images for the project in OCP using the local working copy of the code.
Examples;
- Build everything:
$0 -e tools build
- Build the audit image only:
$0 -e tools build audit
Images:
- audit
tag <sourceTag/> <destinationTag/>
- Tags all of the application images.
Example;
$0 -e tools tag latest dev
clean
- Deletes all application resources from a given environment.
EOF
}
# =================================================================================================================
# Process the local command line arguments and pass everything else along.
# - The 'getopts' options string must start with ':' for this to work.
# -----------------------------------------------------------------------------------------------------------------
while [ ${OPTIND} -le $# ]; do
if getopts : FLAG; then
case ${FLAG} in
# Pass unrecognized options ...
\?) pass+=" -${OPTARG}" ;;
esac
else
# Pass unrecognized arguments ...
pass+=" ${!OPTIND}"
let OPTIND++
fi
done
# Pass the unrecognized arguments along for further processing ...
shift $((OPTIND-1))
set -- "$@" $(echo -e "${pass}" | sed -e 's/^[[:space:]]*//')
# =================================================================================================================
# -----------------------------------------------------------------------------------------------------------------
# Define hook scripts:
# - These must be defined before the main settings script 'settings.sh' is loaded.
# -----------------------------------------------------------------------------------------------------------------
onRequiredOptionsExist() {
(
if [ -z "${DEPLOYMENT_ENV_NAME}" ]; then
_red='\033[0;31m'
_nc='\033[0m' # No Color
echo -e "\n${_red}You MUST specify an environment name using the '-e' flag.${_nc}"
echo -e "${_red}Assuming a default would have unwanted consequences.${_nc}\n"
return 1
else
return 0
fi
)
}
onUsesCommandLineArguments() {
(
# This script is expecting command line arguments to be passed ...
return 0
)
}
# -----------------------------------------------------------------------------------------------------------------
# Initialization:
# -----------------------------------------------------------------------------------------------------------------
# Load the project settings and functions ...
_includeFile="ocFunctions.inc"
_settingsFile="settings.sh"
if [ ! -z $(type -p ${_includeFile}) ]; then
_includeFilePath=$(type -p ${_includeFile})
export OCTOOLSBIN=$(dirname ${_includeFilePath})
if [ -f ${OCTOOLSBIN}/${_settingsFile} ]; then
. ${OCTOOLSBIN}/${_settingsFile}
fi
if [ -f ${OCTOOLSBIN}/${_includeFile} ]; then
. ${OCTOOLSBIN}/${_includeFile}
fi
else
_red='\033[0;31m'
_yellow='\033[1;33m'
_nc='\033[0m' # No Color
echo -e \\n"${_red}${_includeFile} could not be found on the path.${_nc}"
echo -e "${_yellow}Please ensure the openshift-developer-tools are installed on and registered on your path.${_nc}"
echo -e "${_yellow}https://github.com/BCDevOps/openshift-developer-tools${_nc}"
fi
# -----------------------------------------------------------------------------------------------------------------
# Functions:
# -----------------------------------------------------------------------------------------------------------------
function cleanEnv() {
printAndAskToContinue "If you contiune all of the application resources will be perminently deleted from $(getProjectName)."
oc -n $(getProjectName) delete all,pvc,secret,networkpolicies -l app=Audit
}
function functionExists() {
(
if [ ! -z ${1} ] && type ${1} &>/dev/null; then
return 0
else
return 1
fi
)
}
function build-and-tag() {
(
_tag=${1}
if [ -z "${_tag}" ]; then
echoError "\ntag; You MUST supply a tag.\n"
exit 1
fi
build-all
tag "latest" "${_tag}"
)
}
function build-all() {
build-audit
}
function build-audit() {
_namespace=$(getProjectName)
echo -e "\n\n===================================================================================================="
echo -e "Building the 'audit' image via binary build ..."
echo -e "----------------------------------------------------------------------------------------------------"
oc -n ${_namespace} start-build audit --follow=true --from-dir=.. --no-cache
echo -e "===================================================================================================="
}
function tag()
{
(
_sourceTag=${1}
_destTag=${2}
if [ -z "${_sourceTag}" ] || [ -z "${_destTag}" ]; then
echoError "\ntag; You MUST supply both 'source' and 'destination' tag.\n"
exit 1
fi
images="audit"
for image in ${images}; do
# Tag images ...
echo -e "\nTagging ${image}:${_sourceTag} as ${image}:${_destTag} ..."
oc -n ${TOOLS} tag ${image}:${_sourceTag} ${image}:${_destTag}
done
)
}
# =================================================================================================================
pushd ${SCRIPT_HOME} >/dev/null
_cmd=$(toLower ${1})
shift
case "${_cmd}" in
clean)
cleanEnv
;;
build)
buildImage=$(toLower ${1})
shift || buildImage=all
buildImage=$(echo ${buildImage} | sed s~^vcr-~~)
case "$buildImage" in
*=*)
buildImage=all
;;
esac
if functionExists "build-${buildImage}"; then
eval "build-${buildImage}"
else
echo -e "Error:\nThe build function, build-${buildImage}, does not exist. Please check your build parameters and try again.\nUse '-h' to get full help details."
exit 1
fi
;;
tag)
tag "${1}" "${2}"
;;
buildandtag)
build-and-tag "${@}"
;;
*)
echoWarning "Unrecognized command; ${_cmd}"
globalUsage
;;
esac
popd >/dev/null