-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy.init.sh
executable file
·54 lines (43 loc) · 1.87 KB
/
deploy.init.sh
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
#!/usr/bin/env bash
if [[ ! ${GITHUB_TOKEN} ]]; then echo "GITHUB_TOKEN is required" 1>&2; exit 1; fi
PROJECT="${PROJECT:-mqtt-gateway}"
SOURCE=${SOURCE:-"https://api.github.com/repos/netology-group/ulms-env/contents/k8s"}
APPS_SOURCE="https://api.github.com/repos/foxford/ulms-env/contents/apps"
BRANCH="${BRANCH:-master}"
function FILE_FROM_GITHUB() {
local DEST_DIR="${1}"; if [[ ! "${DEST_DIR}" ]]; then echo "${FUNCNAME[0]}:DEST_DIR is required" 1>&2; exit 1; fi
local URI="${2}"; if [[ ! "${URI}" ]]; then echo "${FUNCNAME[0]}:URI is required" 1>&2; exit 1; fi
if [[ "${3}" != "optional" ]]; then
local FLAGS="-fsSL"
else
local FLAGS="-sSL"
fi
mkdir -p "${DEST_DIR}"
curl ${FLAGS} \
-H "authorization: token ${GITHUB_TOKEN}" \
-H 'accept: application/vnd.github.v3.raw' \
-o "${DEST_DIR}/$(basename $URI)" \
"${URI}?ref=${BRANCH}"
}
function ADD_PROJECT() {
local _PATH="${1}"; if [[ ! "${_PATH}" ]]; then echo "${FUNCNAME[0]}:_PATH is required" 1>&2; exit 1; fi
local _PROJECT="${2}"; if [[ ! "${_PROJECT}" ]]; then echo "${FUNCNAME[0]}:PROJECT is required" 1>&2; exit 1; fi
tee "${_PATH}" <<END
PROJECT=${_PROJECT}
$(cat "${_PATH}")
END
}
set -ex
if [[ -n ${NAMESPACE} ]]; then
FILE_FROM_GITHUB "deploy" "${SOURCE}/certs/ca-${NAMESPACE}.crt"
SHORT_NS=$(echo $NAMESPACE | sed s/-ng/-foxford/ | sed -E "s/^(.)([[:alpha:]]*)(.*)$/\1\3/")
FILE_FROM_GITHUB "deploy" "${APPS_SOURCE}/${SHORT_NS}/${PROJECT}/values.yaml"
echo "In order to enable deployment NAMESPACE is required."
fi
## Use the same project for build & deploy scripts.
CI_FILES=(ci-build.sh ci-deploy.sh ci-mdbook.sh ci-install-tools.sh github-actions-run.sh)
for FILE in ${CI_FILES[@]}; do
FILE_FROM_GITHUB "deploy" "${SOURCE}/utils/${FILE}"
ADD_PROJECT "deploy/${FILE}" "${PROJECT}"
chmod u+x "deploy/${FILE}"
done