@@ -6,9 +6,11 @@ trap 'rm -rf $TMPDIR' EXIT
66
77cd " $TMPDIR "
88
9- # --------- UNIT ----------
9+ # --------- Installers for the 'unit' stage ----------
10+ # NOTE: as long as a function is prefixed with 'unit_install_', it will be automatically
11+ # picked up by the parallel stage below.
1012
11- install_bats () {
13+ unit_install_bats () {
1214 _parse_version " ${BATS_CORE_VERSION} "
1315 git clone -q --depth 1 https://github.com/bats-core/bats-core.git --branch " v${VERSION} " " ${TMPDIR} /bats-core"
1416 " ${TMPDIR} /bats-core/install.sh" /usr/local
@@ -22,23 +24,23 @@ install_bats() {
2224 echo " ✓ bats installed"
2325}
2426
25- install_docs () {
27+ unit_install_docs () {
2628 git clone -q --depth 1 --recurse-submodules --shallow-submodules https://github.com/elastisys/welkin.git " ${DOCS_PATH} "
2729 python3 -m venv " ${DOCS_PATH} /.venv"
2830 pushd " ${DOCS_PATH} " > /dev/null
2931 ./.venv/bin/pip install --no-cache-dir --quiet -r requirements.txt
3032 echo " ✓ docs installed"
3133}
3234
33- install_gomplate () {
35+ unit_install_gomplate () {
3436 _parse_version " ${GOMPLATE_VERSION} "
3537 curl -LOs " https://github.com/hairyhenderson/gomplate/releases/download/v${VERSION} /gomplate_linux-amd64"
3638 echo " ${SHA} gomplate_linux-amd64" | sha256sum -c -
3739 install -Tm 755 gomplate_linux-amd64 /usr/local/bin/gomplate
3840 echo " ✓ gomplate installed"
3941}
4042
41- install_helm () {
43+ unit_install_helm () {
4244 _parse_version " ${HELM_VERSION} "
4345 curl -LOs " https://get.helm.sh/helm-v${VERSION} -linux-amd64.tar.gz"
4446 tar -zxf " helm-v${VERSION} -linux-amd64.tar.gz" linux-amd64/helm
@@ -55,7 +57,7 @@ install_helm() {
5557 echo " ✓ helm-secrets installed"
5658}
5759
58- install_helmfile () {
60+ unit_install_helmfile () {
5961 _parse_version " ${HELMFILE_VERSION} "
6062 curl -LOs " https://github.com/helmfile/helmfile/releases/download/v${VERSION} /helmfile_${VERSION} _linux_amd64.tar.gz"
6163 tar -zxf " helmfile_${VERSION} _linux_amd64.tar.gz" helmfile
@@ -64,15 +66,15 @@ install_helmfile() {
6466 echo " ✓ helmfile installed"
6567}
6668
67- install_kubectl () {
69+ unit_install_kubectl () {
6870 _parse_version " ${KUBECTL_VERSION} "
6971 curl -LOs " https://dl.k8s.io/release/v${VERSION} /bin/linux/amd64/kubectl"
7072 echo " ${SHA} kubectl" | sha256sum -c -
7173 install -Tm 755 kubectl /usr/local/bin/kubectl
7274 echo " ✓ kubectl installed"
7375}
7476
75- install_kubeconform () {
77+ unit_install_kubeconform () {
7678 _parse_version " ${KUBECONFORM_VERSION} "
7779 curl -LOs " https://github.com/yannh/kubeconform/releases/download/v${VERSION} /kubeconform-linux-amd64.tar.gz"
7880 tar -zxf kubeconform-linux-amd64.tar.gz kubeconform
@@ -81,7 +83,7 @@ install_kubeconform() {
8183 echo " ✓ kubeconform installed"
8284}
8385
84- install_kubelogin () {
86+ unit_install_kubelogin () {
8587 _parse_version " ${KUBELOGIN_VERSION} "
8688 curl -LOs " https://github.com/int128/kubelogin/releases/download/v${VERSION} /kubelogin_linux_amd64.zip"
8789 unzip -q kubelogin_linux_amd64.zip
@@ -90,15 +92,15 @@ install_kubelogin() {
9092 echo " ✓ kubelogin installed"
9193}
9294
93- install_opa () {
95+ unit_install_opa () {
9496 _parse_version " ${OPA_VERSION} "
9597 curl -LOs " https://github.com/open-policy-agent/opa/releases/download/v${VERSION} /opa_linux_amd64"
9698 echo " ${SHA} opa_linux_amd64" | sha256sum -c -
9799 install -Tm 755 opa_linux_amd64 /usr/local/bin/opa
98100 echo " ✓ opa installed"
99101}
100102
101- install_promtool () {
103+ unit_install_promtool () {
102104 _parse_version " ${PROMTOOL_VERSION} "
103105 curl -fsSL " https://github.com/prometheus/prometheus/releases/download/v${VERSION} /prometheus-${VERSION} .linux-amd64.tar.gz" |
104106 tar -zxf - " prometheus-${VERSION} .linux-amd64/promtool" --strip-components=1
@@ -107,41 +109,43 @@ install_promtool() {
107109 echo " ✓ promtool installed"
108110}
109111
110- install_sops () {
112+ unit_install_sops () {
111113 _parse_version " ${SOPS_VERSION} "
112114 curl -LOs " https://github.com/getsops/sops/releases/download/v${VERSION} /sops-v${VERSION} .linux.amd64"
113115 echo " ${SHA} sops-v${VERSION} .linux.amd64" | sha256sum -c -
114116 install -Tm 755 " sops-v${VERSION} .linux.amd64" /usr/local/bin/sops
115117 echo " ✓ sops installed"
116118}
117119
118- install_yajsv () {
120+ unit_install_yajsv () {
119121 _parse_version " ${YAJSV_VERSION} "
120122 curl -LOs " https://github.com/neilpa/yajsv/releases/download/v${VERSION} /yajsv.linux.amd64"
121123 echo " ${SHA} yajsv.linux.amd64" | sha256sum -c -
122124 install -Tm 755 yajsv.linux.amd64 /usr/local/bin/yajsv
123125 echo " ✓ yajsv installed"
124126}
125127
126- install_yq () {
128+ unit_install_yq () {
127129 _parse_version " ${YQ_VERSION} "
128130 curl -LOs " https://github.com/mikefarah/yq/releases/download/v${VERSION} /yq_linux_amd64"
129131 echo " ${SHA} yq_linux_amd64" | sha256sum -c -
130132 install -Tm 755 yq_linux_amd64 /usr/local/bin/yq
131133 echo " ✓ yq installed"
132134}
133135
134- # --------- MAIN ----------
136+ # --------- Installers for the 'main' stage ----------
137+ # NOTE: as long as a function is prefixed with 'main_install_', it will be automatically
138+ # picked up by the parallel stage below.
135139
136- install_kind () {
140+ main_install_kind () {
137141 _parse_version " ${KIND_VERSION} "
138142 curl -LOs " https://github.com/kubernetes-sigs/kind/releases/download/v${VERSION} /kind-linux-amd64"
139143 echo " ${SHA} kind-linux-amd64" | sha256sum -c -
140144 install -Tm 755 kind-linux-amd64 /usr/local/bin/kind
141145 echo " ✓ kind installed"
142146}
143147
144- install_velero () {
148+ main_install_velero () {
145149 _parse_version " ${VELERO_VERSION} "
146150 curl -LOs " https://github.com/vmware-tanzu/velero/releases/download/v${VERSION} /velero-v${VERSION} -linux-amd64.tar.gz"
147151 tar -zxf " velero-v${VERSION} -linux-amd64.tar.gz" " velero-v${VERSION} -linux-amd64"
@@ -150,7 +154,7 @@ install_velero() {
150154 echo " ✓ velero installed"
151155}
152156
153- install_bun () {
157+ main_install_bun () {
154158 _parse_version " ${BUN_VERSION} "
155159 curl -LOs " https://github.com/oven-sh/bun/releases/download/bun-v${VERSION} /bun-linux-x64.zip"
156160 unzip -q bun-linux-x64.zip
@@ -160,7 +164,7 @@ install_bun() {
160164 echo " ✓ bun installed"
161165}
162166
163- # --------- UTILS ----------
167+ # --------- Utility functions ----------
164168
165169_git_clone_revision () {
166170 if [[ $# -lt 3 ]]; then
@@ -184,47 +188,24 @@ _parse_version() {
184188 SHA=" ${1#*@ sha256: } "
185189}
186190
187- export -f _git_clone_revision _parse_version \
188- install_bats install_docs install_gomplate \
189- install_helm install_helmfile \
190- install_kubectl install_kubeconform install_kubelogin install_opa install_promtool \
191- install_sops install_yajsv install_yq \
192- install_kind install_velero install_bun
193- export SHELLOPTS TMPDIR \
194- BATS_CORE_VERSION BATS_ASSERT_REV BATS_DETIK_REV BATS_FILE_REV BATS_MOCK_REV BATS_SUPPORT_REV \
195- DOCS_PATH GOMPLATE_VERSION \
196- HELM_DATA_HOME HELM_VERSION HELM_DIFF_VERSION HELM_SECRETS_VERSION HELMFILE_VERSION \
197- KUBECTL_VERSION KUBECONFORM_VERSION KUBELOGIN_VERSION OPA_VERSION PROMTOOL_VERSION \
198- SOPS_VERSION YAJSV_VERSION YAJSV_SHA YQ_VERSION YQ_SHA \
199- KIND_VERSION VELERO_VERSION BUN_VERSION
191+ # Re-export versions and revisions
192+ mapfile -t _version_and_revision_envs < <( compgen -v | grep -E ' (_VERSION|_REV)$' )
193+ export SHELLOPTS TMPDIR " ${_version_and_revision_envs[@]} "
194+
195+ # Export all utility + installer functions
196+ mapfile -t _unit_installer_fns < <( declare -F | grep -oP ' .+\Kunit_install_.+' )
197+ mapfile -t _main_installer_fns < <( declare -F | grep -oP ' .+\Kmain_install_.+' )
198+ export -f _git_clone_revision _parse_version " ${_unit_installer_fns[@]} " " ${_main_installer_fns[@]} "
200199
201200do_unit () {
202201 echo " Installing unit tools in parallel..."
203-
204202 git config --global advice.detachedHead false
205-
206- parallel -j " $( nproc) " --will-cite --halt now,fail=1 ::: \
207- install_bats \
208- install_docs \
209- install_gomplate \
210- install_helm \
211- install_helmfile \
212- install_kubectl \
213- install_kubeconform \
214- install_kubelogin \
215- install_opa \
216- install_promtool \
217- install_sops \
218- install_yajsv \
219- install_yq
203+ parallel -j " $( nproc) " --will-cite --halt now,fail=1 ::: " ${_unit_installer_fns[@]} "
220204}
221205
222206do_main () {
223207 echo " Installing main tools in parallel..."
224- parallel -j " $( nproc) " --will-cite --halt now,fail=1 ::: \
225- install_kind \
226- install_velero \
227- install_bun
208+ parallel -j " $( nproc) " --will-cite --halt now,fail=1 ::: " ${_main_installer_fns[@]} "
228209}
229210
230211" $@ "
0 commit comments