This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.init.sh
executable file
·57 lines (45 loc) · 2.08 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
55
56
57
#!/usr/bin/env bash
if [[ ! ${GITHUB_TOKEN} ]]; then echo "GITHUB_TOKEN is required" 1>&2; exit 1; fi
PROJECT="${PROJECT:-storage-v2}"
SOURCE=${SOURCE:-"https://api.github.com/repos/foxford/ulms-env/contents/k8s"}
APPS_SOURCE="https://api.github.com/repos/foxford/ulms-env/contents/apps"
BRANCH="${BRANCH:-master}"
FLAGS="-sSL"
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
# insert PROJECT=${_PROJECT} as second line under a shebang
cat ${_PATH} | awk "NR==1{print; print \"PROJECT=${_PROJECT}\"} NR!=1" > ${_PATH}.tmp
mv ${_PATH}.tmp ${_PATH}
}
set -ex
if [[ -n ${NAMESPACE} ]]; then
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 "storage" project for the documentation.
FILE_FROM_GITHUB "deploy" "${SOURCE}/utils/ci-mdbook.sh"
ADD_PROJECT "deploy/ci-mdbook.sh" "storage"
## Use the same project for build & deploy scripts.
CI_FILES=(ci-build.sh ci-deploy.sh github-actions-run.sh)
for FILE in ${CI_FILES[@]}; do
FILE_FROM_GITHUB "deploy" "${SOURCE}/utils/${FILE}"
ADD_PROJECT "deploy/${FILE}" "${PROJECT}"
done
chmod u+x deploy/{ci-mdbook.sh,ci-build.sh,ci-deploy.sh,github-actions-run.sh}