Skip to content

Commit 857788e

Browse files
authored
[AIRFLOW-5369] Adds interactivity to pre-commits (apache#5976)
This commit adds full interactivity to pre-commits. Whenever you run pre-commit and it detects that the image should be rebuild, an interactive question will pop up instead of failing the build and asking to rebuild with REBUILD=yes This is much nicer from the user perspective. You can choose whether to: 1) Rebuild the image (which will take some time) 2) Not rebuild the image (this will use the old image with hope it's OK) 3) Quit. Answer to that question is carried across all images needed to rebuild. There is the special "build" pre-commit hook that takes care about that. Note that this interactive question cannot be asked if you run only single pre-commit hook with Dockerfile because it can run multiple processes and you can start building in parallel. This is not desired so instead we fail such builds.
1 parent 7ad1544 commit 857788e

31 files changed

+397
-196
lines changed

.pre-commit-config.yaml

+13-8
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ repos:
2424
hooks:
2525
- id: build
2626
name: Check if image build is needed
27-
entry: ./scripts/ci/ci_build.sh
27+
entry: ./scripts/ci/local_ci_build.sh
2828
language: system
2929
always_run: true
3030
pass_filenames: false
3131
- id: check-apache-license
3232
name: Check if licences are OK for Apache
33-
entry: ./scripts/ci/ci_check_license.sh
33+
entry: "./scripts/ci/pre_commit_check_license.sh"
3434
language: system
3535
files: ^.*LICENSE.*$|^.*LICENCE.*$
3636
pass_filenames: false
@@ -177,32 +177,37 @@ repos:
177177
language: docker_image
178178
entry: koalaman/shellcheck:stable -x -a
179179
types: [shell]
180-
files: ^breeze$|^breeze-complete$|\.sh$
180+
files: ^breeze$|^breeze-complete$|\.sh$|^hooks/build$|^hooks/push$
181181
exclude: ^airflow/_vendor/.*$
182182
- id: lint-dockerfile
183183
name: Lint dockerfile
184184
language: system
185-
entry: ./scripts/ci/ci_lint_dockerfile.sh
185+
entry: "./scripts/ci/pre_commit_lint_dockerfile.sh"
186186
files: ^Dockerfile.*$
187+
pass_filenames: true
187188
- id: mypy
188189
name: Run mypy
189190
language: system
190-
entry: ./scripts/ci/ci_mypy.sh
191+
entry: "./scripts/ci/pre_commit_mypy.sh"
191192
files: \.py$
192193
exclude: ^airflow/_vendor/.*$
194+
pass_filenames: true
193195
- id: pylint
194196
name: Run pylint for main sources
195197
language: system
196-
entry: ./scripts/ci/ci_pylint_main.sh
198+
entry: "./scripts/ci/pre_commit_pylint_main.sh"
197199
files: \.py$
198200
exclude: ^tests/.*\.py$|^airflow/_vendor/.*$
201+
pass_filenames: true
199202
- id: pylint
200203
name: Run pylint for tests
201204
language: system
202-
entry: ./scripts/ci/ci_pylint_tests.sh
205+
entry: "./scripts/ci/pre_commit_pylint_tests.sh"
203206
files: ^tests/.*\.py$
207+
pass_filenames: true
204208
- id: flake8
205209
name: Run flake8
206210
language: system
207-
entry: ./scripts/ci/ci_flake8.sh
211+
entry: "./scripts/ci/pre_commit_flake8.sh"
208212
files: \.py$
213+
pass_filenames: true

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ env:
2222
global:
2323
- BUILD_ID=${TRAVIS_BUILD_ID}
2424
- AIRFLOW_CONTAINER_MOUNT_HOST_VOLUMES="false"
25+
- FORCE_ANSWER_TO_QUESTIONS="yes"
2526
- AIRFLOW_CI_SILENT="true"
2627
- CI="true"
2728
python: "3.6"

BREEZE.rst

+7-4
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,9 @@ These are the current flags of the `./breeze <./breeze>`_ script
776776
-y, --assume-yes
777777
Assume 'yes' answer to all questions.
778778
779+
-n, --assume-no
780+
Assume 'no' answer to all questions.
781+
779782
-C, --toggle-suppress-cheatsheet
780783
Toggles on/off cheatsheet displayed before starting bash shell
781784
@@ -790,13 +793,13 @@ These are the current flags of the `./breeze <./breeze>`_ script
790793
-H, --dockerhub-repo
791794
DockerHub repository used to pull, push, build images. Default: airflow.
792795
793-
-r, --force-rebuild-images
794-
Forces rebuilding of the local docker images. The images are rebuilt
796+
-r, --force-build-images
797+
Forces building of the local docker images. The images are rebuilt
795798
automatically for the first time or when changes are detected in
796799
package-related files, but you can force it using this flag.
797800
798-
-R, --force-rebuild-images-clean
799-
Force rebuild images without cache. This will remove the pulled or build images
801+
-R, --force-build-images-clean
802+
Force build images without cache. This will remove the pulled or build images
800803
and start building images from scratch. This might take a long time.
801804
802805
-p, --force-pull-images

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Before running the pre-commit hooks you must first build the docker images as de
274274

275275
Sometimes your image is outdated (when dependencies change) and needs to be rebuilt because some
276276
dependencies have been changed. In such case the docker build pre-commit will inform
277-
you that you should rebuild the image.
277+
you that you should build the image.
278278

279279
## Prerequisites for pre-commit hooks
280280

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ARG PYTHON_BASE_IMAGE="python:3.6-slim-stretch"
2525
############################################################################################################
2626
FROM ${PYTHON_BASE_IMAGE} as airflow-apt-deps-ci-slim
2727

28+
2829
SHELL ["/bin/bash", "-o", "pipefail", "-e", "-u", "-x", "-c"]
2930

3031
ARG PYTHON_BASE_IMAGE="python:3.6-slim-stretch"

breeze

+29-29
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ EOF
121121
export AIRFLOW_VERSION
122122

123123
# Verbosity in running ci scripts
124-
export AIRFLOW_CI_VERBOSE="false"
124+
export VERBOSE="false"
125125

126126
# Enter environment by default, rather than run tests or bash command or docker compose or static checks
127127
export RUN_TESTS="false"
@@ -130,10 +130,7 @@ export RUN_IN_BASH="false"
130130
export RUN_STATIC_CHECKS="false"
131131
export RUN_BUILD_DOCS="false"
132132

133-
export FORCE_BUILD=${FORCE_BUILD:="false"}
134-
135-
# if set to true, rebuild is done without asking user
136-
export SKIP_BUILD_CHECK="false"
133+
export AIRFLOW_CONTAINER_FORCE_DOCKER_BUILD=${AIRFLOW_CONTAINER_FORCE_DOCKER_BUILD:="false"}
137134

138135
# Files determining whether asciiart/cheatsheet are suppressed
139136

@@ -392,6 +389,9 @@ The swiss-knife-army tool for Airflow testings. It allows to perform various tes
392389
-y, --assume-yes
393390
Assume 'yes' answer to all questions.
394391
392+
-n, --assume-no
393+
Assume 'no' answer to all questions.
394+
395395
-C, --toggle-suppress-cheatsheet
396396
Toggles on/off cheatsheet displayed before starting bash shell
397397
@@ -406,13 +406,13 @@ The swiss-knife-army tool for Airflow testings. It allows to perform various tes
406406
-H, --dockerhub-repo
407407
DockerHub repository used to pull, push, build images. Default: ${_BREEZE_DEFAULT_DOCKERHUB_REPO:=}.
408408
409-
-r, --force-rebuild-images
410-
Forces rebuilding of the local docker images. The images are rebuilt
409+
-r, --force-build-images
410+
Forces building of the local docker images. The images are rebuilt
411411
automatically for the first time or when changes are detected in
412412
package-related files, but you can force it using this flag.
413413
414-
-R, --force-rebuild-images-clean
415-
Force rebuild images without cache. This will remove the pulled or build images
414+
-R, --force-build-images-clean
415+
Force build images without cache. This will remove the pulled or build images
416416
and start building images from scratch. This might take a long time.
417417
418418
-p, --force-pull-images
@@ -421,7 +421,7 @@ The swiss-knife-army tool for Airflow testings. It allows to perform various tes
421421
environment, later the locally build images are used as cache.
422422
423423
-u, --push-images
424-
After rebuilding - uploads the images to DockerHub
424+
After building - uploads the images to DockerHub
425425
It is useful in case you use your own DockerHub user to store images and you want
426426
to build them locally. Note that you need to use 'docker login' before you upload images.
427427
@@ -491,22 +491,25 @@ do
491491
shift ;;
492492
-b|--build-only)
493493
ENTER_ENVIRONMENT="false"
494-
SKIP_BUILD_CHECK="true"
495-
AIRFLOW_CONTAINER_DOCKER_BUILD_NEEDED="true"
496-
FORCE_BUILD="true"
494+
export AIRFLOW_CONTAINER_FORCE_DOCKER_BUILD="true"
497495
echo "Only build. Do not enter airflow-testing container"
498496
echo
499497
shift ;;
500498
-v|--verbose)
501-
AIRFLOW_CI_VERBOSE="true"
499+
VERBOSE="true"
502500
echo "Verbose output"
503501
echo
504502
shift ;;
505503
-y|--assume-yes)
506-
export ASSUME_YES="true"
504+
export FORCE_ANSWER_TO_QUESTIONS="yes"
507505
echo "Assuming 'yes' answer to all questions."
508506
echo
509507
shift ;;
508+
-n|--assume-no)
509+
export FORCE_ANSWER_TO_QUESTIONS="no"
510+
echo "Assuming 'no' answer to all questions."
511+
echo
512+
shift ;;
510513
-C|--toggle-suppress-cheatsheet)
511514
if [[ -f "${SUPPRESS_CHEATSHEET_FILE}" ]]; then
512515
rm -f "${SUPPRESS_CHEATSHEET_FILE}"
@@ -525,32 +528,27 @@ do
525528
echo "Toggle suppress asciiart"
526529
echo
527530
shift ;;
528-
-r|--force-rebuild-images)
531+
-r|--force-build-images)
529532
echo
530-
echo "Force rebuild images"
533+
echo "Force build images"
531534
echo
532-
AIRFLOW_CONTAINER_DOCKER_BUILD_NEEDED="true"
533-
SKIP_BUILD_CHECK="true"
534-
FORCE_BUILD="true"
535+
export AIRFLOW_CONTAINER_FORCE_DOCKER_BUILD="true"
535536
shift ;;
536-
-R|--force-rebuild-images-clean)
537+
-R|--force-build-images-clean)
537538
echo
538-
echo "Clean rebuild of images without cache"
539+
echo "Clean build of images without cache"
539540
echo
540541
export AIRFLOW_CONTAINER_USE_DOCKER_CACHE=false
541542
export AIRFLOW_CONTAINER_USE_PULLED_IMAGES_CACHE=false
542-
AIRFLOW_CONTAINER_DOCKER_BUILD_NEEDED="true"
543-
SKIP_BUILD_CHECK="true"
544-
FORCE_BUILD="true"
543+
export AIRFLOW_CONTAINER_FORCE_DOCKER_BUILD="true"
545544
CLEANUP_IMAGES="true"
546545
shift ;;
547546
-p|--force-pull-images)
548547
echo
549548
echo "Force pulling images before build. Uses pulled images as cache."
550549
echo
551550
export AIRFLOW_CONTAINER_FORCE_PULL_IMAGES="true"
552-
AIRFLOW_CONTAINER_DOCKER_BUILD_NEEDED="true"
553-
SKIP_BUILD_CHECK="true"
551+
export AIRFLOW_CONTAINER_FORCE_DOCKER_BUILD="true"
554552
shift ;;
555553
-u|--push-images)
556554
if [[ "${AIRFLOW_FIX_PERMISSIONS}" != "all" ]]; then
@@ -568,8 +566,7 @@ do
568566
echo "Pushing images to DockerHub"
569567
echo
570568
export AIRFLOW_CONTAINER_PUSH_IMAGES="true"
571-
AIRFLOW_CONTAINER_DOCKER_BUILD_NEEDED="true"
572-
SKIP_BUILD_CHECK="true"
569+
export AIRFLOW_CONTAINER_FORCE_DOCKER_BUILD="true"
573570
shift ;;
574571
-c|--cleanup-images)
575572
echo
@@ -683,6 +680,9 @@ echo
683680

