Skip to content

Commit

Permalink
[AIRFLOW-5078] User is asked if an image needs to be rebuild (apache#…
Browse files Browse the repository at this point in the history
…5691)

This is not happening when the user explicitely wants to build image
or in CI environment (DockerHub always builds the image via
hooks/build script.
  • Loading branch information
potiuk authored Jul 31, 2019
1 parent b460e5d commit da938a1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
8 changes: 7 additions & 1 deletion confirm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/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
Expand All @@ -15,6 +15,12 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
set -euo pipefail

if [[ "${ASSUME_YES:=false}" == "true" ]]; then
exit 0
fi

read -r -p "${1}. Are you sure? [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
Expand Down
44 changes: 27 additions & 17 deletions scripts/ci/_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# Assume all the scripts are sourcing the _utils.sh from the scripts/ci directory
# and MY_DIR variable is set to this directory
AIRFLOW_SOURCES=$(cd ${MY_DIR}/../../ && pwd)
AIRFLOW_SOURCES=$(cd "${MY_DIR}/../../" && pwd)
export AIRFLOW_SOURCES

BUILD_CACHE_DIR="${AIRFLOW_SOURCES}/.build"
Expand All @@ -32,16 +32,17 @@ Dockerfile \
airflow/version.py
"

mkdir -p ${AIRFLOW_SOURCES}/.mypy_cache
mkdir -p ${AIRFLOW_SOURCES}/logs
mkdir -p ${AIRFLOW_SOURCES}/tmp
mkdir -p "${AIRFLOW_SOURCES}/.mypy_cache"
mkdir -p "${AIRFLOW_SOURCES}/logs"
mkdir -p "${AIRFLOW_SOURCES}/tmp"

# Disable writing .pyc files - slightly slower imports but not messing around when switching
# Python version and avoids problems with root-owned .pyc files in host
export PYTHONDONTWRITEBYTECODE="true"

# Read default branch name
. ${AIRFLOW_SOURCES}/hooks/_default_branch.sh
# shellcheck source=../../hooks/_default_branch.sh
. "${AIRFLOW_SOURCES}/hooks/_default_branch.sh"

# Default branch name for triggered builds is the one configured in hooks/_default_branch.sh
export AIRFLOW_CONTAINER_BRANCH_NAME=${AIRFLOW_CONTAINER_BRANCH_NAME:=${DEFAULT_BRANCH}}
Expand Down Expand Up @@ -328,11 +329,10 @@ EOF
check_if_docker_build_is_needed

if [[ "${AIRFLOW_CONTAINER_DOCKER_BUILD_NEEDED}" == "true" ]]; then
SKIP_REBUILD="false"
local SKIP_REBUILD="false"
if [[ ${CI:=} != "true" ]]; then
set +e
${MY_DIR}/../../confirm "The image might need to be rebuild. This will take short time"
if [[ $? != "0" ]]; then
if ! "${MY_DIR}/../../confirm" "The image might need to be rebuild."; then
SKIP_REBUILD="true"
fi
set -e
Expand Down Expand Up @@ -400,15 +400,25 @@ EOF
check_if_docker_build_is_needed

if [[ "${AIRFLOW_CONTAINER_DOCKER_BUILD_NEEDED}" == "true" ]]; then
echo
echo "Rebuilding image"
echo
# shellcheck source=../../hooks/build
./hooks/build | tee -a "${OUTPUT_LOG}"
update_all_md5_files
echo
echo "Image rebuilt"
echo
local SKIP_REBUILD="false"
if [[ ${CI:=} != "true" ]]; then
set +e
if ! "${MY_DIR}/../../confirm" "The image might need to be rebuild."; then
SKIP_REBUILD="true"
fi
set -e
fi
if [[ ${SKIP_REBUILD} != "true" ]]; then
echo
echo "Rebuilding image"
echo
# shellcheck source=../../hooks/build
./hooks/build | tee -a "${OUTPUT_LOG}"
update_all_md5_files
echo
echo "Image rebuilt"
echo
fi
else
echo
echo "No need to rebuild the image as none of the sensitive files changed: ${FILES_FOR_REBUILD_CHECK}"
Expand Down
2 changes: 2 additions & 0 deletions scripts/ci/local_ci_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ basic_sanity_checks

script_start

export ASSUME_YES="true"

rebuild_image_if_needed_for_tests

rebuild_image_if_needed_for_static_checks
Expand Down
1 change: 1 addition & 0 deletions scripts/ci/local_ci_pull_and_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ script_start

export AIRFLOW_CONTAINER_FORCE_PULL_IMAGES="true"
export AIRFLOW_CONTAINER_SKIP_LATEST_PYTHON_PULL="true"
export ASSUME_YES="true"

rebuild_image_if_needed_for_tests

Expand Down

0 comments on commit da938a1

Please sign in to comment.