-
Notifications
You must be signed in to change notification settings - Fork 0
/
util
executable file
·55 lines (47 loc) · 1.31 KB
/
util
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
#!/usr/bin/env bash
function _require() {
[[ -z "$2" ]] && echo "no service $1 provided" && exit 1
}
function _to_config_entry() {
uppercase=$(echo "$service" | tr '[:lower:]' '[:upper:]')
ref="${uppercase}_REF"
if [ 'ontology' != "$service" ]; then
echo "INGEST_$ref"
else
echo "$ref"
fi
}
function _replace_config() {
config_entry=$1
update=$2
env=$3
sed -i '' "s/${config_entry}.*/${update}/g" config/environment_${env}
}
function _source_env() {
target=$(echo "$1" | tr '[:upper:]' '[:lower:]')
if [ "staging" == "$target" ]; then
echo 'dev'
elif [ "prod" == "$target" ]; then
echo 'staging'
fi
}
function release() {
service=$1
version=$2
_require "service" $service
_require "version" $version
config_entry=$(_to_config_entry $service)
_replace_config "$config_entry" "${config_entry}=${version}" dev
}
function promote() {
to_env=$1
service=$2
_require "deployment environment" $to_env
_require "service" $service
from_env=$(_source_env "$to_env")
[[ -z "$from_env" ]] && echo "cannot determine source for '$to_env'" && exit 1
config_entry=$(_to_config_entry "$service")
update=$(grep -ioE "${config_entry}.*" config/environment_${from_env})
_replace_config $config_entry $update $to_env
}
"$@"