684681
CMDNAME="$(basename -- "$0")"
685682

683+
# Cleans up the answer that was given last time, whether to force/
684+
cleanup_last_force_answer
685+
686686
export ENV="${ENV:=$(read_from_file ENV)}"
687687
export BACKEND="${BACKEND:=$(read_from_file BACKEND)}"
688688
export KUBERNETES_VERSION="${KUBERNETES_VERSION:=$(read_from_file KUBERNETES_VERSION)}"

breeze-complete

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ _BREEZE_DEFAULT_DOCKERHUB_REPO="airflow"
1212
_BREEZE_SHORT_OPTIONS="
1313
h P: E: B: K: M:
1414
s b O
15-
v y C A
15+
v y n C A
1616
r R p u
1717
c D: H: e a
1818
t: d: k x: S: F:
@@ -21,8 +21,8 @@ t: d: k x: S: F:
2121
_BREEZE_LONG_OPTIONS="
2222
help python: env: backend: kubernetes-version: kubernetes-mode:
2323
skip-mounting-local-sources build-only build-docs
24-
verbose assume-yes toggle-suppress-cheatsheet toggle-suppress-asciiart
25-
force-rebuild-images force-rebuild-images-clean force-pull-images push-images
24+
verbose assume-yes assume-no toggle-suppress-cheatsheet toggle-suppress-asciiart
25+
force-build-images force-build-images-clean force-pull-images push-images
2626
cleanup-images dockerhub-user: dockerhub-repo: initialize-local-virtualenv setup-autocomplete
2727
test-target: docker-compose: stop-environment execute-command: static-check: static-check-all-files:
2828
"

