-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy-env
executable file
·66 lines (56 loc) · 1.86 KB
/
deploy-env
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
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
LANG=C
# shellcheck source=./shellib/shellib.sh
. "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/shellib/shellib.sh"
# Check if dev env should be deployed by CI pipeline source
function is_dev_env_pipeline_source() {
local ci_pipeline_sources=('api' 'chat' 'trigger' 'web' 'webide')
[[ ${ci_pipeline_sources[*]} =~ $CI_PIPELINE_SOURCE ]]
}
# Check if dev env should be deployed by CI pipeline source and ENV_SKIP or CREATE_ENV variable
function is_dev_env_create_var() {
local ci_pipeline_sources=('push' 'schedule')
[[ ${ci_pipeline_sources[*]} =~ $CI_PIPELINE_SOURCE ]] &&
{ [ -n "${ENV_CREATE+x}" ] || [ -n "${CREATE_ENV+x}" ]; }
}
# Check if dev env should be skipped by ENV_SKIP or SKIP_ENV variable
function is_dev_env_skip() {
[ -n "${ENV_SKIP+x}" ] || [ -n "${SKIP_ENV+x}" ] ||
[[ ${CI_COMMIT_MESSAGE,,} =~ \[(skip\ env|env\ skip)\] ]]
}
# Check if dev env should be deployed or not
function deploy_dev_env() {
local result=1
local gl_tf_be_status_code
gl_tf_be_status_code=$(curl -s -H "Private-Token: $GL_TOKEN" -I "$GL_TF_BE/$CI_ENVIRONMENT_SLUG" -o /dev/null -w '%{http_code}')
case "$gl_tf_be_status_code" in
200) result=0 ;;
404)
if is_dev_env_pipeline_source || is_dev_env_create_var; then
result=0
fi
;;
*)
err "Terraform state at '$GL_TF_BE/$CI_ENVIRONMENT_SLUG' returns HTTP status code '$gl_tf_be_status_code'"
return "$status_err"
;;
esac
if [ $result == 0 ] && is_dev_env_skip; then
return 1
fi
return $result
}
# Check if env should be deployed or not
function deploy_env() {
if [ "$CI_ENVIRONMENT_TIER" == "development" ]; then
deploy_dev_env
else
true
fi
}
# Skip execution under test
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
deploy_env
fi