|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | +# contributor license agreements. See the NOTICE file distributed with |
| 5 | +# this work for additional information regarding copyright ownership. |
| 6 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 7 | +# (the "License"); you may not use this file except in compliance with |
| 8 | +# the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | + |
| 19 | +# This script builds and pushes docker images when run from a release of Spark |
| 20 | +# with Kubernetes support. |
| 21 | + |
| 22 | +declare -A path=( [spark-driver]=kubernetes/dockerfiles/driver/Dockerfile \ |
| 23 | + [spark-executor]=kubernetes/dockerfiles/executor/Dockerfile ) |
| 24 | + |
| 25 | +function build { |
| 26 | + docker build -t spark-base -f kubernetes/dockerfiles/spark-base/Dockerfile . |
| 27 | + for image in "${!path[@]}"; do |
| 28 | + docker build -t ${REPO}/$image:${TAG} -f ${path[$image]} . |
| 29 | + done |
| 30 | +} |
| 31 | + |
| 32 | + |
| 33 | +function push { |
| 34 | + for image in "${!path[@]}"; do |
| 35 | + docker push ${REPO}/$image:${TAG} |
| 36 | + done |
| 37 | +} |
| 38 | + |
| 39 | +function usage { |
| 40 | + echo "This script must be run from a runnable distribution of Apache Spark." |
| 41 | + echo "Usage: ./sbin/build-push-docker-images.sh -r <repo> -t <tag> build" |
| 42 | + echo " ./sbin/build-push-docker-images.sh -r <repo> -t <tag> push" |
| 43 | + echo "for example: ./sbin/build-push-docker-images.sh -r docker.io/myrepo -t v2.3.0 push" |
| 44 | +} |
| 45 | + |
| 46 | +if [[ "$@" = *--help ]] || [[ "$@" = *-h ]]; then |
| 47 | + usage |
| 48 | + exit 0 |
| 49 | +fi |
| 50 | + |
| 51 | +while getopts r:t: option |
| 52 | +do |
| 53 | + case "${option}" |
| 54 | + in |
| 55 | + r) REPO=${OPTARG};; |
| 56 | + t) TAG=${OPTARG};; |
| 57 | + esac |
| 58 | +done |
| 59 | + |
| 60 | +if [ -z "$REPO" ] || [ -z "$TAG" ]; then |
| 61 | + usage |
| 62 | +else |
| 63 | + case "${@: -1}" in |
| 64 | + build) build;; |
| 65 | + push) push;; |
| 66 | + *) usage;; |
| 67 | + esac |
| 68 | +fi |
0 commit comments