diff --git a/Dockerfile b/Dockerfile index 35bdc32da9302..cf8c58d80b27e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,14 @@ ENV DEBIAN_FRONTEND=noninteractive # Increase the value to force renstalling of all apt-get dependencies ENV FORCE_REINSTALL_APT_GET_DEPENDENCIES=1 +ARG AIRFLOW_TAG + +# If you build for different version it will invalidate the cache here and rebuild from scratch +# This is typically used in release versions +ENV AIRFLOW_TAG=${AIRFLOW_TAG:-"development"} + +RUN echo "Airflow tag: ${AIRFLOW_TAG}" + # Install build dependencies RUN apt-get update \ && apt-get install -y --no-install-recommends \ diff --git a/hooks/build b/hooks/build new file mode 100755 index 0000000000000..2a8dfd0679f0b --- /dev/null +++ b/hooks/build @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -x + +echo "Build hook is running. IMAGE_NAME=${IMAGE_NAME}, DOCKER_REPO=${DOCKER_REPO}, CACHE_TAG=${CACHE_TAG}, DOCKERFILE_PATH=${DOCKERFILE_PATH}" + +# Pull the image for image currently built if it exists +docker pull ${IMAGE_NAME} || true + +# Pull the image for latest build if it exists +docker pull ${DOCKER_REPO}:latest || true + +if [[ ${CACHE_TAG} == "latest-clean" || ${CACHE_TAG} =~ "release.*" ]]; then + echo "Disabling cache" + CACHE_SPEC="--no-cache" +else + echo "Enabling cache" + CACHE_SPEC="--cache-from ${IMAGE_NAME} --cache-from ${DOCKER_REPO}:latest" +fi + +# Build the image using cached versions if present - both the branch/tag version and latest build can be used +# as cache source - docker will choose appropriate cache based on hashes of the files changed +docker build --pull --build-arg AIRFLOW_TAG=${CACHE_TAG} -f ${DOCKERFILE_PATH} -t ${IMAGE_NAME} \ + ${CACHE_SPEC} . + +echo "Build finished" diff --git a/setup.py b/setup.py index 09792e41812b9..a267167ef2622 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ try: with io.open('README.md', encoding='utf-8') as f: long_description = f.read() -except FileNotFoundError as e: +except FileNotFoundError: long_description = ''