forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
breeze
executable file
·3637 lines (3213 loc) · 132 KB
/
breeze
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
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
set -euo pipefail
AIRFLOW_SOURCES="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ ${BREEZE_REDIRECT=} == "" ]]; then
set +u
mkdir -p "${AIRFLOW_SOURCES}"/logs
export BREEZE_REDIRECT="true"
if [[ "$(uname)" == "Darwin" ]]; then
exec script -q "${AIRFLOW_SOURCES}"/logs/breeze.out "$(command -v bash)" -c "$(printf "%q " "${0}" "${@}")"
else
exec script --return --quiet "${AIRFLOW_SOURCES}"/logs/breeze.out -c "$(printf "%q " "${0}" "${@}")"
fi
set -u
fi
export AIRFLOW_SOURCES
readonly AIRFLOW_SOURCES
# Bash arrays need to be defined outside of functions unfortunately :(
# Because on Mac OS Bash 3.4 defining arrays inside functions does not work
# Array with extra options for Docker compose
declare -a EXTRA_DC_OPTIONS
export EXTRA_DC_OPTIONS
# Array with selected integrations
declare -a INTEGRATIONS
export INTEGRATIONS
# This is where remaining args are passed
declare -a REMAINING_ARGS
export REMAINING_ARGS
# This is where static check options are defined
declare -a EXTRA_STATIC_CHECK_OPTIONS
export EXTRA_STATIC_CHECK_OPTIONS
#######################################################################################################
# Sets up all the default variables for Breeze. They are needed by all other functions
# All those variables are exported. They are not set to read-only because those
# defaults can be modified later on when command line arguments are parsed
# and variables stored in .build directory (stored in the previous run) are read
#
# Used globals:
# FORCE_SCREEN_WIDTH
#
# Modified globals (constants or candidates for constants after we override them via appropriate flags):
#
# BREEZE
# SUPPRESS_CHEATSHEET_FILE
# SUPPRESS_ASCIIART_FILE
# MAX_SCREEN_WIDTH
# SCREEN_WIDTH
# MOUNT_SELECTED_LOCAL_SOURCES
# FORWARD_CREDENTIALS
# DB_RESET
# START_AIRFLOW
# INSTALL_AIRFLOW_VERSION
# INSTALL_AIRFLOW_REFERENCE
# FORCE_BUILD_IMAGES
# PRODUCTION_IMAGE
# PYTHON_MAJOR_MINOR_VERSION
#
# Global variables:
#
# command_to_run
# second_command_to_run
# docker_compose_command
#
# Also it sets the variables and globals set by common initialization functions from
# scripts/ci/libraries/_initialization.sh and breeze-complete script (which sets-up auto-complete).
#
#######################################################################################################
function breeze::setup_default_breeze_constants() {
# Indicates that we are inside Breeze environment
export BREEZE=true
readonly BREEZE
# If those files are present, the ASCII-art/cheat-sheet are suppressed
SUPPRESS_CHEATSHEET_FILE="${AIRFLOW_SOURCES}/.build/.suppress_cheatsheet"
readonly SUPPRESS_CHEATSHEET_FILE
SUPPRESS_ASCIIART_FILE="${AIRFLOW_SOURCES}/.build/.suppress_asciiart"
readonly SUPPRESS_ASCIIART_FILE
# Maximum screen indented_screen_width to print the lines spanning the whole terminal indented_screen_width
export MAX_SCREEN_WIDTH=100
readonly MAX_SCREEN_WIDTH
# By default we mount selected local Airflow sources
export MOUNT_SELECTED_LOCAL_SOURCES="true"
# By default we do not mount all local Airflow sources
export MOUNT_ALL_LOCAL_SOURCES="false"
# Forward common host credentials to docker (gcloud, aws etc.).
export FORWARD_CREDENTIALS="false"
# If set to true, the database will be reset at entry. Works for Postgres and MySQL
export DB_RESET="false"
# If set to true, the database will be initialized, a user created and webserver and scheduler started
export START_AIRFLOW="false"
# If set to true, the test connections will be created
export LOAD_DEFAULT_CONNECTIONS="false"
# If set to true, the sample dags will be used
export LOAD_EXAMPLES="false"
# If set to true, Breeze db volumes will be preserved when breeze is stopped and reused next time
# Which means that you do not have to start from scratch
export PRESERVE_VOLUMES="false"
# Sources by default are installed from local sources when using breeze
AIRFLOW_SOURCES_FROM=${AIRFLOW_SOURCES_FROM:="."}
export AIRFLOW_SOURCES_FROM
# They are copied to /opt/airflow by default in breeze
AIRFLOW_SOURCES_TO=${AIRFLOW_SOURCES_TO:="/opt/airflow"}
export AIRFLOW_SOURCES_TO
# Sources by default are installed from local sources when using breeze
AIRFLOW_SOURCES_WWW_FROM=${AIRFLOW_SOURCES_WWW_FROM:="./airflow/www"}
export AIRFLOW_SOURCES_WWW_FROM
# They are copied to /opt/airflow by default in breeze
AIRFLOW_SOURCES_WWW_TO=${AIRFLOW_SOURCES_WWW_TO:="/opt/airflow/airflow/www"}
export AIRFLOW_SOURCES_WWW_TO
# Unlike in CI scripts, in breeze by default production image is installed from sources
export AIRFLOW_INSTALLATION_METHOD="."
# If it set is set to specified version, then the source version of Airflow
# is removed and the specified version of Airflow is installed from PyPi
export INSTALL_AIRFLOW_VERSION=""
# If it is set to specified reference (tag/branch), then the source version
# of Airflow is removed and the specified version of Airflow is installed from GitHub
export INSTALL_AIRFLOW_REFERENCE=""
# Determines whether to force build without checking if it is needed
# Can be overridden by '--force-build-images' flag.
export FORCE_BUILD_IMAGES="false"
# Determines whether to reinstall airflow at entering the image.
export USE_AIRFLOW_VERSION=""
# if set to true, the ci image will look for wheel packages in dist folder and will install them
# during entering the container
export USE_PACKAGES_FROM_DIST="false"
# load all the common functions here - those are the functions that are shared between Breeze
# and CI scripts. The CI scripts do not use Breeze as driving script - they read all configuration
# from the environment variables. That's why we keep all the common initialization in those libs
# shellcheck source=scripts/ci/libraries/_all_libs.sh
. "${AIRFLOW_SOURCES}/scripts/ci/libraries/_all_libs.sh"
# When we generate documentation for README files, we want to force the indented_screen_width of terminal so that
# No matter who is running the documentation generation gets the same output
if [[ ${FORCE_SCREEN_WIDTH:="false"} != "true" ]]; then
# Sets indented_screen_width of the screen from terminal
SCREEN_WIDTH="$(tput cols)"
if [[ -z ${SCREEN_WIDTH=} ]]; then
SCREEN_WIDTH=${MAX_SCREEN_WIDTH}
fi
if ((SCREEN_WIDTH > MAX_SCREEN_WIDTH)); then
SCREEN_WIDTH=${MAX_SCREEN_WIDTH}
fi
else
SCREEN_WIDTH=${MAX_SCREEN_WIDTH}
fi
export SCREEN_WIDTH
readonly SCREEN_WIDTH
# for Breeze default tests executed are "All"
export TEST_TYPE=${TEST_TYPE:="All"}
# Update short and long options in the breeze-complete script
# This way autocomplete will work automatically with all options available
# shellcheck source=breeze-complete
. "${AIRFLOW_SOURCES}/breeze-complete"
# Default command to run - entering breeze environment
command_to_run="enter_breeze"
# In some cases we also want to run two commands in a row (for example when we restart the environment)
second_command_to_run=""
# Determines if help should be run (set to true by --help flag)
run_help="false"
# Holds docker compose command if the `docker-compose` command is used.
docker_compose_command=""
}
#######################################################################################################
#
# Initializes development-friendly virtualenv if you are already in such env. It installs all the necessary
# packages from PyPI and it case of problems it provides useful hints on what prerequisites should be
# installed. It also removes and resets the existing AIRFLOW_HOME installation to make sure that you
# have it synchronized with the version of airflow installed. It resets the airflow's sqlite database to
# a clean state. You can use this function if your virtualenv is broken, to clean it up
#
# Used globals:
# PYTHON_MAJOR_MINOR_VERSION
# AIRFLOW_HOME_DIR
# AIRFLOW_SOURCES
# VIRTUALENV_EXTRAS
# DEFAULT_CONSTRAINTS_BRANCH
# OSTYPE
#
#######################################################################################################
function breeze::initialize_virtualenv() {
# Check if we are inside virtualenv
set +e
echo -e "import sys\nif not hasattr(sys,'base_prefix'):\n sys.exit(1)" |
python"${PYTHON_MAJOR_MINOR_VERSION}"
local res=$?
set -e
if [[ ${res} != "0" ]]; then
echo
echo "${COLOR_RED}ERROR: Initializing local virtualenv only works when you have virtualenv activated ${COLOR_RESET}"
echo
echo "Please enter your local virtualenv before (for example using 'pyenv activate' or 'workon') "
echo
exit 1
else
echo
echo "Initializing the virtualenv: $(command -v python)!"
echo
echo "Extras to be installed: ${VIRTUALENV_EXTRAS}"
echo
echo "This will wipe out ${AIRFLOW_HOME_DIR} and reset all the databases!"
echo
"${AIRFLOW_SOURCES}/confirm" "Proceeding with the initialization"
echo
pushd "${AIRFLOW_SOURCES}" >/dev/null 2>&1 || exit 1
set +e
pip install -e ".[${VIRTUALENV_EXTRAS}]" \
--constraint "https://raw.githubusercontent.com/${CONSTRAINTS_GITHUB_REPOSITORY}/${DEFAULT_CONSTRAINTS_BRANCH}/constraints-source-providers-${PYTHON_MAJOR_MINOR_VERSION}.txt"
res=$?
set -e
popd
if [[ ${res} != "0" ]]; then
echo "#######################################################################"
echo " You had some troubles installing the venv !!!!!"
echo " Try running the command below and rerun virtualenv installation"
echo
if [[ ${OSTYPE} == "darwin"* ]]; then
echo " brew install sqlite mysql postgresql openssl"
echo " export LDFLAGS=\"-L/usr/local/opt/openssl/lib\""
echo " export CPPFLAGS=\"-I/usr/local/opt/openssl/include\""
else
echo " sudo apt install build-essential python3-dev libsqlite3-dev openssl \\"
echo " sqlite default-libmysqlclient-dev libmysqlclient-dev postgresql"
fi
echo
echo "#######################################################################"
exit ${res}
fi
echo
echo "Wiping and recreating ${AIRFLOW_HOME_DIR}"
echo
if [[ "${AIRFLOW_SOURCES}" == "${AIRFLOW_HOME_DIR}" ]]; then
echo "AIRFLOW_HOME and Source code for Apache Airflow resides in the same path ${AIRFLOW_HOME_DIR}"
echo "When running this command it will delete all the files in the path ${AIRFLOW_HOME_DIR} to clear dynamic files like config/logs/db"
echo "Move your source code for Apache Airflow to different folder to avoid deletion"
exit 1
fi
rm -rvf "${AIRFLOW_HOME_DIR}"
mkdir -p "${AIRFLOW_HOME_DIR}"
echo
echo "Resetting AIRFLOW sqlite database"
echo
AIRFLOW__CORE__LOAD_EXAMPLES="False" \
AIRFLOW__CORE__UNIT_TEST_MODE="False" \
AIRFLOW__CORE__SQL_ALCHEMY_POOL_ENABLED="False" \
AIRFLOW__CORE__DAGS_FOLDER="${AIRFLOW_SOURCES}/empty" \
AIRFLOW__CORE__PLUGINS_FOLDER="${AIRFLOW_SOURCES}/empty" \
airflow db reset -y
echo
echo "Resetting AIRFLOW sqlite unit test database"
echo
AIRFLOW__CORE__LOAD_EXAMPLES="False" \
AIRFLOW__CORE__UNIT_TEST_MODE="True" \
AIRFLOW__CORE__SQL_ALCHEMY_POOL_ENABLED="False" \
AIRFLOW__CORE__DAGS_FOLDER="${AIRFLOW_SOURCES}/empty" \
AIRFLOW__CORE__PLUGINS_FOLDER="${AIRFLOW_SOURCES}/empty" \
airflow db reset -y
echo
echo "Initialization of virtualenv was successful! Go ahead and develop Airflow!"
echo
exit 0
fi
}
#######################################################################################################
#
# Sets up autocomplete for Breeze for both - bash and zsh
#
# Used globals:
#
# AIRFLOW_SOURCES
# HOME
# OSTYPE
#
#######################################################################################################
function breeze::setup_autocomplete() {
echo "Installing bash/zsh completion for local user"
echo
"${AIRFLOW_SOURCES}/confirm" "This will create ~/.bash_completion.d/ directory and modify ~/.*rc files"
echo
echo
mkdir -pv ~/.bash_completion.d
ln -sf "${AIRFLOW_SOURCES}/breeze-complete" "${HOME}/.bash_completion.d/"
echo
echo "Breeze Bash completion is now linked to: ${AIRFLOW_SOURCES}/breeze-complete"
echo
local breeze_comment="Added by Airflow Breeze autocomplete setup"
if ! grep "${breeze_comment}" "${HOME}/.bashrc" >/dev/null 2>&1; then
touch ~/.bashrc
# shellcheck disable=SC2129
echo "# START: ${breeze_comment}" >>~/.bashrc
cat <<"EOF" >>~/.bashrc
for bcfile in ~/.bash_completion.d/* ; do
. ${bcfile}
done
EOF
echo "# END: ${breeze_comment}" >>~/.bashrc
echo
echo "The ${HOME}/.bashrc has been modified"
echo
else
echo
echo "The ${HOME}/.bashrc was already modified before. Not changing it."
echo
fi
if ! grep "${breeze_comment}" "${HOME}/.zshrc" >/dev/null 2>&1; then
# shellcheck disable=SC2129
echo "# START: ${breeze_comment}" >>~/.zshrc
cat <<"EOF" >>~/.zshrc
autoload compinit && compinit
autoload bashcompinit && bashcompinit
source ~/.bash_completion.d/breeze-complete
EOF
echo "# END: ${breeze_comment}" >>~/.zshrc
echo
echo "The ${HOME}/.zshrc has been modified"
echo
else
echo
echo "The ${HOME}/.zshrc was already modified before. Not changing it."
echo
fi
if [[ "${OSTYPE}" == "darwin"* ]]; then
# For MacOS we have to handle the special case where terminal app DOES NOT run .bashrc by default
# But re-runs .bash_profile :(
# See https://scriptingosx.com/2017/04/about-bash_profile-and-bashrc-on-macos/
if ! grep "${breeze_comment}" "${HOME}/.bash_profile"; then
# shellcheck disable=SC2129
echo "# START: ${breeze_comment}" >>~/.bash_profile
cat <<"EOF" >>~/.bash_profile
if [ -r ~/.bashrc ]; then
source ~/.bashrc
fi
EOF
echo "# END: ${breeze_comment}" >>~/.bash_profile
echo
echo "The ${HOME}/.bash_profile has been modified"
echo
else
echo
echo "The ${HOME}/.bash_profile was already modified before. Not changing it."
echo
fi
fi
echo
echo
echo "Breeze completion is installed to ~/.bash_completion.d/breeze-complete"
echo
echo "Please exit and re-enter your shell or run:"
echo
if [[ "${OSTYPE}" == "darwin"* ]]; then
if grep "${breeze_comment}" "${HOME}/.zshrc" >/dev/null 2>&1; then
echo " source ~/.zshrc"
echo
echo " source ~/.bash_completion.d/breeze-complete"
echo
exec zsh
exit 0
fi
fi
echo " source ~/.bash_completion.d/breeze-complete"
echo
exit 0
}
#######################################################################################################
#
# Prints information about the current configuration of Breeze - if you enter breeze interactively
# and you did not suppress cheatsheet or asciiart, it also prints those. It also prints values
# of constants set by breeze::read_saved_environment_variables() function and other initialization functions.
#
# Used globals:
#
# BACKEND
# POSTGRES_VERSION
# MYSQL_VERSION
# SUPPRESS_CHEATSHEET_FILE
# SUPPRESS_ASCIIART_FILE
# PRODUCTION_IMAGE
# BRANCH_NAME
# AIRFLOW_CI_IMAGE
# AIRFLOW_PROD_IMAGE
# AIRFLOW_VERSION
# INSTALL_AIRFLOW_VERSION
# INSTALL_AIRFLOW_REFERENCE
#
# Outputs:
# Prints the information about the build to stdout.
#
#######################################################################################################
function breeze::print_badge() {
local backend_version=""
if [[ ${BACKEND} == "postgres" ]]; then
backend_version="${POSTGRES_VERSION}"
elif [[ ${BACKEND} == "mysql" ]]; then
backend_version="${MYSQL_VERSION}"
fi
if [[ ! -f "${SUPPRESS_ASCIIART_FILE}" && ${command_to_run} == "enter_breeze" ]]; then
cat <<EOF
@&&&&&&@
@&&&&&&&&&&&@
&&&&&&&&&&&&&&&&
&&&&&&&&&&
&&&&&&&
&&&&&&&
@@@@@@@@@@@@@@@@ &&&&&&
@&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&
&&&&&&&&&&&&
@@&&&&&&&&&&&&&&&@
@&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&
&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&
&&&&&&
&&&&&&&
@&&&&&&&&
@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
@&&&@ && @&&&&&&&&&&& &&&&&&&&&&&& && &&&&&&&&&& &&& &&& &&&
&&& &&& && @&& &&& && && &&& &&&@ &&& &&&&& &&&
&&& &&& && @&&&&&&&&&&&& &&&&&&&&&&& && && &&& &&& &&& &&@ &&&
&&&&&&&&&&& && @&&&&&&&&& && && &&@ &&& &&@&& &&@&&
&&& &&& && @&& &&&@ && &&&&&&&&&&& &&&&&&&&&&&& &&&& &&&&
&&&&&&&&&&&& &&&&&&&&&&&& &&&&&&&&&&&@ &&&&&&&&&&&& &&&&&&&&&&& &&&&&&&&&&&
&&& &&& && &&& && &&& &&&& &&
&&&&&&&&&&&&@ &&&&&&&&&&&& &&&&&&&&&&& &&&&&&&&&&& &&&& &&&&&&&&&&
&&& && && &&&& && &&& &&&& &&
&&&&&&&&&&&&& && &&&&@ &&&&&&&&&&&@ &&&&&&&&&&&& @&&&&&&&&&&& &&&&&&&&&&&
EOF
if [[ ${PRODUCTION_IMAGE} == "true" ]]; then
cat <<EOF
Use production image.
Branch name: ${BRANCH_NAME}
Docker image: ${AIRFLOW_PROD_IMAGE}
Airflow source version: $(build_images::get_airflow_version_from_production_image)
EOF
else
cat <<EOF
Use CI image.
Branch name: ${BRANCH_NAME}
Docker image: ${AIRFLOW_CI_IMAGE_WITH_TAG}
Airflow source version: ${AIRFLOW_VERSION}
EOF
fi
cat <<EOF
Python version: ${PYTHON_MAJOR_MINOR_VERSION}
Backend: ${BACKEND} ${backend_version}
EOF
if [[ -n ${USE_AIRFLOW_VERSION=} ]]; then
cat <<EOF
Airflow used at runtime: ${USE_AIRFLOW_VERSION=}
EOF
fi
else
if [[ ${PRODUCTION_IMAGE} == "true" ]]; then
cat <<EOF
Production image.
Branch name: ${BRANCH_NAME}
Docker image: ${AIRFLOW_PROD_IMAGE}
EOF
else
cat <<EOF
CI image.
Branch name: ${BRANCH_NAME}
Docker image: ${AIRFLOW_CI_IMAGE}
EOF
fi
if [[ -n ${INSTALL_AIRFLOW_VERSION=} || -n ${INSTALL_AIRFLOW_REFERENCE=} ]]; then
cat <<EOF
Airflow version installed: ${INSTALL_AIRFLOW_VERSION=}${INSTALL_AIRFLOW_REFERENCE=}
EOF
fi
cat <<EOF
Airflow source version: ${AIRFLOW_VERSION}
Python version: ${PYTHON_MAJOR_MINOR_VERSION}
Backend: ${BACKEND} ${backend_version}
EOF
fi
if [[ ${VERBOSE} == "true" ]]; then
initialization::summarize_build_environment
fi
}
#######################################################################################################
#
# Prepares command file that can be used to easily run the docker commands outside of Breeze.
#
# The command file generated in cache ./build directory is a standalone script that contains
# All the environment variables and docker-compose configuration to run the command.
# This is because depending on configuration of Breeze we might have different compose files
# used and different env variables set.
#
# Those are a convenience scripts that you might use to debug command execution although
# In most cases they are used internally by Breeze.
#
# Arguments:
#
# file to prepare
# command to run
# compose_file to use
# airflow_image to use
#
# Outputs:
# Creates the convenience command file that can be run to use the docker command.
#
#######################################################################################################
function breeze::prepare_command_file() {
local file="${1}"
local command="${2}"
local compose_file="${3}"
cat <<EOF >"${file}"
#!/usr/bin/env bash
docker_compose_version=\$(docker-compose --version || true)
if [[ \${docker_compose_version} =~ .*([0-9]+)\.([0-9]+)\.([0-9]+).* ]]; then
major=\${BASH_REMATCH[1]}
minor=\${BASH_REMATCH[2]}
patch=\${BASH_REMATCH[3]}
if [[ \${major} == "1" ]]; then
if (( minor < 29 )); then
echo
echo "${COLOR_RED}You have too old version of docker-compose: \${major}.\${minor}.\${patch}! At least 1.29 is needed! Please upgrade!${COLOR_RESET}"
echo "${COLOR_RED}See https://docs.docker.com/compose/install/ for instructions. Make sure docker-compose you install is first on the PATH variable of yours.${COLOR_RESET}"
echo
exit 1
fi
fi
echo
echo "${COLOR_GREEN}Good version of docker-compose: \${major}.\${minor}.\${patch}${COLOR_RESET}"
echo
else
echo
echo "${COLOR_YELLOW}Unknown docker-compose version. At least 1.29 is needed! If Breeze fails - upgrade to latest available docker-compose version${COLOR_RESET}"
echo
fi
if [[ \${VERBOSE} == "true" ]]; then
echo
echo "Executing script:"
echo
echo "${COLOR_CYAN}${file} \${@}${COLOR_RESET}"
echo
set -x
fi
cd "\$( dirname "\${BASH_SOURCE[0]}" )" || exit
export HOST_USER_ID=${HOST_USER_ID}
export HOST_GROUP_ID=${HOST_GROUP_ID}
export COMPOSE_FILE="${compose_file}"
export PYTHON_MAJOR_MINOR_VERSION="${PYTHON_MAJOR_MINOR_VERSION}"
export BACKEND="${BACKEND}"
export AIRFLOW_VERSION="${AIRFLOW_VERSION}"
export INSTALL_AIRFLOW_VERSION="${INSTALL_AIRFLOW_VERSION}"
export SSH_PORT="${SSH_PORT}"
export WEBSERVER_HOST_PORT="${WEBSERVER_HOST_PORT}"
export FLOWER_HOST_PORT="${FLOWER_HOST_PORT}"
export REDIS_HOST_PORT="${REDIS_HOST_PORT}"
export POSTGRES_HOST_PORT="${POSTGRES_HOST_PORT}"
export POSTGRES_VERSION="${POSTGRES_VERSION}"
export MYSQL_HOST_PORT="${MYSQL_HOST_PORT}"
export MYSQL_VERSION="${MYSQL_VERSION}"
export MSSQL_HOST_PORT="${MSSQL_HOST_PORT}"
export MSSQL_VERSION="${MSSQL_VERSION}"
export AIRFLOW_SOURCES="${AIRFLOW_SOURCES}"
export AIRFLOW_CI_IMAGE="${AIRFLOW_CI_IMAGE}"
export AIRFLOW_CI_IMAGE_WITH_TAG="${AIRFLOW_CI_IMAGE_WITH_TAG}"
export AIRFLOW_PROD_IMAGE="${AIRFLOW_PROD_IMAGE}"
export AIRFLOW_IMAGE_KUBERNETES="${AIRFLOW_IMAGE_KUBERNETES}"
export SQLITE_URL="${SQLITE_URL}"
export USE_AIRFLOW_VERSION="${USE_AIRFLOW_VERSION}"
export SKIP_TWINE_CHECK="${SKIP_TWINE_CHECK}"
export USE_PACKAGES_FROM_DIST="${USE_PACKAGES_FROM_DIST}"
export EXECUTOR="${EXECUTOR}"
export START_AIRFLOW="${START_AIRFLOW}"
export ENABLED_INTEGRATIONS="${ENABLED_INTEGRATIONS}"
export ENABLED_SYSTEMS="${ENABLED_SYSTEMS}"
export GITHUB_ACTIONS="${GITHUB_ACTIONS}"
export ISSUE_ID="${ISSUE_ID}"
export NUM_RUNS="${NUM_RUNS}"
export VERSION_SUFFIX_FOR_SVN="${VERSION_SUFFIX_FOR_SVN}"
export VERSION_SUFFIX_FOR_PYPI="${VERSION_SUFFIX_FOR_PYPI}"
docker-compose ${command}
EOF
chmod u+x "${file}"
}
#######################################################################################################
#
# Prepare all command files that we are using. We use dc_ci - to run docker compose command for CI image
#
# Global constants set:
#
# PYTHON_BASE_IMAGE
# AIRFLOW_CI_IMAGE
# BUILT_CI_IMAGE_FLAG_FILE
#
#######################################################################################################
function breeze::prepare_command_files() {
local main_ci_docker_compose_file=${SCRIPTS_CI_DIR}/docker-compose/base.yml
local backend_docker_compose_file=${SCRIPTS_CI_DIR}/docker-compose/backend-${BACKEND}.yml
local backend_port_docker_compose_file=${SCRIPTS_CI_DIR}/docker-compose/backend-${BACKEND}-port.yml
local local_docker_compose_file=${SCRIPTS_CI_DIR}/docker-compose/local.yml
local local_all_sources_docker_compose_file=${SCRIPTS_CI_DIR}/docker-compose/local-all-sources.yml
local files_docker_compose_file=${SCRIPTS_CI_DIR}/docker-compose/files.yml
local remove_sources_docker_compose_file=${SCRIPTS_CI_DIR}/docker-compose/remove-sources.yml
local forward_credentials_docker_compose_file=${SCRIPTS_CI_DIR}/docker-compose/forward-credentials.yml
if [[ ${BACKEND} == "mssql" ]]; then
local docker_filesystem
docker_filesystem=$(stat "-f" "-c" "%T" /var/lib/docker 2>/dev/null || echo "unknown")
if [[ ${docker_filesystem} == "tmpfs" ]]; then
# In case of tmpfs backend for docker, mssql fails because TMPFS does not support
# O_DIRECT parameter for direct writing to the filesystem
# https://github.com/microsoft/mssql-docker/issues/13
# so we need to mount an external volume for its db location
# specified by MSSQL_DATA_VOLUME
backend_docker_compose_file="${backend_docker_compose_file}:${SCRIPTS_CI_DIR}/docker-compose/backend-mssql-bind-volume.yml"
else
backend_docker_compose_file="${backend_docker_compose_file}:${SCRIPTS_CI_DIR}/docker-compose/backend-mssql-docker-volume.yml"
fi
fi
local compose_ci_file=${main_ci_docker_compose_file}:${backend_docker_compose_file}:${files_docker_compose_file}
if [[ "${MOUNT_SELECTED_LOCAL_SOURCES}" != "false" ]]; then
compose_ci_file=${compose_ci_file}:${local_docker_compose_file}:${backend_port_docker_compose_file}
fi
if [[ "${MOUNT_ALL_LOCAL_SOURCES}" != "false" ]]; then
compose_ci_file=${compose_ci_file}:${local_all_sources_docker_compose_file}:${backend_port_docker_compose_file}
fi
if [[ ${FORWARD_CREDENTIALS} == "true" ]]; then
compose_ci_file=${compose_ci_file}:${forward_credentials_docker_compose_file}
fi
if [[ -n ${INSTALL_AIRFLOW_VERSION=} || -n ${INSTALL_AIRFLOW_REFERENCE} || -n ${USE_AIRFLOW_VERSION=} ]]; then
compose_ci_file=${compose_ci_file}:${remove_sources_docker_compose_file}
fi
set +u
local unique_integrations
# shellcheck disable=SC2207
unique_integrations=($(echo "${INTEGRATIONS[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
local integration
for integration in "${unique_integrations[@]}"; do
compose_ci_file=${compose_ci_file}:${SCRIPTS_CI_DIR}/docker-compose/integration-${integration}.yml
done
set -u
export DOCKER_COMPOSE_RUN_SCRIPT_FOR_CI="dc_ci"
readonly DOCKER_COMPOSE_RUN_SCRIPT_FOR_CI
breeze::prepare_command_file "${BUILD_CACHE_DIR}/${DOCKER_COMPOSE_RUN_SCRIPT_FOR_CI}" \
"\"\${@}\"" "${compose_ci_file}"
}
#######################################################################################################
#
# Prints detailed help for all commands and flags. Used to generate documentation added to BREEZE.rst
# automatically.
#
# Used global variables:
# _breeze_all_commands
#
# Outputs:
# Prints detailed help for all commands to stdout.
#
#######################################################################################################
function breeze::do_help_all() {
echo
breeze::print_line
breeze::usage
breeze::print_line
echo
echo
echo "Detailed usage"
echo
breeze::print_line
echo
local subcommand
# shellcheck disable=SC2154
for subcommand in ${_breeze_all_commands}; do
breeze::detailed_usage "${subcommand}"
breeze::print_line
echo
done
echo
breeze::flags
}
#######################################################################################################
#
# Parses all arguments that can be passed to Breeze command - that includes command to run and flags.
#
# Used global variables:
# _breeze_getopt_short_options
# _breeze_getopt_long_options
# _breeze_allowed_integrations
#
# Updated global constants:
# By the end of this function, all the constants from `initialization::make_constants_read_only`
# function are set and they are set as read-only.
#
#######################################################################################################
function breeze::parse_arguments() {
set -u
local params
if ! params=$(getopt \
-o "${_breeze_getopt_short_options:=}" \
-l "${_breeze_getopt_long_options:=}" \
--name "$CMDNAME" -- "$@"); then
breeze::flags
exit 1
fi
eval set -- "${params}"
unset params
# Parse Flags.
# Please update short and long options in the breeze-complete script
# This way autocomplete will work out-of-the-box
while true; do
case "${1}" in
-h | --help)
run_help="true"
shift
;;
-p | --python)
export PYTHON_MAJOR_MINOR_VERSION="${2}"
echo "Python version: ${PYTHON_MAJOR_MINOR_VERSION}"
echo
shift 2
;;
-b | --backend)
export BACKEND="${2}"
echo "Backend: ${BACKEND}"
echo
shift 2
;;
-i | --integration)
local INTEGRATION=${2}
parameters::check_and_save_allowed_param "INTEGRATION" "integration" "--integration"
echo "Integration: ${INTEGRATION}"
if [[ ${INTEGRATION} == "all" ]]; then
# shellcheck disable=SC2154
for INTEGRATION in ${_breeze_allowed_integrations}; do
if [[ ${INTEGRATION} != "all" ]]; then
echo "${INTEGRATION}"
INTEGRATIONS+=("${INTEGRATION}")
fi
done
else
INTEGRATIONS+=("${INTEGRATION}")
fi
if [[ " ${INTEGRATIONS[*]} " =~ " trino " ]]; then
INTEGRATIONS+=("kerberos");
fi
echo
shift 2
;;
-K | --kubernetes-mode)
export KUBERNETES_MODE="${2}"
echo "Kubernetes mode: ${KUBERNETES_MODE}"
echo
shift 2
;;
-V | --kubernetes-version)
export KUBERNETES_VERSION="${2}"
echo "Kubernetes version: ${KUBERNETES_VERSION}"
echo
shift 2
;;
--kind-version)
export KIND_VERSION="${2}"
echo "Kind version: ${KIND_VERSION}"
echo
shift 2
;;
--executor)
export EXECUTOR="${2}"
echo "Using ${EXECUTOR} in cluster"
echo
shift 2
;;
--helm-version)
export HELM_VERSION="${2}"
echo "Helm version: ${HELM_VERSION}"
echo
shift 2
;;
--postgres-version)
export POSTGRES_VERSION="${2}"
echo "Postgres version: ${POSTGRES_VERSION}"
echo
shift 2
;;
--mysql-version)
export MYSQL_VERSION="${2}"
echo "MySQL version: ${MYSQL_VERSION}"
echo
shift 2
;;
--mssql-version)
export MSSQL_VERSION="${2}"
echo "MSSQL version: ${MSSQL_VERSION}"
echo
shift 2
;;
-l | --skip-mounting-local-sources)
MOUNT_SELECTED_LOCAL_SOURCES="false"
MOUNT_ALL_LOCAL_SOURCES="false"
echo "Mount selected local sources: ${MOUNT_SELECTED_LOCAL_SOURCES}"
echo "Mount all local sources: ${MOUNT_ALL_LOCAL_SOURCES}"
echo
shift
;;
--mount-all-local-sources)
MOUNT_ALL_LOCAL_SOURCES="true"
MOUNT_SELECTED_LOCAL_SOURCES="false"
echo "Mount selected local sources: ${MOUNT_SELECTED_LOCAL_SOURCES}"
echo "Mount all local sources: ${MOUNT_ALL_LOCAL_SOURCES}"
echo
shift
;;
-a | --install-airflow-version)
INSTALL_AIRFLOW_VERSION="${2}"
# Reference is mutually exclusive with version
INSTALL_AIRFLOW_REFERENCE=""
echo "Installs version of Airflow: ${INSTALL_AIRFLOW_VERSION}"
echo
shift 2
;;
-t | --install-airflow-reference)
INSTALL_AIRFLOW_REFERENCE="${2}"
# Reference is mutually exclusive with version
INSTALL_AIRFLOW_VERSION=""
# Skip mounting local sources when airflow is installed from remote
INSTALL_PROVIDERS_FROM_SOURCES="false"
echo "Installs Airflow from reference: ${INSTALL_AIRFLOW_REFERENCE}"
echo
shift 2
;;
--use-airflow-version)
USE_AIRFLOW_VERSION="${2}"
MOUNT_SELECTED_LOCAL_SOURCES="false"
MOUNT_ALL_LOCAL_SOURCES="false"
DB_RESET="true"
echo "Uses Airflow at runtime from: ${USE_AIRFLOW_VERSION}, reset DB and skip mounting local sources"
echo
shift 2
;;
-d | --db-reset)
echo "Resetting the DB!"
echo
export DB_RESET="true"
shift
;;
-v | --verbose)
export VERBOSE="true"
echo "Verbose output"
echo
shift
;;
-y | --assume-yes)
export FORCE_ANSWER_TO_QUESTIONS="yes"
echo "Assuming 'yes' answer to all questions."
echo
shift
;;
-n | --assume-no)
export FORCE_ANSWER_TO_QUESTIONS="no"
echo "Assuming 'no' answer to all questions."
echo
shift
;;
-q | --assume-quit)
export FORCE_ANSWER_TO_QUESTIONS="quit"
echo "Assuming 'quit' answer to all questions."
echo
shift
;;
-F | --force-build-images)
echo "Force build images"
echo
export FORCE_BUILD_IMAGES="true"
# if you want to force build an image - assume you want to build it :)
export FORCE_ANSWER_TO_QUESTIONS="yes"
shift
;;
-C | --force-clean-images)
echo "Clean build of images without cache"
echo
export DOCKER_CACHE="disabled"
# if not set here, docker cached is determined later, depending on type of image to be built
export FORCE_BUILD_IMAGES="true"
shift
;;
-r | --skip-rebuild-check)
echo "Skips checking image for rebuilds"
echo
export CHECK_IMAGE_FOR_REBUILD="false"
export SKIP_BUILDING_PROD_IMAGE="true"
shift
;;
-L | --build-cache-local)
echo "Use local cache to build images"
echo
export DOCKER_CACHE="local"
# if not set here, docker cached is determined later, depending on type of image to be built
shift
;;
-U | --build-cache-pulled)
echo "Use pulled cache to build images"
echo
export DOCKER_CACHE="pulled"
# if not set here, docker cached is determined later, depending on type of image to be built
shift
;;
-X | --build-cache-disabled)
echo "Use disabled cache to build images"