@leverege/build-tools 1.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/.publishrc +15 -0
  2. package/CHANGELOG.md +30 -0
  3. package/LICENSE.md +3 -0
  4. package/README.md +32 -0
  5. package/lib/server/auditate/help.js +119 -0
  6. package/lib/server/auditate/index.js +23 -0
  7. package/lib/server/auditate/report.js +61 -0
  8. package/lib/server/circleate +549 -0
  9. package/lib/server/decrypt-secrets +91 -0
  10. package/lib/server/dnsify/CloudflareAPI.js +103 -0
  11. package/lib/server/dnsify/accounts.json.enc +0 -0
  12. package/lib/server/dnsify/index.js +92 -0
  13. package/lib/server/dockreate +338 -0
  14. package/lib/server/encrypt-secrets +31 -0
  15. package/lib/server/getfbcfg +23 -0
  16. package/lib/server/getjson +48 -0
  17. package/lib/server/helmdn +103 -0
  18. package/lib/server/helmify +289 -0
  19. package/lib/server/helmup +87 -0
  20. package/lib/server/overwhelm +303 -0
  21. package/lib/server/packleate/Packleator.js +269 -0
  22. package/lib/server/packleate/index.js +98 -0
  23. package/lib/server/packleate/logo-ansi.js +17 -0
  24. package/lib/server/pkgck +136 -0
  25. package/lib/server/pkglint/index.js +19 -0
  26. package/lib/server/test.json +4 -0
  27. package/lib/web/auditate/help.js +158 -0
  28. package/lib/web/auditate/index.js +27 -0
  29. package/lib/web/auditate/report.js +91 -0
  30. package/lib/web/dnsify/CloudflareAPI.js +250 -0
  31. package/lib/web/dnsify/index.js +147 -0
  32. package/lib/web/packleate/Packleator.js +645 -0
  33. package/lib/web/packleate/index.js +157 -0
  34. package/lib/web/packleate/logo-ansi.js +3 -0
  35. package/lib/web/pkglint/index.js +19 -0
  36. package/package.json +74 -0
  37. package/src/auditate/help.js +83 -0
  38. package/src/auditate/index.js +25 -0
  39. package/src/auditate/report.js +54 -0
  40. package/src/circleate +549 -0
  41. package/src/decrypt-secrets +91 -0
  42. package/src/dnsify/CloudflareAPI.js +99 -0
  43. package/src/dnsify/accounts.json.enc +0 -0
  44. package/src/dnsify/index.js +82 -0
  45. package/src/dockreate +338 -0
  46. package/src/encrypt-secrets +31 -0
  47. package/src/getfbcfg +23 -0
  48. package/src/getjson +48 -0
  49. package/src/helmdn +103 -0
  50. package/src/helmify +289 -0
  51. package/src/helmup +87 -0
  52. package/src/overwhelm +303 -0
  53. package/src/packleate/Packleator.js +271 -0
  54. package/src/packleate/index.js +86 -0
  55. package/src/packleate/logo-ansi.js +16 -0
  56. package/src/pkgck +136 -0
  57. package/src/pkglint/index.js +21 -0
  58. package/src/test.json +4 -0