confirm

+21-14
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,35 @@
1717
# under the License.
1818
set -euo pipefail
1919

20-
if [[ "${ASSUME_YES_TO_ALL_QUESTIONS:=false}" == "true" ]]; then
21-
exit 0
20+
if [[ "${FORCE_ANSWER_TO_QUESTIONS:=""}" != "" ]]; then
21+
RESPONSE=${FORCE_ANSWER_TO_QUESTIONS}
22+
echo
23+
echo "Forcing response '${FORCE_ANSWER_TO_QUESTIONS}' to ${1}."
24+
case "${RESPONSE}" in
25+
[yY][eE][sS]|[yY])
26+
exit 0 ;;
27+
[qQ][uU][iI][tT]|[qQ])
28+
exit 2 ;;
29+
*)
30+
exit 1 ;;
31+
esac
32+
else
33+
echo
34+
echo "Please confirm ${1} images. Are you sure? [y/N/q]"
35+
read -r RESPONSE
2236
fi
2337

24-
if [[ "${ASSUME_NO_TO_ALL_QUESTIONS:=false}" == "true" ]]; then
25-
exit 1
26-
fi
27-
28-
if [[ "${ASSUME_QUIT_TO_ALL_QUESTIONS:=false}" == "true" ]]; then
29-
exit 2
30-
fi
31-
32-
33-
read -r -p "${1}. Are you sure? [y/N/q] " response
34-
case "$response" in
38+
case "${RESPONSE}" in
3539
[yY][eE][sS]|[yY])
40+
echo "The answer is 'yes'. Attempting to ${1} images. This can take some time !"
3641
exit 0
3742
;;
38-
[qQ][uU][iI|[tT]|[qQ])
43+
[qQ][uU][iI][tT]|[qQ])
44+
echo "The answer is 'quit'. Quitting now!"
3945
exit 2
4046
;;
4147
*)
48+
echo "The answer is 'no'. Skipping attempt to ${1} images."
4249
exit 1
4350
;;
4451
esac

0 commit comments

Comments
 (0)