-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.sh
executable file
·71 lines (57 loc) · 2.06 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
FLATTEN=false
echo "USAGE: $0 -r <GIT_REPO> -d <DOCKER_REGISTRY> [-h <HELM_MUSEUM> -f]"
while getopts 'r:d:h:f' OPTION; do
case "$OPTION" in
r) GIT_REPO=$OPTARG ;;
d) DOCKER_REGISTRY=$OPTARG ;;
h) HELM_MUSEUM=$OPTARG ;;
f) FLATTEN=true ;;
esac
done
shift "$(($OPTIND -1))"
: ${GIT_REPO:?Missing -r} ${DOCKER_REGISTRY:?Missing -d}
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
SED_FLAGS="-i"
elif [[ "$OSTYPE" == "darwin"* ]]; then
SED_FLAGS="-i ''"
else
echo "UNSUPPORTED OS: ${OSTYPE}"
fi
update_internal_refs() {
echo "updating internal refs in manifests/runtime.yaml"
sed ${SED_FLAGS} 's@https://github\.com/codefresh-contrib/internal-runtime-def-example\.git@'"${GIT_REPO}"'@g' manifests/runtime.yaml
}
update_docker_registr() {
echo "updating docker registry in all kustomization.yaml patches"
find . -type f -name "kustomization.yaml" | xargs sed ${SED_FLAGS} 's@<private_registry>@'"${DOCKER_REGISTRY}"@'g' manifests/app-proxy/kustomization.yaml
sed ${SED_FLAGS} 's@<private_registry>@'"${DOCKER_REGISTRY}"@'g' manifests/codefresh-tunnel-client/values.yaml
}
update_helm_museum() {
echo "updating helm museum in codefresh-tunnel-client chart.yaml"
sed ${SED_FLAGS} 's@https://chartmuseum\.codefresh\.io@'"${HELM_MUSEUM}"'@g' manifests/codefresh-tunnel-client/chart.yaml
}
flatten() {
local KUSTOMIZATIONS=()
while IFS= read -r -d $'\0'; do
KUSTOMIZATIONS+=("$REPLY")
done < <(find . -type f -name "kustomization.yaml" -print0)
for i in "${KUSTOMIZATIONS[@]}"; do
local COMPONENT_DIR=$(dirname ${i})
local INSTALL_YAML=${COMPONENT_DIR}/install.yaml
if [ ! -f ${INSTALL_YAML} ]; then
echo "flattening ${i}"
local RESOURCE=$(cat ${i} | grep https://github.com/codefresh.io/csdp.official)
kustomize build ${RESOURCE:2} > ${INSTALL_YAML}
sed ${SED_FLAGS} 's@- https://github\.com/codefresh-io/csdp-official\.git/.*@- install.yaml@g' ${i}
fi
done
}
update_internal_refs
update_docker_registr
if [ -n "${HELM_MUSEUM}" ]; then
update_helm_museum
fi
if [ "$FLATTEN" = true ]; then
flatten
fi