-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathpre-deploy
executable file
·73 lines (57 loc) · 2.18 KB
/
pre-deploy
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
72
73
#!/bin/bash
set -ue
# Upgrade check
version="$(exodus kit_version)"
set +e
if [[ -n "${version:-}" ]] && ! new_enough "${version}" "2.0.0-rc1" ; then
describe >&2 "" \
"[#M{$GENESIS_ENVIRONMENT}] migrating v#C{${version}} kit secrets from Vault to Credhub..."
#shellcheck disable=SC1091
source ./hooks/migrate-to-2.0
validate_expected_vault_secrets
correct_x509_certs
migrate_credentials_to_credhub
fi
# Cloud Config checks - deferred to after manifest is fully available.
describe >&2 "" \
"[#M{$GENESIS_ENVIRONMENT}] checking BOSH Cloud Config meets requirements of generated manifest..."
manifest="$(bosh int "$GENESIS_MANIFEST_FILE" -l "$GENESIS_BOSHVARS_FILE" | spruce json)"
cc_ok=yes
missing="$(jq -r '.instance_groups | map({"\(.name)": ((["azs","instances","jobs","name","networks","stemcell","vm_type"]) - (.|keys))}) | .[] | to_entries[] | select(.value | length > 0) | " - #m{\(.key)}: #R{\(.value| join(", "))}"' <(echo "$manifest"))"
if [[ -n "$missing" ]] ; then
describe \
" Invalid Instance Groups (missing one or more required fields):" \
"$missing" \
"" \
" Note: this could be because an instance group has been renamed" ""
cc_ok=no
fi
networks="$(jq -r '.instance_groups | map( .networks//[] | .[] |.name) | sort | unique[]' <(echo "$manifest"))"
vm_types="$(jq -r '.instance_groups | map( .vm_type ) | sort | unique[] | select(. != null)' <(echo "$manifest"))"
vm_extensions="$(jq -r '.instance_groups | map(.vm_extensions//[]) | flatten | sort | unique[]' <(echo "$manifest"))"
disks="$(jq -r '.instance_groups | map(.persistent_disk_type//[]) | flatten | sort | unique[]' <(echo "$manifest"))"
for t in $networks ; do
cloud_config_needs network "$t"
done
for t in $vm_types; do
cloud_config_needs vm_type "$t"
done
for t in $vm_extensions ; do
cloud_config_needs vm_extensions "$t"
done
for t in $disks ; do
cloud_config_needs disk_type "$t"
done
if ! check_cloud_config ; then
cc_ok=no
fi
# Check if there were any errors reported from the above checks.
if [[ $cc_ok == "yes" ]]; then
describe >&2 " cloud config [#G{OK}]"
else
describe >&2 " cloud config [#R{FAILED}]"
cc_ok=no
fi
[[ "$cc_ok" == "no" ]] && exit 1
echo
exit 0