forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreeze
executable file
·1323 lines (1126 loc) · 47.1 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
MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Bash arrays need to be defined outside of functions unfortunately :(
# Array with extra options for Docker compose
declare -a EXTRA_DC_OPTIONS
# Array with selected integrations
declare -a INTEGRATIONS
# This is where remaining args are passed
declare -a REMAINING_ARGS
# This is where static check options are defined
declare -a EXTRA_STATIC_CHECK_OPTIONS
function setup_default_breeze_variables() {
# Whether to actually run docker compose with the command set given
COMMAND_TO_RUN="enter_breeze"
export BREEZE=true
export AIRFLOW_SOURCES="${MY_DIR}"
# Directory where all CI scripts are located
SCRIPTS_CI_DIR="${MY_DIR}/scripts/ci"
BUILD_CACHE_DIR="${MY_DIR}/.build"
FILES_DIR="${MY_DIR}/files"
TMP_DIR="${MY_DIR}/tmp"
mkdir -pv "${BUILD_CACHE_DIR}"
mkdir -pv "${TMP_DIR}"
mkdir -pv "${FILES_DIR}"
# Note - we do not use __script_init.sh here because it can only be used from within
# the CI directory and we need to overrride PYTHON_VERSION based on what we store
# in the .build directory
# Beginning of the initialisation here
# shellcheck source=scripts/ci/_utils.sh
. "${SCRIPTS_CI_DIR}/_utils.sh"
export PYTHON_VERSION="${PYTHON_VERSION:=$(read_from_file PYTHON_VERSION)}"
# Sets width of the screen
SEPARATOR_WIDTH="$(tput cols)"
# Name of the script
CMDNAME="$(basename -- "$0")"
# Update short and long options in the breeze-complete script
# This way autocomplete will work automatically with all options
# shellcheck source=breeze-complete
. "${MY_DIR}/breeze-complete"
# Skips mounting local Airflow sources
SKIP_MOUNTING_LOCAL_SOURCES="false"
# Holds chosen command if the -x flag is used.
RUN_COMMAND=""
# Holds the test target if the -t flag is used.
TEST_TARGET=""
# Holds docker compose command if the -d flag is used.
DOCKER_COMPOSE_COMMAND=""
# If true, the docker images are rebuilt locally.
export NEEDS_DOCKER_BUILD="false"
# By default we only pull images if we do not have them locally.
# This can be overridden by -p flag
export FORCE_PULL_IMAGES="false"
# Runtime is empty initially (might be set to kubernetes in case kubernetes is chosen)
RUNTIME=""
# Do not enable Kind Kubernetes cluster by default
export ENABLE_KIND_CLUSTER="false"
# We use docker image caches by default to speed up the builds
export USE_PULLED_IMAGES_AS_CACHE=${USE_PULLED_IMAGES_AS_CACHE:="true"}
# By default we do not push images. This can be overridden by -u flag.
export PUSH_IMAGES=${PUSH_IMAGES:="false"}
# Forward credentials to docker
export FORWARD_CREDENTIALS="false"
# If install released airflow 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=${INSTALL_AIRFLOW_VERSION:="current"}
# Determine version of the Airflow from version.py
AIRFLOW_VERSION=$(cat airflow/version.py - << EOF | python
print(version.replace("+",""))
EOF
)
export AIRFLOW_VERSION
# Verbosity in running ci scripts
export VERBOSE="false"
# Whether to force build without checking if it is needed
export FORCE_BUILD_IMAGES=${FORCE_BUILD_IMAGES:="false"}
# Files determining whether asciiart/cheatsheet are suppressed
SUPPRESS_CHEATSHEET_FILE="${MY_DIR}/.suppress_cheatsheet"
SUPPRESS_ASCIIART_FILE="${MY_DIR}/.suppress_asciiart"
# Default values for flags
_BREEZE_DEFAULT_BACKEND="sqlite"
_BREEZE_DEFAULT_KUBERNETES_MODE="git_mode"
_BREEZE_DEFAULT_KUBERNETES_VERSION="v1.15.3"
_BREEZE_DEFAULT_INSTALL_AIRFLOW_VERSION="current"
STATIC_CHECK_PYTHON_VERSION=3.6
}
# End of initialisation here
function initialize_virtualenv() {
# Check if we are in virtualenv
set +e
echo -e "import sys\nif not hasattr(sys,'base_prefix'):\n sys.exit(1)" | "python${PYTHON_VERSION}"
RES=$?
set -e
if [[ ${RES} != "0" ]]; then
echo >&2
echo >&2 "ERROR: Initializing local virtualenv only works when you have virtualenv activated"
echo >&2
echo >&2 "Please enter your local virtualenv before (for example using 'workon') "
echo >&2
exit 1
else
# If no Airflow Home defined - fallback to ${HOME}/airflow
AIRFLOW_HOME_DIR=${AIRFLOW_HOME:=${HOME}/airflow}
export CASS_DRIVER_NO_CYTHON="1"
echo
echo "Initializing the virtualenv: $(command -v python)!"
echo
echo "This will wipe out ${AIRFLOW_HOME_DIR} and reset all the databases!"
echo
"${MY_DIR}/confirm" "Proceeding with the initialization"
echo
pushd "${MY_DIR}"
set +e
pip install -e ".[devel]"
RES=$?
set -e
popd
if [[ ${RES} != "0" ]]; then
echo "#######################################################################"
echo " You had some troubles installing the venv !!!!!"
echo " Try runnning the command below and rerun virtualenv installation"
echo
SYSTEM=$(uname -s)
if [[ ${SYSTEM} == "Darwin" ]]; then
echo " brew install sqlite mysql postgresql"
else
echo " sudo apt install build-essentials python3.6-dev python3.7-dev python-dev openssl sqlite sqlite-dev default-libmysqlclient-dev libmysqld-dev postgresql"
fi
echo
echo "#######################################################################"
exit ${RES}
fi
echo
echo "Wiping and recreating ${AIRFLOW_HOME_DIR}"
echo
rm -rvf "${AIRFLOW_HOME_DIR}"
mkdir -p "${AIRFLOW_HOME_DIR}"
echo
echo "Resetting AIRFLOW sqlite database"
echo
unset AIRFLOW__CORE__UNIT_TEST_MODE
airflow db reset -y
echo
echo "Resetting AIRFLOW sqlite unit test database"
echo
export AIRFLOW__CORE__UNIT_TEST_MODE=True
airflow db reset -y
exit 0
fi
}
function setup_autocomplete() {
echo "Installing bash/zsh completion for local user"
echo "Note that completion for zsh is just limited to flags - without their values"
echo
echo
set +e
grep ".bash_completion.d" "${HOME}/.bashrc" >/dev/null 2>&1
RES=$?
set -e
if [[ "${RES}" == "0" ]]; then
echo >&2
echo >&2 "ERROR: Bash completion already setup before."
echo >&2
exit 1
fi
"${MY_DIR}/confirm" "This will create ~/.bash_completion.d/ directory and modify ~/.bashrc and ~/.zshrc file"
echo
echo
mkdir -pv ~/.bash_completion.d
ln -sf "${MY_DIR}/breeze-complete" "${HOME}/.bash_completion.d/"
touch ~/.bashrc
cat >>~/.bashrc <<"EOF"
for BCFILE in ~/.bash_completion.d/* ; do
. ${BCFILE}
done
EOF
cat >>~/.zshrc <<"EOF"
autoload compinit && compinit
autoload bashcompinit && bashcompinit
source ~/.bash_completion.d/breeze-complete
EOF
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/
set +e
grep ".bashrc" "${HOME}/.bash_profile"
RES=$?
set -e
if [[ "${RES}" == "0" ]]; then
echo " Seems you already source .bashrc in your .bash_profile so not adding it."
else
"${MY_DIR}/confirm" "This will modify ~/.bash_profile and source .bashrc from it"
echo
echo
cat >>~/.bash_profile <<"EOF"
if [ -r ~/.bashrc ]; then
source ~/.bashrc
fi
EOF
fi
fi
echo
echo
echo "Breeze bash completion installed to ~/.bash_completion.d/breeze-complete"
echo
echo
echo "Please re-enter bash or run '. ~/.bash_completion.d/breeze-complete'"
echo
exit 0
}
function print_badge {
if [[ ! -f "${SUPPRESS_ASCIIART_FILE}" ]]; then
cat <<EOF
@&&&&&&@
@&&&&&&&&&&&@
&&&&&&&&&&&&&&&&
&&&&&&&&&&
&&&&&&&
&&&&&&&
@@@@@@@@@@@@@@@@ &&&&&&
@&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&
&&&&&&&&&&&&
@@&&&&&&&&&&&&&&&@
@&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&
&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&
&&&&&&
&&&&&&&
@&&&&&&&&
@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
@&&&@ && @&&&&&&&&&&& &&&&&&&&&&&& && &&&&&&&&&& &&& &&& &&&
&&& &&& && @&& &&& && && &&& &&&@ &&& &&&&& &&&
&&& &&& && @&&&&&&&&&&&& &&&&&&&&&&& && && &&& &&& &&& &&@ &&&
&&&&&&&&&&& && @&&&&&&&&& && && &&@ &&& &&@&& &&@&&
&&& &&& && @&& &&&@ && &&&&&&&&&&& &&&&&&&&&&&& &&&& &&&&
&&&&&&&&&&&& &&&&&&&&&&&& &&&&&&&&&&&@ &&&&&&&&&&&& &&&&&&&&&&& &&&&&&&&&&&
&&& &&& && &&& && &&& &&&& &&
&&&&&&&&&&&&@ &&&&&&&&&&&& &&&&&&&&&&& &&&&&&&&&&& &&&& &&&&&&&&&&
&&& && && &&&& && &&& &&&& &&
&&&&&&&&&&&&& && &&&&@ &&&&&&&&&&&@ &&&&&&&&&&&& @&&&&&&&&&&& &&&&&&&&&&&
Branch name: ${BRANCH_NAME}
Docker image: ${AIRFLOW_CI_IMAGE}
Airflow source version: ${AIRFLOW_VERSION}
Airflow installed: ${INSTALL_AIRFLOW_VERSION}
Python version: ${PYTHON_VERSION}
DockerHub user: ${DOCKERHUB_USER}
DockerHub repo: ${DOCKERHUB_REPO}
Backend: ${BACKEND}
EOF
if [[ ${RUNTIME} == "kubernetes" ]]; then
cat <<EOF
Kubernetes RUNTIME
Kubernetes mode: ${KUBERNETES_MODE}
Kubernetes version: ${KUBERNETES_VERSION}
Enable kind: ${ENABLE_KIND_CLUSTER}
Cluster operation: ${KIND_CLUSTER_OPERATION}
EOF
fi
else
cat <<EOF
Branch name: ${BRANCH_NAME}
Docker image: ${AIRFLOW_CI_IMAGE}
Airflow source version: ${AIRFLOW_VERSION}
Airflow installed: ${INSTALL_AIRFLOW_VERSION}
Python version: ${PYTHON_VERSION}
DockerHub user: ${DOCKERHUB_USER}
DockerHub repo: ${DOCKERHUB_REPO}
Backend: ${BACKEND}
EOF
if [[ ${RUNTIME} == "kubernetes" ]]; then
cat <<EOF
Kubernetes RUNTIME
Kubernetes mode: ${KUBERNETES_MODE}
Kubernetes version: ${KUBERNETES_VERSION}
Enable kind: ${ENABLE_KIND_CLUSTER}
Cluster operation: ${KIND_CLUSTER_OPERATION}
EOF
fi
fi
}
function prepare_command_file() {
local FILE="${1}"
local CMD="${2}"
local TESTS="${3}"
local EXPANSION="${4-@}"
cat <<EOF > "${FILE}"
#!/usr/bin/env bash
cd "\$(pwd)" || exit
export DOCKERHUB_USER=${DOCKERHUB_USER}
export DOCKERHUB_REPO=${DOCKERHUB_REPO}
export COMPOSE_FILE="${COMPOSE_FILE}"
export PYTHON_VERSION="${PYTHON_VERSION}"
export BACKEND="${BACKEND}"
export RUNTIME="${RUNTIME}"
export ENABLE_KIND_CLUSTER="${ENABLE_KIND_CLUSTER}"
export KUBERNETES_MODE="${KUBERNETES_MODE}"
export KUBERNETES_VERSION="${KUBERNETES_VERSION}"
export AIRFLOW_VERSION="${AIRFLOW_VERSION}"
export INSTALL_AIRFLOW_VERSION="${INSTALL_AIRFLOW_VERSION}"
export RUN_TESTS="${TESTS}"
export WEBSERVER_HOST_PORT="${WEBSERVER_HOST_PORT}"
export POSTGRES_HOST_PORT="${POSTGRES_HOST_PORT}"
export MYSQL_HOST_PORT="${MYSQL_HOST_PORT}"
export AIRFLOW_CI_IMAGE="${AIRFLOW_CI_IMAGE}"
docker-compose --log-level INFO ${CMD}\$${EXPANSION}"
EOF
chmod u+x "${FILE}"
}
function prepare_command_files() {
MAIN_DOCKER_COMPOSE_FILE=${SCRIPTS_CI_DIR}/docker-compose/base.yml
BACKEND_DOCKER_COMPOSE_FILE=${SCRIPTS_CI_DIR}/docker-compose/backend-${BACKEND}.yml
LOCAL_DOCKER_COMPOSE_FILE=${SCRIPTS_CI_DIR}/docker-compose/local.yml
KUBERNETES_DOCKER_COMPOSE_FILE=${SCRIPTS_CI_DIR}/docker-compose/runtime-kubernetes.yml
REMOVE_SOURCES_DOCKER_COMPOSE_FILE=${SCRIPTS_CI_DIR}/docker-compose/remove-sources.yml
FORWARD_CREDENTIALS_DOCKER_COMPOSE_FILE=${SCRIPTS_CI_DIR}/docker-compose/forward-credentials.yml
COMPOSE_FILE=${MAIN_DOCKER_COMPOSE_FILE}:${BACKEND_DOCKER_COMPOSE_FILE}
if [[ "${SKIP_MOUNTING_LOCAL_SOURCES}" != "true" ]]; then
COMPOSE_FILE=${COMPOSE_FILE}:${LOCAL_DOCKER_COMPOSE_FILE}
fi
if [[ ${FORWARD_CREDENTIALS} == "true" ]]; then
COMPOSE_FILE=${COMPOSE_FILE}:${FORWARD_CREDENTIALS_DOCKER_COMPOSE_FILE}
fi
if [[ ${INSTALL_AIRFLOW_VERSION} != "current" ]]; then
COMPOSE_FILE=${COMPOSE_FILE}:${REMOVE_SOURCES_DOCKER_COMPOSE_FILE}
fi
if [[ ${RUNTIME} == "kubernetes" ]]; then
COMPOSE_FILE=${COMPOSE_FILE}:${KUBERNETES_DOCKER_COMPOSE_FILE}
fi
set +u
# shellcheck disable=SC2207
UNIQUE_INTEGRATIONS=($(echo "${INTEGRATIONS[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
for _INT in "${UNIQUE_INTEGRATIONS[@]}"
do
COMPOSE_FILE=${COMPOSE_FILE}:${SCRIPTS_CI_DIR}/docker-compose/integration-${_INT}.yml
done
set -u
export COMPOSE_FILE
CI_ENTRYPOINT_FILE="/opt/airflow/scripts/ci/in_container/entrypoint_ci.sh"
# Base python image for the build
export PYTHON_BASE_IMAGE=python:${PYTHON_VERSION}-slim-stretch
export AIRFLOW_CI_IMAGE="${DOCKERHUB_USER}/${DOCKERHUB_REPO}:${BRANCH_NAME}-python${PYTHON_VERSION}-ci"
export BUILT_IMAGE_FLAG_FILE="${BUILD_CACHE_DIR}/${BRANCH_NAME}/.built_${PYTHON_VERSION}"
DC_RUN_COMMAND="run --service-ports --rm airflow-testing \"${CI_ENTRYPOINT_FILE} "
LAST_DC_RUN_FILE="cmd_run"
LAST_DC_TEST_FILE="test_run"
LAST_DC_FILE="dc"
# Prepare script for "run command"
prepare_command_file "${BUILD_CACHE_DIR}/${LAST_DC_RUN_FILE}" "${DC_RUN_COMMAND}" "false" '*'
# Prepare script for "run test"
prepare_command_file "${BUILD_CACHE_DIR}/${LAST_DC_TEST_FILE}" "${DC_RUN_COMMAND}" "true" '*'
# Prepare script for "run docker compose command"
prepare_command_file "${BUILD_CACHE_DIR}/${LAST_DC_FILE}" '"' "false"
}
function parse_arguments() {
set -u
if ! PARAMS=$(getopt \
-o "${_BREEZE_GETOPT_SHORT_OPTIONS:=}" \
-l "${_BREEZE_GETOPT_LONG_OPTIONS:=}" \
--name "$CMDNAME" -- "$@")
then
usage
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)
usage;
exit 0 ;;
-P|--python)
export PYTHON_VERSION="${2}";
echo "Python version: ${PYTHON_VERSION}"
echo
shift 2 ;;
-B|--backend)
export BACKEND="${2}";
echo "Backend: ${BACKEND}"
echo
shift 2 ;;
-I|--integration)
INTEGRATION=${2}
check_and_save_allowed_param "INTEGRATION" "integration" "--integration"
echo "Integration: ${INTEGRATION}"
if [[ ${INTEGRATION} == "all" ]]; then
for _INT in ${_BREEZE_ALLOWED_INTEGRATIONS}
do
if [[ ${_INT} != "all" ]]; then
echo "${_INT}"
INTEGRATIONS+=("${_INT}")
fi
done
else
INTEGRATIONS+=("${INTEGRATION}");
fi
echo
shift 2 ;;
-K|--start-kind-cluster)
export RUNTIME=kubernetes
export ENABLE_KIND_CLUSTER="true"
export KIND_CLUSTER_OPERATION="start"
echo "Starting kubernetes cluster"
echo
shift ;;
-z|--recreate-kind-cluster)
export RUNTIME=kubernetes
export ENABLE_KIND_CLUSTER="true"
export KIND_CLUSTER_OPERATION="recreate"
echo "Recreating kind cluster"
echo
shift ;;
-X|--stop-kind-cluster)
export RUNTIME=kubernetes
export ENABLE_KIND_CLUSTER="true"
export KIND_CLUSTER_OPERATION="stop"
echo "Stop kind cluster"
echo
shift ;;
-M|--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 ;;
-s|--skip-mounting-local-sources)
SKIP_MOUNTING_LOCAL_SOURCES="true"
echo "Skip mounting local sources: ${SKIP_MOUNTING_LOCAL_SOURCES}"
echo
shift ;;
-N|--install-airflow-version)
INSTALL_AIRFLOW_VERSION="${2}"
echo "Installs version of Airflow: ${INSTALL_AIRFLOW_VERSION}"
echo
shift 2 ;;
-b|--build-only)
COMMAND_TO_RUN="build_ci_images_only"
# if you want to build an image - assume you want to build it :)
export FORCE_ANSWER_TO_QUESTIONS="yes"
# and assume you want to build it no matter if it is needed
export FORCE_BUILD_IMAGES="true"
echo "Only build. Do not enter airflow-testing container"
echo
shift ;;
-v|--verbose)
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 ;;
-C|--toggle-suppress-cheatsheet)
if [[ -f "${SUPPRESS_CHEATSHEET_FILE}" ]]; then
rm -f "${SUPPRESS_CHEATSHEET_FILE}"
else
touch "${SUPPRESS_CHEATSHEET_FILE}"
fi
echo "Toggle suppress cheatsheet"
echo
shift ;;
-A|--toggle-suppress-asciiart)
if [[ -f "${SUPPRESS_ASCIIART_FILE}" ]]; then
rm -f "${SUPPRESS_ASCIIART_FILE}"
else
touch "${SUPPRESS_ASCIIART_FILE}"
fi
echo "Toggle suppress asciiart"
echo
shift ;;
-r|--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 ;;
-R|--force-clean-images)
echo "Clean build of images without cache"
echo
export USE_PULLED_IMAGES_AS_CACHE="false"
export FORCE_BUILD_IMAGES="true"
shift ;;
-L|--use-local-cache)
echo "Use local cache to build images"
echo
export USE_NO_CACHE="false"
export USE_PULLED_IMAGES_AS_CACHE="false"
shift ;;
-p|--force-pull-images)
echo "Force pulling images before build. Uses pulled images as cache."
echo
export FORCE_PULL_IMAGES="true"
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 ;;
-D|--dockerhub-user)
export DOCKERHUB_USER="${2}"
echo "Dockerhub user ${DOCKERHUB_USER}"
echo
shift 2 ;;
-H|--dockerhub-repo)
export DOCKERHUB_REPO="${2}"
echo "Dockerhub repo ${DOCKERHUB_REPO}"
echo
shift 2 ;;
-u|--push-images)
echo
echo "Pushing images to DockerHub"
echo
export PUSH_IMAGES="true"
export FORCE_BUILD_IMAGES="true"
shift ;;
-c|--cleanup-image)
echo "Cleanup the image"
echo
COMMAND_TO_RUN="cleanup_image"
shift ;;
-e|--initialize-local-virtualenv)
echo "Initializing local virtualenv"
echo
COMMAND_TO_RUN="perform_initialize_local_virtualenv"
shift ;;
-f|--forward-credentials)
echo "Fowarding credentials. Be careful as your credentials ar available in the container!"
echo
export FORWARD_CREDENTIALS="true"
shift 1 ;;
-a|--setup-autocomplete)
echo "Setting up autocomplete"
echo
COMMAND_TO_RUN="perform_setup_autocomplete"
shift ;;
-t|--test-target)
if [[ "${TEST_TARGET}" == "." ]]; then
export TEST_TARGET=""
fi
COMMAND_TO_RUN="run_tests"
shift 2 ;;
-d|--docker-compose)
DOCKER_COMPOSE_COMMAND="${2}"
COMMAND_TO_RUN="run_docker_compose"
shift 2 ;;
-k|--stop-environment)
COMMAND_TO_RUN="run_docker_compose"
DOCKER_COMPOSE_COMMAND="down"
EXTRA_DC_OPTIONS+=("--remove-orphans")
shift ;;
-x|--execute-command)
COMMAND_TO_RUN="run_in_bash"
shift 2 ;;
-S|--static-check )
COMMAND_TO_RUN="perform_static_checks"
export PYTHON_VERSION=${STATIC_CHECK_PYTHON_VERSION}
export STATIC_CHECK="${2}"
export STATIC_CHECK_ALL_FILES="false"
EXTRA_STATIC_CHECK_OPTIONS+=("--show-diff-on-failure")
shift 2 ;;
-F|--static-check-all-files)
COMMAND_TO_RUN="perform_static_checks"
export PYTHON_VERSION=${STATIC_CHECK_PYTHON_VERSION}
export STATIC_CHECK="${2}"
export STATIC_CHECK_ALL_FILES="true"
EXTRA_STATIC_CHECK_OPTIONS+=("--all-files" "--show-diff-on-failure")
shift 2 ;;
-O|--build-docs)
COMMAND_TO_RUN="build_docs"
shift 1 ;;
--)
shift ;
break ;;
*)
usage
echo >&2
echo >&2 "ERROR: Unknown argument ${1}"
echo >&2
exit 1
;;
esac
done
REMAINING_ARGS+=("$@")
}
usage() {
LIST_PREFIX=" "
WIDTH=$((SEPARATOR_WIDTH>80 ? 80: SEPARATOR_WIDTH))
ALLOWED_PYTHON_VERSIONS=$(echo "${_BREEZE_ALLOWED_PYTHON_VERSIONS=""}" | tr '\n' ' ' | \
fold -w "${WIDTH}" -s | sed "s/^/${LIST_PREFIX}/")
ALLOWED_BACKENDS=$(echo "${_BREEZE_ALLOWED_BACKENDS=""}" | tr '\n' ' ' | \
fold -w "${WIDTH}" -s | sed "s/^/${LIST_PREFIX}/")
ALLOWED_STATIC_CHECKS=$(echo "${_BREEZE_ALLOWED_STATIC_CHECKS=""}" | tr '\n' ' ' | \
fold -w "${WIDTH}" -s | sed "s/^/${LIST_PREFIX}/")
ALLOWED_INTEGRATIONS=$(echo "${_BREEZE_ALLOWED_INTEGRATIONS=""}" | tr '\n' ' ' | \
fold -w "${WIDTH}" -s | sed "s/^/${LIST_PREFIX}/")
ALLOWED_KUBERNETES_MODES=$(echo "${_BREEZE_ALLOWED_KUBERNETES_MODES=""}" | tr '\n' ' ' | \
fold -w "${WIDTH}" -s | sed "s/^/${LIST_PREFIX}/")
ALLOWED_KUBERNETES_VERSIONS=$(echo "${_BREEZE_ALLOWED_KUBERNETES_VERSIONS=""}" | tr '\n' ' ' | \
fold -w "${WIDTH}" -s | sed "s/^/${LIST_PREFIX}/")
ALLOWED_INSTALL_AIRFLOW_VERSIONS=$(echo "${_BREEZE_ALLOWED_INSTALL_AIRFLOW_VERSIONS=""}" | \
tr '\n' ' ' | fold -w "${WIDTH}" -s | sed "s/^/${LIST_PREFIX}/")
echo """
*********************************************************************************************************
Usage: ${CMDNAME} [FLAGS] -- <EXTRA_ARGS>
The swiss-knife-army tool for Airflow testings. It allows to perform various test tasks:
* Enter interactive environment when no command flags are specified (default behaviour)
* Start integrations if specified as extra flags
* Start Kind Kubernetes cluster for Kubernetes tests if specified
* Stop the interactive environment with -k, --stop-environment command
* Run static checks - either for currently staged change or for all files with
-S, --static-check or -F, --static-check-all-files command
* Build documentation with -O, --build-docs command
* Setup local virtualenv with -e, --setup-virtualenv command
* Setup autocomplete for itself with -a, --setup-autocomplete command
* Build docker image with -b, --build-only command
* Run test target specified with -t, --test-target command
* Execute arbitrary command in the test environment with -x, --execute-command command
* Execute arbitrary docker-compose command with -d, --docker-compose command
*********************************************************************************************************
**
** Command to run
**
*********************************************************************************************************
By default the script enters IT environment and drops you to bash shell,
but you can choose one of the commands to run specific actions instead:
-O, --build-docs
Build documentation.
-b, --build-only
Only build docker images but do not enter the airflow-testing docker container.
-e, --initialize-local-virtualenv
Initializes locally created virtualenv installing all dependencies of Airflow.
This local virtualenv can be used to aid autocompletion and IDE support as
well as run unit tests directly from the IDE. You need to have virtualenv
activated before running this command.
-a, --setup-autocomplete
Sets up autocomplete for breeze commands. Once you do it you need to re-enter the bash
shell and when typing breeze command <TAB> will provide autocomplete for parameters and values.
-k, --stop-environment
Bring down running docker compose environment. When you start the environment, the docker
containers will continue running so that startup time is shorter. But they take quite a lot of
memory and CPU. This command stops all running containers from the environment.
-S, --static-check <STATIC_CHECK>
Run selected static checks for currently changed files. You should specify static check that
you would like to run or 'all' to run all checks. One of:
${ALLOWED_STATIC_CHECKS}
You can pass extra arguments including options to to the pre-commit framework as
<EXTRA_ARGS> passed after --. For example:
'${0} --static-check mypy' or
'${0} --static-check mypy -- --files tests/core.py'
You can see all the options by adding --help EXTRA_ARG:
'${0} --static-check mypy -- --help'
-F, --static-check-all-files <STATIC_CHECK>
Run selected static checks for all applicable files. You should specify static check that
you would like to run or 'all' to run all checks. One of:
${ALLOWED_STATIC_CHECKS}
You can pass extra arguments including options to the pre-commit framework as
<EXTRA_ARGS> passed after --. For example:
'${0} --static-check-all-files mypy' or
'${0} --static-check-all-files mypy -- --verbose'
You can see all the options by adding --help EXTRA_ARG:
'${0} --static-check-all-files mypy -- --help'
-t, --test-target <TARGET>
Run the specified unit test target. There might be multiple
targets specified separated with comas. The <EXTRA_ARGS> passed after -- are treated
as additional options passed to pytest. For example:
'${0} --test-target tests/test_core.py -- --logging-level=DEBUG'
*********************************************************************************************************
**
** Print help message
**
*********************************************************************************************************
-h, --help
Shows this help message.
*********************************************************************************************************
**
** Choose tested Airflow variant
**
*********************************************************************************************************
-P, --python <PYTHON_VERSION>
Python version used for the image. This is always major/minor version.
One of:
${ALLOWED_PYTHON_VERSIONS}
-B, --backend <BACKEND>
Backend to use for tests - it determines which database is used.
One of:
${ALLOWED_BACKENDS}
Default: ${_BREEZE_DEFAULT_BACKEND:=}
-I, --integration <INTEGRATION>
Integration to start during tests - it determines which integrations are started for integration
tests. There can be more than one integration started, or all to start all integrations.
Selected integrations are not saved for future execution.
One of:
${ALLOWED_INTEGRATIONS}
*********************************************************************************************************
**
** Manage Kind kubernetes cluster
**
*********************************************************************************************************
-K, --start-kind-cluster
Starts kind Kubernetes cluster after entering the environment. The cluster is started using
Kubernetes Mode selected and Kubernetes version specifed via --kubernetes-mode and
--kubernetes-version flags.
-Z, --recreate-kind-cluster
Recreates kind Kubernetes cluster if one has already been created. By default, if you do not stop
environment, the Kubernetes cluster created for testing is continuously running and when
you start Kubernetes testing again it will be reused. You can force deletion and recreation
of such cluster with this flag.
-X, --stop-kind-cluster
Stops kind Kubernetes cluster if one has already been created. By default, if you do not stop
environment, the Kubernetes cluster created for testing is continuously running and when
you start Kubernetes testing again it will be reused. You can force deletion and recreation
of such cluster with this flag.
-M, --kubernetes-mode <KUBERNETES_MODE>
Kubernetes mode - only used in case --start-kind-cluster flag is specified.
One of:
${ALLOWED_KUBERNETES_MODES}
Default: ${_BREEZE_DEFAULT_KUBERNETES_MODE:=}
-V, --kubernetes-version <KUBERNETES_VERSION>
Kubernetes version - only used in case --start-kind-cluster flag is specified.
One of:
${ALLOWED_KUBERNETES_VERSIONS}
Default: ${_BREEZE_DEFAULT_KUBERNETES_VERSION:=}
*********************************************************************************************************
**
** Manage mounting local files
**
*********************************************************************************************************
-s, --skip-mounting-source-volume
Skips mounting local volume with sources - you get exactly what is in the
docker image rather than your current local sources of airflow.
*********************************************************************************************************
**
** Install Airflow if different than current
**
*********************************************************************************************************
-N, --install-airflow-version <INSTALL_AIRFLOW_VERSION>
If different than 'current' removes the source-installed airflow and installs a
released version of Airflow instead. One of:
${ALLOWED_INSTALL_AIRFLOW_VERSIONS}
Default: ${_BREEZE_DEFAULT_INSTALL_AIRFLOW_VERSION:=}.
*********************************************************************************************************
**
** Assume answers to questions
**
*********************************************************************************************************
-y, --assume-yes
Assume 'yes' answer to all questions.
-n, --assume-no
Assume 'no' answer to all questions.
*********************************************************************************************************
**
** Credentials
**
*********************************************************************************************************
-f, --forward-credentials
Forwards host credentials to docker container. Use with care as it will make your credentials
Available to everything you install in Docker.
*********************************************************************************************************
**
** Increase verbosity of the script
**
*********************************************************************************************************
-v, --verbose
Show verbose information about executed commands (enabled by default for running test)
*********************************************************************************************************
**
** Enable/Disable extra information printed at output
**
*********************************************************************************************************
-C, --toggle-suppress-cheatsheet
Toggles on/off cheatsheet displayed before starting bash shell
-A, --toggle-suppress-asciiart
Toggles on/off asciiart displayed before starting bash shell
*********************************************************************************************************
**
** Flags for building the docker images
**
*********************************************************************************************************
-r, --force-build-images
Forces building of the local docker images. The images are rebuilt
automatically for the first time or when changes are detected in
package-related files, but you can force it using this flag.
-p, --force-pull-images
Forces pulling of images from DockerHub before building to populate cache. The
images are pulled by default only for the first time you run the
environment, later the locally build images are used as cache.
-R, --force-clean-build
Force build images with cache disabled. This will remove the pulled or build images
and start building images from scratch. This might take a long time.
-L, --use-local-cache
Uses local cache to build images. No pulled images will be used, but results of local builds in
the Docker cache are used instead.
-c, --cleanup-images
Cleanup your local docker cache of the airflow docker images. This will not reclaim space in
docker cache. You need to 'docker system prune' (optionally with --all) to reclaim that space.
*********************************************************************************************************
**
** Flags for pushing the docker images
**
*********************************************************************************************************
-u, --push-images
After building - uploads the images to DockerHub
It is useful in case you use your own DockerHub user to store images and you want
to build them locally. Note that you need to use 'docker login' before you upload images.
*********************************************************************************************************
**
** User and repo used to login to github registry
**
*********************************************************************************************************
-D, --dockerhub-user
DockerHub user used to pull, push and build images. Default: ${_BREEZE_DEFAULT_DOCKERHUB_USER:=}.