potiuk commented on a change in pull request #4937: [AIRFLOW-4116] 
Multi-staging includes CI image [Step 2/3]
URL: https://github.com/apache/airflow/pull/4937#discussion_r285377558
 
 

 ##########
 File path: hooks/build
 ##########
 @@ -0,0 +1,449 @@
+#!/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.
+
+# This is hook build used by DockerHub. We are also using it
+# on Travis CI to potentially rebuild (and refresh layers that
+# are not cached) Docker images that are used to run CI jobs
+
+set -euo pipefail
+
+MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+echo "My dir: ${MY_DIR}"
+
+AIRFLOW_ROOT=$(cd "${MY_DIR}"; cd ..; pwd)
+cd ${AIRFLOW_ROOT}
+
+echo
+echo "Airflow root directory: ${AIRFLOW_ROOT}"
+echo
+
+date
+
+BUILD_START_TIME=$(date +%s)
+LAST_STEP_START_TIME=${BUILD_START_TIME}
+LAST_STEP_NAME=""
+STEP_STARTED="false"
+
+function end_step {
+    if [[ "${STEP_STARTED}" != "true" ]]; then
+        return
+    fi
+    LAST_STEP_END_TIME=$(date +%s)
+    echo
+    echo 
"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
+    echo "                     Finishing step: ${LAST_STEP_NAME}"
+    echo "                     Date: $(date)"
+    echo "                     Step time in s : 
$((LAST_STEP_END_TIME-LAST_STEP_START_TIME))"
+    echo "                     Total time in s: 
$((LAST_STEP_END_TIME-BUILD_START_TIME))"
+    echo 
"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
+    echo
+    STEP_STARTED="false"
+}
+
+function start_step {
+    end_step
+    LAST_STEP_NAME="${1}"
+    LAST_STEP_START_TIME=$(date +%s)
+    STEP_STARTED="true"
+    echo
+    echo 
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
+    echo "                     Starting step: ${LAST_STEP_NAME}"
+    echo "                     Date: $(date)"
+    echo 
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
+    echo
+}
+
+function add_image_to_push {
+    IMAGE=$1
+    IMAGES_BUILT="${IMAGES_BUILT} ${IMAGE}"
+    echo
+    echo "Adding TAG ${IMAGE} to push"
+    echo
+    echo
+    echo "List of tags to push now: '${IMAGES_BUILT}'"
+    echo
+}
+
+function build_image {
+    NAME="${1}"
+    MY_IMAGE_TAG="${2}"
+    TARGET_IMAGE="${3}"
+    APT_DEPS_IMAGE="${4:-airflow-apt-deps}"
+    AIRFLOW_EXTRAS="${5:-all}"
+    AIRFLOW_USER="${6:-airflow}"
+    AIRFLOW_USER_HOME="${7:-/home/airflow}"
+
+    echo "Build ${NAME} image: ${MY_IMAGE_TAG}"
+    echo "Base image: ${PYTHON_BASE_IMAGE}"
+
+    set -x
+    docker build \
+        --build-arg PYTHON_BASE_IMAGE="${PYTHON_BASE_IMAGE}" \
+        --build-arg AIRFLOW_VERSION="${AIRFLOW_VERSION}" \
+        --build-arg APT_DEPS_IMAGE=${APT_DEPS_IMAGE} \
+        --build-arg AIRFLOW_EXTRAS=${AIRFLOW_EXTRAS} \
+        --build-arg AIRFLOW_USER=${AIRFLOW_USER} \
+        --build-arg AIRFLOW_USER_HOME=${AIRFLOW_USER_HOME} \
+        ${DOCKER_CACHE_DIRECTIVE} \
+        -t "${MY_IMAGE_TAG}" \
+        --target "${TARGET_IMAGE}" \
+        .
+
+    add_image_to_push ${MY_IMAGE_TAG}
+
+    set +x
+}
+
+start_step "Setting variables"
+
+# You can override DOCKERHUB_USER to use your own DockerHub account and play 
with your
+# own docker images. In this case you can build images locally and push them
+export DOCKERHUB_USER=${DOCKERHUB_USER:="potiuk"} # TODO: change back to 
"airflow"
+
+# You can override DOCKERHUB_REPO to use your own DockerHub repository and 
play with your
+# own docker images. In this case you can build images locally and push them
+export DOCKERHUB_REPO=${DOCKERHUB_REPO:="airflow"}
+
+# Determine python version from the local python on the path.
+# You can override it with PYTHON_VERSION because all python version 
dependencies
+# Are determined in Docker images. If you pass IMAGE_NAME, python version will 
be extracted from the name
+# This default Python version is later overridden in case IMAGE_NAME is passed
+export PYTHON_VERSION=${PYTHON_VERSION:=$(python -c 'import sys; print("%s.%s" 
% (sys.version_info.major, sys.version_info.minor))')}
+export 
IMAGE_NAME=${IMAGE_NAME:=${DOCKERHUB_USER}/${DOCKERHUB_REPO}:latest-${PYTHON_VERSION}}
+
+echo
+echo "IMAGE_NAME=${IMAGE_NAME:=}"
+echo
+
+# Remove index.docker.io/ prefix as it is added by default by DockerHub
+export LOCAL_IMAGE=${IMAGE_NAME#index.docker.io/}
+echo
+echo "LOCAL_IMAGE=${LOCAL_IMAGE}"
+echo
+
+# Extract python version from image name we want to build in case it was passed
+# Via IMAGE_NAME
+# This nice bash construct below extracts last field after '-' delimiter
+# So for example 'latest-3.6' will produce PYTHON_VERSION=3.6
+export PYTHON_VERSION=$(echo "${LOCAL_IMAGE}" | rev | cut -d '-' -f1 | rev )
+
+
+# In case of CRON jobs on Travis we run builds without cache
+if [[ "${TRAVIS_EVENT_TYPE:=}" == "cron" ]]; then
+    
AIRFLOW_CONTAINER_USE_DOCKER_CACHE=${AIRFLOW_CONTAINER_USE_PULLED_IMAGES_CACHE:="false"}
 
 Review comment:
   Done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to