You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/05/25 06:58:09 UTC

[GitHub] [airflow] milton0825 commented on a change in pull request #4937: [AIRFLOW-4116] Multi-staging includes CI image [Step 2/3]

milton0825 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_r287553753
 
 

 ##########
 File path: hooks/build
 ##########
 @@ -0,0 +1,445 @@
+#!/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"
 
 Review comment:
   Should we change it back?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services