-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadtestdata.sh
executable file
·124 lines (104 loc) · 3.85 KB
/
loadtestdata.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
# fail fast
set -e
addParamAndSecret() {
local project=$1
shift
local env=$1
shift
local id=$1
shift
cloudtruth --project ${project} --env ${env} param set "param-${id}" --value "param-${project}-${env}-${id}" "$@"
cloudtruth --project ${project} --env ${env} param set "secret-${id}" --value "secret-${project}-${env}-${id}" --secret true "$@"
}
rand() {
local max=$1
echo $(( RANDOM % max + 1))
}
start_time=$(date)
echo "$0 started at $start_time"
echo "Set CLOUDTRUTH_* to use different config"
echo "e.g."
echo " CLOUDTRUTH_PROFILE=staging $(basename $0)"
echo
echo "Current environment values:"
env | grep CLOUDTRUTH_ || true
echo
base_project=${base_project:-base}
child_project=${child_project:-child}
base_count=${base_count:-300}
child_count=${child_count:-50}
production_step=${production_step:-5}
staging_step=${staging_step:-6}
echo "Set the following to affect how many params/secrets get created across envs"
echo "e.g."
echo " base_count=10 child_count=5 production_step=2 staging_step=2 $(basename $0)"
echo
echo "Current values:"
echo base_project=${base_project} - the base project name
echo child_project=${child_project} - the child project name
echo base_count=${base_count} - how many params and secrets to create in base project
echo child_count=${child_count} - how many params and secrets to create in child project
echo production_step=${production_step} - every Nth item gets overridden for production
echo staging_step=${staging_step} - every Nth item gets overridden for staging
echo
cloudtruth project set "${base_project}"
cloudtruth project set "${child_project}" --parent "${base_project}"
now=$(date +"%Y-%m-%d_%H-%M")
cloudtruth environment tag set production testTag_${now}
cloudtruth environment tag set staging testTag_${now}
# Add templates to base project
cloudtruth --project "${base_project}" template set json --body <(cat <<'EOF'
{
{%- for param in cloudtruth.parameters %}
"{{param[0]}}": "{{param[1]}}"{% unless forloop.last %};{% endunless %}
{%- endfor %}
}
EOF
)
cloudtruth --project "${base_project}" template set yaml --body <(cat <<'EOF'
# {{ cloudtruth.environment }}
{% for param in cloudtruth.parameters -%}
{{param[0]}}: {{param[1]}}
{% endfor -%}
EOF
)
# Add templates to child project
cloudtruth --project "${child_project}" template set dotenv --body <(cat <<'EOF'
{%- for param in cloudtruth.parameters -%}
{{param[0] | upcase}}={{param[1]}}
{% endfor -%}
EOF
)
# Adds params and secrets to base project
seq 1 1 $base_count | while read x; do
addParamAndSecret "${base_project}" default "${base_project}-${x}"
done
# Adds non-override params and secrets to child project
seq 1 1 $child_count| while read x; do
addParamAndSecret "${child_project}" default "${child_project}-${x}"
done
# Adds override params and secrets to child project
seq 1 1 $child_count| while read x; do
addParamAndSecret "${child_project}" default "${base_project}-${x}" --create-child
done
# Sets production values for some params in base project
seq 1 $production_step $base_count | while read x; do
addParamAndSecret "${base_project}" production "${base_project}-${x}"
done
# Sets staging values for some params in base project
seq 1 $staging_step $base_count | while read x; do
addParamAndSecret "${base_project}" staging "${base_project}-${x}"
done
# Sets production values for some params in child project
seq 1 $production_step $child_count | while read x; do
addParamAndSecret "${child_project}" production "${child_project}-${x}"
done
# Sets staging values for some params in child project
seq 1 $staging_step $child_count | while read x; do
addParamAndSecret "${child_project}" staging "${child_project}-${x}"
done
cloudtruth environment tag set production stable
cloudtruth environment tag set staging stable
end_time=$(date)
echo "$0 started at: $start_time and ended at: $end_time"