-
Notifications
You must be signed in to change notification settings - Fork 16
/
run.sh
executable file
·728 lines (571 loc) · 24.9 KB
/
run.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
#!/usr/bin/env bash
set -eo pipefail
acraengdemo_raise() {
echo -e "\\nERROR: $*\\n" >&2
exit 1
}
acraengdemo_detect_os() {
platform=$(uname | tr '[:upper:]' '[:lower:]')
case "$platform" in
(linux)
if [[ -f '/etc/os-release' ]]; then
. /etc/os-release
os="${ID,,}"
if [ -z "${VERSION_ID:-}" ]; then
os_ver="unknown"
else
os_ver="${VERSION_ID%%.*}"
fi
case "$os" in
(debian)
os_ver_name="${VERSION#*(}"
os_ver_name="${os_ver_name%)}"
;;
(ubuntu)
if [[ "$VERSION_ID" == '14.04' ]]; then
os_ver_name='trusty'
else
os_ver_name="${VERSION_CODENAME:-${os_ver}}"
fi
;;
(*)
os_ver_name="${VERSION_CODENAME:-${os_ver}}"
;;
esac
else
acraengdemo_raise 'can not detect Linux version.'
fi
;;
(darwin)
os='macosx'
os_ver="$(sw_vers -productVersion | grep -Eo '^\d+\.\d+')"
os_ver_name="$os_ver"
;;
(*)
acraengdemo_raise "Sorry, the '$(uname)' platform is not supported."
;;
esac
}
acraengdemo_help() {
echo "
Usage:
run.sh <demo_project_name>
where <demo_project_name> can be one of:
$(for p in ${PROJECTS_SUPPORTED[@]}; do echo -e ' - '$p; done)
Description:
This script will prepare the environment and launch the selected
demonstration project.
"
}
acraengdemo_parse_args() {
if [ "$#" -ne '1' ]; then
acraengdemo_help
exit 1
fi
if [[ "$1" =~ (help|--help|-\?|--\?) ]]; then
acraengdemo_help
exit 0
fi
demo_project_name="$1"
}
acraengdemo_check() {
# Supported OS
OS_SUPPORTED=( debian ubuntu centos macosx arch manjaro )
[[ " ${OS_SUPPORTED[@]} " =~ " $os " ]] ||
acraengdemo_raise "OS version '$os' is not supported."
# Required tools
for c in 'git' 'docker' 'docker-compose'; do
if ! which "$c" 1>/dev/null; then
acraengdemo_raise "'$c' required but not found."
fi
done
}
acraengdemo_cmd() {
echo -e "\\n== ${2:-Run command}"
echo -e ">> $1\\n"
eval "$1"
}
acraengdemo_add_cleanup_cmd() {
CLEANUP_CMDS+=( "$1" )
CLEANUP_CMDS_DESC+=( "$2" )
}
acraengdemo_press_any_key() {
read < /dev/tty -n 1 -s -r -p 'Press any key to continue...'
}
acraengdemo_info_django() {
ETCHOSTS_PREFIX=''
if [ "$(uname)" == 'Darwin' ]; then
ETCHOSTS_PREFIX='/private'
fi
echo "
Please do not forget to add a temporary entry to the hosts file:
echo 'SERVER_IP www.djangoproject.example' >> $ETCHOSTS_PREFIX/etc/hosts
where SERVER_IP - IP address of the server with running Acra Engineering Demo.
"
echo '
Resources that will become available after launch:
* Django demo project admin cabinet - add entries to the demo site:
http://www.djangoproject.example:8000/admin/
Default user/password: admin/admin
* Django demo project - here you can see the added materials:
http://www.djangoproject.example:8000/weblog/
* Web interface for PostgreSQL - see how the encrypted data is stored:
http://www.djangoproject.example:8008
Default user/password: [email protected]/test
* PostgreSQL - also you can connect to DB directly:
postgresql://www.djangoproject.example:5432
Default admin user/password: postgres/test
* Prometheus - examine the collected metrics:
http://www.djangoproject.example:9090
* Grafana - sample of dashboards with Acra metrics:
http://www.djangoproject.example:3000
* Jaeger - view traces:
http://www.djangoproject.example:16686
'
acraengdemo_press_any_key
}
acraengdemo_info_django-transparent() {
acraengdemo_info_django
}
acraengdemo_info_python() {
echo '
Resources that will become available after launch:
Run example (write, read):
docker exec -it python_python_1 \
python /app/example.py --data="some data" --public_key="path-to-key"
docker exec -it python_python_1 \
python /app/example.py --print --public_key="path-to-key"
* Web interface for PostgreSQL - see how the encrypted data is stored:
http://$HOST:8008
Default user/password: [email protected]/test
* PostgreSQL - also you can connect to DB directly:
postgresql://$HOST:5432
Default admin user/password: postgres/test
* Prometheus - examine the collected metrics:
http://$HOST:9090
* Grafana - sample of dashboards with Acra metrics:
http://$HOST:3000
* Jaeger - view traces:
http://$HOST:16686
where are HOST is the IP address of the server with running Acra
Engineering Demo. If you run this demo on the same host, from
which you will connect, use "localhost".
'
acraengdemo_press_any_key
}
acraengdemo_info_cockroachdb() {
echo '
Resources that will become available after launch:
* Container with environment prepared for the python example. Folder with
example scripts will be mounted to container, so you will be able to
modify these scripts without stopping docker compose.
Run example (write, read):
docker exec -it cockroachdb_python_1 \
extended_example.py --host=acra-server --port=9393 --data=data.json
docker exec -it cockroachdb_python_1 \
python3 extended_example.py --host=acra-server --port=9393 --print
* CockroachDB - also you can connect to DB directly:
postgresql://$HOST:26257
Default user `root` and Database `defaultdb`
* Prometheus - examine the collected metrics:
http://$HOST:9090
* Grafana - sample of dashboards with Acra metrics:
http://$HOST:3000
* Jaeger - view traces:
http://$HOST:16686
where are HOST is the IP address of the server with running Acra
Engineering Demo. If you run this demo on the same host, from
which you will connect, use "localhost".
'
acraengdemo_press_any_key
}
acraengdemo_info_python-mysql-postgresql() {
echo '
Resources that will become available after launch:
* Container with environment prepared for the python example. Folder with
example scripts will be mounted to container, so you will be able to
modify these scripts without stopping docker compose.
Run example (write, read):
docker exec -it python-mysql_python_1 python3 \
extended_example.py --host=acra-server --port=9393 --data=data.json
docker exec -it python-mysql_python_1 python3 \
extended_example.py --host=acra-server --port=9393 --print
* Web interface for MySQL - see how the encrypted data is stored:
http://$HOST:8080
Default user/password: [email protected]/test
* MySQL - also you can connect to DB directly:
mysql://$HOST:3306
Default admin user/password: test/test
* Web interface for PostgreSQL - see how the encrypted data is stored:
http://$HOST:8008
Default user/password: [email protected]/test
* PostgreSQL - also you can connect to DB directly:
postgresql://$HOST:5432
Default admin user/password: postgres/test
* Prometheus - examine the collected metrics:
http://$HOST:9090
* Grafana - sample of dashboards with Acra metrics:
http://$HOST:3000
* Jaeger - view traces:
http://$HOST:16686
where are HOST is the IP address of the server with running Acra
Engineering Demo. If you run this demo on the same host, from
which you will connect, use "localhost".
'
acraengdemo_press_any_key
}
acraengdemo_info_db-acra-migration() {
echo '
Resources that will become available after launch:
* Container with environment prepared for the migration example. Folder with
example scripts will be mounted to container, so you will be able to
modify these scripts without stopping docker compose.
* Web interface for PostgreSQL - see how the encrypted data is stored:
http://$HOST:8008
Default user/password: [email protected]/test
* PostgreSQL - also you can connect to DB directly:
postgresql://$HOST:5432
Default admin user/password: postgres/test
where are HOST is the IP address of the server with running Acra
Engineering Demo. If you run this demo on the same host, from
which you will connect, use "localhost".
'
acraengdemo_press_any_key
}
acraengdemo_info_acra-translator() {
echo '
Resources that will become available after launch:
* Container with environment prepared for the AcraTransaltor example.
* Web interface for MongoDB - see how the encrypted data is stored:
http://$HOST:8081
BasicAuth user/password: test/test
* MongoDB - also you can connect to DB directly:
mongodb://$HOST:27017
Default admin user/password: root/password
* GO Server - API server integrated with AcraTransaltor and MongoDB:
http://$SWAGGER_HOST:8008/swagger/index.html#/ - swagger for available API
where are HOST is the IP address of the server with running Acra
Engineering Demo. If you run this demo on the same host, from
which you will connect, use "localhost".
'
acraengdemo_press_any_key
}
acraengdemo_info_rails() {
ETCHOSTS_PREFIX=''
if [ "$(uname)" == 'Darwin' ]; then
ETCHOSTS_PREFIX='/private'
fi
echo "
Please do not forget to add a temporary entry to the hosts file:
echo 'SERVER_IP www.rubygems.example' >> $ETCHOSTS_PREFIX/etc/hosts
where SERVER_IP - IP address of the server with running Acra Engineering Demo.
"
echo '
Resources that will become available after launch:
* rubygems.org demo project - here you can see the added materials:
http://www.rubygems.example:8000
* Web interface for PostgreSQL - see how the encrypted data is stored:
http://www.rubygems.example:8008
Default user/password: [email protected]/test
* PostgreSQL - also you can connect to DB directly:
postgresql://www.rubygems.example:5432
Default admin user/password: rubygems/rubygems
* Prometheus - examine the collected metrics:
http://www.rubygems.example:9090
* Grafana - sample of dashboards with Acra metrics:
http://www.rubygems.example:3000
* AcraConnector - play with the encryption system directly:
tcp://www.rubygems.example:9494
* Jaeger - view traces:
http://www.rubygems.example:16686
'
acraengdemo_press_any_key
}
acraengdemo_info_timescaledb() {
echo '
Resources that will become available after launch:
* TimescaleDB - also you can connect to DB directly:
postgresql://$HOST:5432
Default admin user/password: postgres/test
* Web interface for TimescaleDB - see how the encrypted data is stored:
http://$HOST:8008
Default user/password: [email protected]/test
* AcraConnector - play with the encryption system directly:
tcp://$HOST:9494
* Prometheus - examine the collected metrics:
http://$HOST:9090
* Grafana - sample dashboard with TimescaleDB data:
http://$HOST:3000
where are HOST is the IP address of the server with running Acra
Engineering Demo. If you run this demo on the same host, from
which you will connect, use "localhost".
'
acraengdemo_press_any_key
}
acraengdemo_info_python-searchable() {
echo '
Resources that will become available after launch:
* Container with environment prepared for the python example. Folder with
example scripts will be mounted to container, so you will be able to
modify these scripts without stopping docker compose.
Insert data into PostgreSQL:
docker exec -it python-searchable-python-1 \
python /app/searchable.py --postgresql --data=searchable.json
Read data from PostgreSQL:
docker exec -it python-searchable-python-1 \
python /app/searchable.py --postgresql --print
To use MySQL instead of PostgreSQL, provide `--mysql` flag
instead of `--postgresql`.
* Web interface for PostgreSQL - see how the encrypted data is stored:
http://$HOST:8008
Default user/password: [email protected]/test
* PostgreSQL - also you can connect to DB directly:
postgresql://$HOST:5432
Default admin user/password: test/test
* Web interface for MySQL - see how the encrypted data is stored:
http://$HOST:8080
Default user/password: [email protected]/test
* MySQL - also you can connect to DB directly:
mysql://$HOST:3306
Default admin user/password: test/test
* Prometheus - examine the collected metrics:
http://$HOST:9090
* Grafana - sample of dashboards with Acra metrics:
http://$HOST:3000
* Jaeger - view traces:
http://$HOST:16686
where are HOST is the IP address of the server with running Acra
Engineering Demo. If you run this demo on the same host, from
which you will connect, use "localhost".
'
acraengdemo_press_any_key
}
acraengdemo_git_clone_acraengdemo() {
COSSACKLABS_ACRAENGDEMO_VCS_URL=${COSSACKLABS_ACRAENGDEMO_VCS_URL:-'https://github.com/cossacklabs/acra-engineering-demo'}
COSSACKLABS_ACRAENGDEMO_VCS_BRANCH=${COSSACKLABS_ACRAENGDEMO_VCS_BRANCH:-master}
if [ -d "acra-engineering-demo" ]; then
git -C ./acra-engineering-demo/ "$COSSACKLABS_ACRAENGDEMO_VCS_BRANCH";
else
acraengdemo_cmd \
"git clone --depth 1 -b $COSSACKLABS_ACRAENGDEMO_VCS_BRANCH $COSSACKLABS_ACRAENGDEMO_VCS_URL" \
"Cloning acra-engineering-demo"
fi;
COSSACKLABS_ACRAENGDEMO_VCS_REF=$(git -C ./acra-engineering-demo/ rev-parse --verify HEAD)
}
acraengdemo_run_compose() {
DC_FILE="$PROJECT_DIR/$demo_project_name/docker-compose.$demo_project_name.yml"
acraengdemo_add_cleanup_cmd \
'docker image prune --all --force --filter "label=com.cossacklabs.product.name=acra-engdemo"' \
'remove custom built images'
acraengdemo_cmd "$COMPOSE_ENV_VARS docker-compose -f $DC_FILE pull" 'Pull fresh images'
acraengdemo_add_cleanup_cmd \
"docker-compose -f $DC_FILE down -v" \
'stop docker-compose'
acraengdemo_cmd "$COMPOSE_ENV_VARS docker-compose -f $DC_FILE up --build" 'Starting docker-compose'
}
acraengdemo_launch_project_django() {
COSSACKLABS_DJANGO_VCS_URL='https://github.com/cossacklabs/djangoproject.com'
COSSACKLABS_DJANGO_VCS_BRANCH=${COSSACKLABS_DJANGO_VCS_BRANCH:-master}
COSSACKLABS_DJANGO_VCS_REF='621e18f928db903d73b84788b3e3c9df9e83dd4c'
COMPOSE_ENV_VARS="${COMPOSE_ENV_VARS} "\
"COSSACKLABS_DJANGO_VCS_URL=\"$COSSACKLABS_DJANGO_VCS_URL\" "\
"COSSACKLABS_DJANGO_VCS_BRANCH=\"$COSSACKLABS_DJANGO_VCS_BRANCH\" "\
"COSSACKLABS_DJANGO_VCS_REF=\"$COSSACKLABS_DJANGO_VCS_REF\" "
acraengdemo_run_compose
}
acraengdemo_launch_project_django-transparent() {
COSSACKLABS_DJANGO_VCS_URL='https://github.com/django/djangoproject.com'
COSSACKLABS_DJANGO_VCS_BRANCH=${COSSACKLABS_DJANGO_VCS_BRANCH:-main}
COSSACKLABS_DJANGO_VCS_REF='67d1afa8fb8e1a1b2263989fbd8d3d3a8ae5b4c5'
COMPOSE_ENV_VARS="${COMPOSE_ENV_VARS} "\
"COSSACKLABS_DJANGO_VCS_URL=\"$COSSACKLABS_DJANGO_VCS_URL\" "\
"COSSACKLABS_DJANGO_VCS_BRANCH=\"$COSSACKLABS_DJANGO_VCS_BRANCH\" "\
"COSSACKLABS_DJANGO_VCS_REF=\"$COSSACKLABS_DJANGO_VCS_REF\" "
acraengdemo_run_compose
}
acraengdemo_launch_project_acra-translator() {
COSSACKLABS_GO_TRANSLATOR_DEMO_VCS_URL='https://github.com/cossacklabs/acra-engineering-demo'
COSSACKLABS_GO_TRANSLATOR_DEMO_VCS_BRANCH=${COSSACKLABS_DJANGO_VCS_BRANCH:-master}
COSSACKLABS_GO_TRANSLATOR_DEMO_VCS_REF='eb921ff32d76b79af4d9789d8bcb1e994b5777ef'
COMPOSE_ENV_VARS="${COMPOSE_ENV_VARS} "\
"COSSACKLABS_GO_TRANSLATOR_DEMO_VCS_URL=\"$COSSACKLABS_GO_TRANSLATOR_DEMO_VCS_URL\" "\
"COSSACKLABS_GO_TRANSLATOR_DEMO_VCS_BRANCH=\"$COSSACKLABS_GO_TRANSLATOR_DEMO_VCS_BRANCH\" "\
"COSSACKLABS_GO_TRANSLATOR_DEMO_VCS_REF=\"$COSSACKLABS_GO_TRANSLATOR_DEMO_VCS_REF\" "
acraengdemo_run_compose
}
acraengdemo_launch_project_db-acra-migration() {
COSSACKLABS_ACRA_VCS_URL='https://github.com/cossacklabs/acra-engineering-demo'
COSSACKLABS_ACRA_VCS_BRANCH=${COSSACKLABS_DJANGO_VCS_BRANCH:-master}
COSSACKLABS_ACRA_VCS_REF='eb921ff32d76b79af4d9789d8bcb1e994b5777ef'
COMPOSE_ENV_VARS="${COMPOSE_ENV_VARS} "\
"COSSACKLABS_ACRA_VCS_URL=\"$COSSACKLABS_GO_TRANSLATOR_DEMO_VCS_URL\" "\
"COSSACKLABS_ACRA_VCS_BRANCH=\"$COSSACKLABS_GO_TRANSLATOR_DEMO_VCS_BRANCH\" "\
"COSSACKLABS_ACRA_VCS_REF=\"$COSSACKLABS_GO_TRANSLATOR_DEMO_VCS_REF\" "
acraengdemo_run_compose
}
acraengdemo_launch_project_python() {
COSSACKLABS_ACRA_VCS_URL=${COSSACKLABS_ACRA_VCS_URL:-'https://github.com/cossacklabs/acra'}
COSSACKLABS_ACRA_VCS_REF=${COSSACKLABS_ACRA_VCS_REF:-'34e162b335a3d2c248b8fd1e294c25bd5c78350e'}
if [ -d "${PROJECT_DIR}/acra" ]; then
git -C "${PROJECT_DIR}/acra" checkout "$COSSACKLABS_ACRA_VCS_REF";
else
acraengdemo_cmd \
"git clone --depth 1 $COSSACKLABS_ACRA_VCS_URL ${PROJECT_DIR}/acra && cd ${PROJECT_DIR}/acra && git checkout $COSSACKLABS_ACRA_VCS_REF" \
"Cloning Acra"
fi;
COSSACKLABS_ACRA_VCS_REF=$(git -C "${PROJECT_DIR}/acra" rev-parse --verify HEAD)
acraengdemo_add_cleanup_cmd "rm -rf ${PROJECT_DIR}/acra" "remove cloned \"acra\" repository"
COMPOSE_ENV_VARS="${COMPOSE_ENV_VARS} "\
"COSSACKLABS_ACRA_VCS_URL=\"$COSSACKLABS_ACRA_VCS_URL\" "\
"COSSACKLABS_ACRA_VCS_BRANCH=\"master\" "\
"COSSACKLABS_ACRA_VCS_REF=\"$COSSACKLABS_ACRA_VCS_REF\" "
acraengdemo_run_compose
}
acraengdemo_launch_project_cockroachdb() {
COSSACKLABS_ACRA_VCS_URL=${COSSACKLABS_ACRA_VCS_URL:-'https://github.com/cossacklabs/acra'}
COSSACKLABS_ACRA_VCS_REF=${COSSACKLABS_ACRA_VCS_REF:-'e1773020a881a39d126724bd3992b9b436173fa0'}
if [ -d "${PROJECT_DIR}/acra" ]; then
git -C "${PROJECT_DIR}/acra" checkout "$COSSACKLABS_ACRA_VCS_REF";
else
acraengdemo_cmd \
"git clone --depth 1 $COSSACKLABS_ACRA_VCS_URL ${PROJECT_DIR}/acra && cd ${PROJECT_DIR}/acra && git checkout $COSSACKLABS_ACRA_VCS_REF" \
"Cloning Acra"
fi;
COSSACKLABS_ACRA_VCS_REF=$(git -C "${PROJECT_DIR}/acra" rev-parse --verify HEAD)
acraengdemo_add_cleanup_cmd "rm -rf ${PROJECT_DIR}/acra" "remove cloned \"acra\" repository"
COMPOSE_ENV_VARS="${COMPOSE_ENV_VARS} "\
"COSSACKLABS_ACRA_VCS_URL=\"$COSSACKLABS_ACRA_VCS_URL\" "\
"COSSACKLABS_ACRA_VCS_BRANCH=\"master\" "\
"COSSACKLABS_ACRA_VCS_REF=\"$COSSACKLABS_ACRA_VCS_REF\" "
acraengdemo_run_compose
}
acraengdemo_launch_project_python-mysql-postgresql() {
COSSACKLABS_ACRA_VCS_URL=${COSSACKLABS_ACRA_VCS_URL:-'https://github.com/cossacklabs/acra'}
# using commit instead of version/tag to use the commit with specific SqlAlchemy from examples/python
# https://github.com/cossacklabs/acra/pull/669/commits/be2ab1a4440e105dee1423ae21da1ee74e842801
# and some examples/python fixes
# https://github.com/cossacklabs/acra/commit/e1773020a881a39d126724bd3992b9b436173fa0
COSSACKLABS_ACRA_VCS_REF=${COSSACKLABS_ACRA_VCS_REF:-'e1773020a881a39d126724bd3992b9b436173fa0'}
if [ -d "${PROJECT_DIR}/acra" ]
then
git -C "${PROJECT_DIR}/acra" checkout "$COSSACKLABS_ACRA_VCS_REF";
else
# we should clone into folder with acra-eng-demo to allow mount files from acra/examples/python folder
acraengdemo_cmd \
"git clone $COSSACKLABS_ACRA_VCS_URL ${PROJECT_DIR}/acra && cd ${PROJECT_DIR}/acra && git checkout $COSSACKLABS_ACRA_VCS_REF" \
"Cloning Acra"
fi;
acraengdemo_add_cleanup_cmd "rm -rf ${PROJECT_DIR}/acra" "remove cloned \"acra\" repository"
COMPOSE_ENV_VARS="${COMPOSE_ENV_VARS} "\
"COSSACKLABS_ACRA_VCS_URL=\"$COSSACKLABS_ACRA_VCS_URL\" "\
"COSSACKLABS_ACRA_VCS_BRANCH=\"master\" "\
"COSSACKLABS_ACRA_VCS_REF=\"$COSSACKLABS_ACRA_VCS_REF\" "
acraengdemo_run_compose
}
acraengdemo_launch_project_rails() {
COSSACKLABS_RUBYGEMS_VCS_URL='https://github.com/cossacklabs/rubygems.org'
COSSACKLABS_RUBYGEMS_VCS_BRANCH=${COSSACKLABS_RUBYGEMS_VCS_BRANCH:-master}
COSSACKLABS_RUBYGEMS_VCS_REF='05c7338a5ecc89c7562bbe0a2d869d4e8ba601b5'
COMPOSE_ENV_VARS="${COMPOSE_ENV_VARS} "\
"COSSACKLABS_RUBYGEMS_VCS_URL=\"$COSSACKLABS_RUBYGEMS_VCS_URL\" "\
"COSSACKLABS_RUBYGEMS_VCS_BRANCH=\"$COSSACKLABS_RUBYGEMS_VCS_BRANCH\" "\
"COSSACKLABS_RUBYGEMS_VCS_REF=\"$COSSACKLABS_RUBYGEMS_VCS_REF\" "
acraengdemo_run_compose
}
acraengdemo_launch_project_timescaledb() {
acraengdemo_run_compose
}
acraengdemo_launch_project_python-searchable() {
COSSACKLABS_ACRA_VCS_URL=${COSSACKLABS_ACRA_VCS_URL:-'https://github.com/cossacklabs/acra'}
# using commit instead of version/tag to use the commit with specific SqlAlchemy from examples/python
# https://github.com/cossacklabs/acra/pull/669/commits/be2ab1a4440e105dee1423ae21da1ee74e842801
# and some examples/python fixes
# https://github.com/cossacklabs/acra/commit/e1773020a881a39d126724bd3992b9b436173fa0
COSSACKLABS_ACRA_VCS_REF=${COSSACKLABS_ACRA_VCS_REF:-'e1773020a881a39d126724bd3992b9b436173fa0'}
if [ -d "${PROJECT_DIR}/acra" ]
then
git -C "${PROJECT_DIR}/acra" checkout "$COSSACKLABS_ACRA_VCS_REF";
else
# we should clone into folder with acra-eng-demo to allow mount files from acra/examples/python folder
acraengdemo_cmd \
"git clone $COSSACKLABS_ACRA_VCS_URL ${PROJECT_DIR}/acra && cd ${PROJECT_DIR}/acra && git checkout $COSSACKLABS_ACRA_VCS_REF" \
"Cloning Acra"
fi;
COSSACKLABS_ACRA_VCS_REF=$(git -C "${PROJECT_DIR}/acra" rev-parse --verify HEAD)
acraengdemo_add_cleanup_cmd "rm -rf ${PROJECT_DIR}/acra" "remove cloned \"acra\" repository"
COMPOSE_ENV_VARS="${COMPOSE_ENV_VARS} "\
"COSSACKLABS_ACRA_VCS_URL=\"$COSSACKLABS_ACRA_VCS_URL\" "\
"COSSACKLABS_ACRA_VCS_BRANCH=\"$COSSACKLABS_ACRA_VCS_BRANCH\" "\
"COSSACKLABS_ACRA_VCS_REF=\"$COSSACKLABS_ACRA_VCS_REF\" "
acraengdemo_run_compose
}
acraengdemo_launch_project() {
[[ " ${PROJECTS_SUPPORTED[@]} " =~ " $demo_project_name " ]] ||
acraengdemo_raise "unknown demo project '$demo_project_name'."
echo -e "\\n## Selected demo project: $demo_project_name"
if [ -d ".git" ]; then
echo -e "\\n== Work in current directory\\n"
PROJECT_DIR="$(pwd)"
COSSACKLABS_ACRAENGDEMO_VCS_URL=${COSSACKLABS_ACRAENGDEMO_VCS_URL:-'https://github.com/cossacklabs/acra-engineering-demo'}
COSSACKLABS_ACRAENGDEMO_VCS_BRANCH=${COSSACKLABS_ACRAENGDEMO_VCS_BRANCH:-master}
COSSACKLABS_ACRAENGDEMO_VCS_REF=$(git rev-parse --verify HEAD)
else
echo -e "\\n== Create temporary directory\\n>> mktemp -d"
PROJECT_DIR="$(mktemp -d)"
echo "++ Created directory $PROJECT_DIR"
acraengdemo_add_cleanup_cmd "rm -rf $PROJECT_DIR" "remove temporary directory"
acraengdemo_cmd "cd $PROJECT_DIR" 'Go into project dir'
acraengdemo_git_clone_acraengdemo
PROJECT_DIR="${PROJECT_DIR}/acra-engineering-demo"
fi;
# assign default env variables for compose file
COMPOSE_ENV_VARS="COSSACKLABS_ACRAENGDEMO_VCS_URL=\"$COSSACKLABS_ACRAENGDEMO_VCS_URL\" "\
"COSSACKLABS_ACRAENGDEMO_VCS_BRANCH=\"$COSSACKLABS_ACRAENGDEMO_VCS_BRANCH\" "\
"COSSACKLABS_ACRAENGDEMO_VCS_REF=\"$COSSACKLABS_ACRAENGDEMO_VCS_REF\" "\
"COSSACKLABS_ACRAENGDEMO_BUILD_DATE=\"$(date -u +'%Y-%m-%dT%H:%M:%SZ')\" "
eval "acraengdemo_info_$demo_project_name"
eval "acraengdemo_launch_project_$demo_project_name"
}
acraengdemo_int() {
wait
acraengdemo_post
exit 0
}
acraengdemo_main() {
BASEDIR=$(pwd)
CLEANUP_CMDS=( )
CLEANUP_CMDS_DESC=( )
trap acraengdemo_int INT
acraengdemo_launch_project
}
acraengdemo_post() {
local FILE_CLEANUP="$BASEDIR/acraengdemo_cleanup.sh"
echo -e "#!/usr/bin/env bash\\n\\nset -x\\n\\n" > "$FILE_CLEANUP"
chmod +x "$FILE_CLEANUP"
if [ ${#CLEANUP_CMDS[*]} -gt 0 ]; then
echo -e '\n\nDemo stopped. Clean up commands:'
local cleanup_index_max=$(( ${#CLEANUP_CMDS[@]} -1 ))
local reverse_indexes=$(seq ${cleanup_index_max} -1 0)
for i in $reverse_indexes; do
echo -e "\\t* ${CLEANUP_CMDS_DESC[$i]}:"
echo -e "\\t\\t${CLEANUP_CMDS[$i]}"
echo "# ${CLEANUP_CMDS_DESC[$i]}" >> "$FILE_CLEANUP"
echo "${CLEANUP_CMDS[$i]}" >> "$FILE_CLEANUP"
done
fi
echo -e '\nAll these commands were saved to the script:'
echo -e "\\t$FILE_CLEANUP"
echo -e '\nRun it to clean up. May require sudo to remove directories, created by docker.\n'
}
acraengdemo_init() {
PROJECTS_SUPPORTED=( django django-transparent python python-mysql-postgresql rails timescaledb cockroachdb python-searchable acra-translator db-acra-migration )
}
acraengdemo_run() {
acraengdemo_init
acraengdemo_detect_os
acraengdemo_parse_args "$@"
acraengdemo_check
acraengdemo_main
acraengdemo_post
}
acraengdemo_run "$@"