@@ -0,0 +1,103 @@
1
+ #!/bin/bash
2
+
3
+ # Simple ANSI color coded string generator.
4
+ color() {
5
+ local color=
6
+ case "$1" in
7
+ 'g') color="92m" ;; # green
8
+ 'c') color="96m" ;; # lt blue
9
+ 'y') color="93m" ;; # yellow
10
+ 'r') color="91m" ;; # red
11
+ 'toast') color="1;3;7;91;103;5m" ;;
12
+ esac
13
+ printf "\e[$color$2\e[0m"
14
+ }
15
+
16
+ clearlyWarn() {
17
+ clear
18
+ cat<<CLEARWARN
19
+
20
+ `color toast '*** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***'`
21
+
22
+ CLEARWARN
23
+ }
24
+
25
+ clearlyWarn
26
+ cat<<ABOUT2NUKE
27
+ You are about to start nuking deployments, as in delete with --purge. Are
28
+ you certain this is what you want to do?
29
+
30
+ Enter "yes" if that is in fact the case.
31
+
32
+ ABOUT2NUKE
33
+
34
+ read ANS && [ "$ANS" != "yes" ] && exit 1
35
+
36
+ #
37
+ # This script is used to ease the pain of transition testing to chart museum
38
+ # prior to setting up keel for new clusters / installs.
39
+ #
40
+ PLATFORM=(
41
+ api-server
42
+ db-curator
43
+ emailer
44
+ imagine
45
+ message-processor
46
+ messenger
47
+ reason
48
+ scheduler
49
+ transponder-bq
50
+ transponder-fb
51
+ transponder-sql
52
+ )
53
+
54
+ SYSTEM=(
55
+ descheduler
56
+ elastic
57
+ monitoring
58
+ redis
59
+ )
60
+
61
+ GITTOP=`git rev-parse --show-toplevel`
62
+ cd $GITTOP
63
+
64
+ npm run ahoy
65
+ [ $? -ne 0 ] && printf "\n\n***Aborting helmup...\n\n" && exit 1
66
+
67
+ helm repo update && helm search chartmuseum
68
+
69
+ function doNuking() {
70
+
71
+ for PARAM in "$@";
72
+ do
73
+ SERVICE=${PARAM%/} # strip trailing / if it's there
74
+
75
+ if [ "$SERVICE" == "platform" ];
76
+ then
77
+ doNuking "${PLATFORM[@]}" && exit $?
78
+ fi
79
+
80
+ if [ "$SERVICE" == "ingress" ];
81
+ then
82
+ clearlyWarn
83
+ cat<<NOGRESS
84
+
85
+ Deleting the ingress is probably the most costly deployment to nuke since
86
+ it takes so long to rebuild and stabilize. Therefore, if you REALLY want
87
+ to do that then you can copy and paste these commands by hand and do it
88
+ yourself:
89
+
90
+ npm run ahoy; helm delete --purge $SERVICE
91
+
92
+ NOGRESS
93
+ continue
94
+ fi
95
+
96
+ [ "$SERVICE" == "elastic" ] && doNuking elasticsearch && continue
97
+
98
+ helm delete --purge $SERVICE
99
+ done
100
+ }
101
+
102
+ doNuking $@
103
+ cd - &> /dev/null
@@ -0,0 +1,289 @@
1
+ #!/bin/bash
2
+
3
+ # Check if Helm is installed first
4
+ if ! [ -x "$(command -v helm)" ]; then
5
+ echo 'Error: helm is not installed.'
6
+ echo 'To install: brew install kubernetes-helm'
7
+ exit 1
8
+ fi
9
+
10
+ # Check if Chart Museum is installed
11
+ if ! [ -x "$(command -v chartmuseum)" ]; then
12
+ echo 'Error: chartmuseum is not installed.'
13
+ echo 'To install: see instructions at https://leverege.atlassian.net/wiki/spaces/PLAT/pages/679542800/Helm+Charts+via+ChartMuseum'
14
+ exit 1
15
+ fi
16
+
17
+ # Check if Chart Museum is running
18
+ url='http://localhost:8080/'
19
+ status_code=$(curl --write-out %{http_code} --silent --output /dev/null ${url})
20
+
21
+ if [[ "$status_code" -ne 200 ]] ; then
22
+ echo 'Error: Chart Museum is not running'
23
+ echo 'To run: chartmuseum --debug --port=8080 --storage="google" --storage-google-bucket="leverege-helm-charts" --storage-google-prefix=""'
24
+ exit 1
25
+ fi
26
+
27
+ # Bootstrap Helm charts
28
+ chartname=${PWD##*/}
29
+ chartname_go=${chartname//-/_}
30
+
31
+ if [ -d helm ];
32
+ then
33
+ printf "\nThere is an existing Helm repo, do you want to override?\n\n"
34
+ printf "Hit return to continue or ^C to exit\n\n"; read ANS
35
+ rm -rf helm
36
+ fi
37
+
38
+ createService() {
39
+ cat<<SVC_YAML > service.yaml
40
+ kind: Service
41
+ apiVersion: v1
42
+ metadata:
43
+ name: $chartname
44
+ spec:
45
+ type: NodePort
46
+ selector:
47
+ app: $chartname
48
+ ports:
49
+ - protocol: TCP
50
+ port: {{ .Values.$chartname_go.SERVER_PORT }}
51
+ targetPort: api
52
+ SVC_YAML
53
+ }
54
+
55
+ createIngress(){
56
+ cat<<INGRESS_YAML > ingress.yaml
57
+ apiVersion: extensions/v1beta1
58
+ kind: Ingress
59
+ metadata:
60
+ name: $chartname-ingress
61
+ annotations:
62
+ kubernetes.io/ingress.global-static-ip-name: $chartname-ingress
63
+ spec:
64
+ tls:
65
+ - secretName: frontendtls
66
+ rules:
67
+ - host: {{ quote .Values.$chartname_go.INGRESS_HOST }}
68
+ http:
69
+ paths:
70
+ - backend:
71
+ serviceName: $chartname
72
+ servicePort: {{ .Values.$chartname_go.SERVER_PORT }}
73
+ - http:
74
+ paths:
75
+ - backend:
76
+ serviceName: $chartname
77
+ servicePort: {{ .Values.$chartname_go.SERVER_PORT }}
78
+ INGRESS_YAML
79
+ }
80
+
81
+ # Make chart directory
82
+ mkdir helm
83
+ mkdir helm/templates
84
+
85
+ # Make Chart.yaml
86
+ cd helm
87
+
88
+ PACKAGE_VERSION=$(node -p "require('../package.json').version")
89
+
90
+ cat<<CHARTYAML > Chart.yaml
91
+ name: $chartname
92
+ version: 1.0.0
93
+ appVersion: $PACKAGE_VERSION
94
+
95
+ CHARTYAML
96
+
97
+ # Bootstrap values.yaml
98
+ cat<<VALUESYAML > values.yaml
99
+ # List your env variables here
100
+ $chartname_go:
101
+ VERSION: v$PACKAGE_VERSION
102
+ SERVER_PORT: 8080
103
+ IMAGE: gcr.io/leverege-docker-images/$chartname
104
+
105
+ default:
106
+ LOG_DIR: "/var/log/levlog"
107
+ LOG_LEVEL: "info"
108
+ MAX_CHILD_PROCESSES: "1"
109
+
110
+ MODEL_FIREBASE_SERVICE_ACCOUNT: /var/config/keys/model-data
111
+ MODEL_FIREBASE_DATABASE_URL: <firebase URL>
112
+ MODEL_FIREBASE_CONFIG: /var/config/keys/model-data-config
113
+
114
+ SECRET_KEY: key.json
115
+
116
+ PUBSUB_SERVICE_ACCOUNT: /var/config/keys/pubsub
117
+
118
+ TRANSPORT_CONFIG: "{
119
+ \"type\": \"pubsub\",
120
+ \"projectId\": \"OVH:<PROJECT_NAME>\",
121
+ \"keyFilename\": \"/var/config/keys/pubsub/key.json\" ,
122
+ \"publisher\": {
123
+ \"batching\": {
124
+ \"maxMilliseconds\": 0,
125
+ \"maxMessages\": 999
126
+ }
127
+ }
128
+ }"
129
+ LOG_CONFIG: "{
130
+ \"type\": \"bunyan\",
131
+ \"name\": \"${logName}\",
132
+ \"level\": \"info\",
133
+ \"streams\": [
134
+ {
135
+ \"type\": \"rotating-file\",
136
+ \"period\": \"1d\",
137
+ \"count\": 3,
138
+ \"path\": \"/var/log/levlog/${logName}.log\"
139
+ }, {
140
+ \"type\": \"stackdriver\",
141
+ \"logName\": \"${logName}\"
142
+ }
143
+ ]
144
+ }"
145
+ CACHE_CONFIG: "{
146
+ \"type\": \"redis\",
147
+ \"connection\": {
148
+ \"host\": \"redis-master\",
149
+ \"port\": \"6379\"
150
+ }
151
+ }"
152
+ LIMIT_CONFIG: "{
153
+ \"type\":\"redis\",
154
+ \"connection\":{
155
+ \"host\":\"redis-master\",
156
+ \"port\":6379
157
+ },
158
+ \"limitOptions\":{
159
+ \"frequency\":30,
160
+ \"period\":60000,
161
+ \"duration\":600000
162
+ }
163
+ }"
164
+ NODE_ENVIRONMENT: production
165
+
166
+ VALUESYAML
167
+
168
+ # Bootstrap templates
169
+ cd templates
170
+ cat<<DEPLOYMENT_YAML > deployment.yaml
171
+ apiVersion: apps/v1beta1
172
+ kind: Deployment
173
+ metadata:
174
+ name: $chartname
175
+ spec:
176
+ template:
177
+ metadata:
178
+ labels:
179
+ app: $chartname
180
+ redis-client: 'true'
181
+ annotations:
182
+ prometheus.io/port: '5111'
183
+ prometheus.io/scrape: 'true'
184
+ spec:
185
+ volumes:
186
+ - name: model-firebase-key
187
+ secret:
188
+ secretName: model-data
189
+ - name: logs
190
+ emptyDir: {}
191
+ - name: pubsub-key
192
+ secret:
193
+ secretName: pubsub
194
+ # UNCOMMENT TO USE PRE-EMPTIBLES
195
+ # tolerations:
196
+ # - key: "preemptible"
197
+ # operator: "Equal"
198
+ # value: "true"
199
+ # effect: "NoSchedule"
200
+ # affinity:
201
+ # podAntiAffinity:
202
+ # preferredDuringSchedulingIgnoredDuringExecution:
203
+ # - weight: 100
204
+ # podAffinityTerm:
205
+ # labelSelector:
206
+ # matchExpressions:
207
+ # - key: app
208
+ # operator: In
209
+ # values:
210
+ # - api-server
211
+ # topologyKey: kubernetes.io/hostname
212
+ # nodeAffinity:
213
+ # preferredDuringSchedulingIgnoredDuringExecution:
214
+ # - preference:
215
+ # matchExpressions:
216
+ # - key: cloud.google.com/gke-preemptible
217
+ # operator: Exists
218
+ # weight: 50
219
+ containers:
220
+ - name: $chartname
221
+ image: gcr.io/leverege-docker-images/$chartname:{{ .Values.$chartname_go.VERSION }}
222
+ resources:
223
+ requests:
224
+ cpu: "10m"
225
+ ports:
226
+ {{- if .Values.$chartname_go.SERVER_PORT }}
227
+ - name: api
228
+ containerPort: {{ .Values.$chartname_go.SERVER_PORT }}
229
+ {{- end }}
230
+ - name: node-metrics
231
+ containerPort: 5111
232
+ volumeMounts:
233
+ - name: model-firebase-key
234
+ mountPath: {{ quote .Values.default.MODEL_FIREBASE_SERVICE_ACCOUNT }}
235
+ - name: logs
236
+ mountPath: {{ quote .Values.default.LOG_DIR }}
237
+ - name: pubsub-key
238
+ mountPath: {{ quote .Values.default.PUBSUB_SERVICE_ACCOUNT }}
239
+ env:
240
+ - name: NODE_ENV
241
+ value: {{ .Values.default.NODE_ENVIRONMENT }}
242
+ - name: CACHE_CONFIG
243
+ value: {{ required "Cache config required" .Values.default.CACHE_CONFIG | quote }}
244
+ - name: LIMIT_CONFIG
245
+ value: {{ required "Limit config required" .Values.default.LIMIT_CONFIG | quote }}
246
+ - name: TRANSPORT_CONFIG
247
+ value: {{ required "Transport config required" .Values.default.TRANSPORT_CONFIG | quote }}
248
+ - name: LOG_DIR
249
+ value: {{ quote .Values.default.LOG_DIR }}
250
+ - name: LOG_LEVEL
251
+ value: {{ quote .Values.default.LOG_LEVEL }}
252
+ - name: LOG_CONFIG
253
+ value: {{ required "Log config required" .Values.default.LOG_CONFIG | quote }}
254
+ - name: MAX_CHILD_PROCESSES
255
+ value: {{ quote .Values.default.MAX_CHILD_PROCESSES }}
256
+ - name: MODEL_FIREBASE_SERVICE_ACCOUNT
257
+ value: {{ .Values.default.MODEL_FIREBASE_SERVICE_ACCOUNT }}/{{ .Values.default.SECRET_KEY }}
258
+ - name: MODEL_FIREBASE_DATABASE_URL
259
+ value: {{ quote .Values.default.MODEL_FIREBASE_DATABASE_URL }}
260
+ DEPLOYMENT_YAML
261
+
262
+ read -p "Does your server need an open port to the Internet (i.e. ingress or service)? [Y or N] " -n 1 -r
263
+ echo # (optional) move to a new line
264
+ if [[ $REPLY =~ ^[Yy]$ ]]
265
+ then
266
+ echo
267
+ echo '**************************************'
268
+ echo 'CREATING SERVICE AND INGRESS TEMPLATES'
269
+ echo '**************************************'
270
+ createService
271
+ createIngress
272
+ fi
273
+
274
+ # Print out some hints
275
+ cat<<HINTS
276
+
277
+ *** IMPORTANT ***
278
+
279
+ 1. You will need to add in additional env variables to both templates/*.yaml and values.yaml
280
+ 2. You may not need all the default env variables so feel free to remove them as well
281
+ 3. To use ingress, you need to reserve static ip as specified in ingress.yaml
282
+
283
+ Further instructions here: https://github.com/kelseyhightower/ingress-with-static-ip
284
+
285
+ 4. Finally, follow chart museum directions to add your chart or
286
+
287
+ helm push helm/ chartmuseum
288
+
289
+ HINTS
@@ -0,0 +1,87 @@
1
+ #!/bin/bash
2
+ #
3
+ # This script is used to ease the pain of transition testing to chart museum
4
+ # prior to setting up keel for new clusters / installs.
5
+ #
6
+ PLATFORM=(
7
+ api-server
8
+ db-curator
9
+ emailer
10
+ imagine
11
+ message-processor
12
+ messenger
13
+ reason
14
+ scheduler
15
+ transponder-bq
16
+ transponder-fb
17
+ transponder-sql
18
+ )
19
+
20
+ SYSTEM=(
21
+ descheduler
22
+ elastic
23
+ monitoring
24
+ redis
25
+ )
26
+
27
+ GITTOP=`git rev-parse --show-toplevel`
28
+ cd $GITTOP
29
+
30
+ npm run ahoy
31
+ [ $? -ne 0 ] && printf "\n\n***Aborting helmup...\n\n" && exit 1
32
+
33
+ helm repo update && helm search chartmuseum
34
+
35
+ function doInstall() {
36
+
37
+ for PARAM in "$@";
38
+ do
39
+ SERVICE=${PARAM%/} # strip trailing / if it's there
40
+
41
+ case "$SERVICE" in
42
+ "platform")
43
+ doInstall "${PLATFORM[@]}"
44
+ ;;
45
+
46
+ "system")
47
+ doInstall "${SYSTEM[@]}"
48
+ ;;
49
+
50
+ "descheduler")
51
+ helm repo add akomljen-charts https://raw.githubusercontent.com/komljen/helm-charts/master/charts/
52
+ helm upgrade --install descheduler akomljen-charts/descheduler --set schedule="*/13 * * * *"
53
+ ;;
54
+
55
+ "elastic"|"elasticsearch")
56
+ helm repo add elastic https://helm.elastic.co
57
+ helm upgrade --install elasticsearch elastic/elasticsearch --version 7.2.0
58
+ ;;
59
+
60
+ "monitoring")
61
+ helm dep up ./monitoring && helm upgrade --install monitoring ./monitoring
62
+ ;;
63
+
64
+ "redis")
65
+ # https://github.com/helm/charts/tree/master/stable/redis
66
+ helm upgrade --install redis stable/redis \
67
+ --set usePassword=false,cluster.slaveCount=3,networkPolicy.enabled=true,metrics.enabled=true
68
+ ;;
69
+
70
+ "ingress")
71
+ helm upgrade --install ingress ./ingress
72
+ ;;
73
+
74
+ *)
75
+ [ ! -d $SERVICE ] && continue
76
+ [ ! -f $SERVICE/values-local.yaml ] && continue
77
+
78
+ printf "\n--------------------------------------------------------------\nCharting $SERVICE\n"
79
+ helm upgrade --install $SERVICE chartmuseum/$SERVICE -f $SERVICE/values.yaml
80
+ [ $? -ne 0 ] && printf "The $SERVICE chart failed - you have issues.\n"
81
+ ;;
82
+ esac
83
+ done
84
+ }
85
+
86
+ doInstall $@
87
+ cd - &> /dev/null