Skip to content

Commit ae1d743

Browse files
committed
[SPARK-25957][K8S] Add ability to skip building optional k8s docker images
bin/docker-image-tool.sh tries to build all docker images (JVM, PySpark and SparkR) by default. But not all spark distributions are built with SparkR and hence this script will fail on such distros. With this change, - We should be able to skip building optional docker images (PySpark and SparkR) by specifying -pskip or -Rskip flags. - We autodetect if SparkR is not installed in the build and skip building SparkR docker image. - We skip pushing docker images that are not available locally. Tested following scenarios. - On source code and distro with SparkR support - Run bin/docker-image-tool.sh -r <repo> -t <tag> build. Verify that JVM, PySpark and SparkR docker images are built. - Run bin/docker-image-tool.sh -r <repo> -t <tag> -Rskip -pskip build. Verify that only JVM docker image is built. Building PySpark and SparkR images is skipped. - On source code and distro without SparkR support - Run bin/docker-image-tool.sh -r <repo> -t <tag> build. Verify that only JVM, PySpark docker images are built. Building SparkR image is skipped. - On system with JVM, PySpark and SparkR images built, - Run bin/docker-image-tool.sh -r <repo> -t <tag> push. Verify that all images are pushed to docker registry. - On system with only JVM and PySpark images built. - Run bin/docker-image-tool.sh -r <repo> -t <tag> push. Verify that only JVM and PySpark images are pushed. Pushing SparkR images is skipped.
1 parent 9a5fda6 commit ae1d743

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

bin/docker-image-tool.sh

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ function image_ref {
4141
echo "$image"
4242
}
4343

44+
function docker_push {
45+
local image_name="$1"
46+
if [ ! -z $(docker images -q "$(image_ref ${image_name})") ]; then
47+
docker push "$(image_ref ${image_name})"
48+
if [ $? -ne 0 ]; then
49+
error "Failed to push $image_name Docker image."
50+
fi
51+
else
52+
echo "$(image_ref ${image_name}) image not found. Skipping push for this image."
53+
fi
54+
}
55+
4456
function build {
4557
local BUILD_ARGS
4658
local IMG_PATH
@@ -102,33 +114,33 @@ function build {
102114
error "Failed to build Spark JVM Docker image, please refer to Docker build output for details."
103115
fi
104116

105-
docker build $NOCACHEARG "${BINDING_BUILD_ARGS[@]}" \
106-
-t $(image_ref spark-py) \
107-
-f "$PYDOCKERFILE" .
117+
if [ "${PYDOCKERFILE}" != "skip" ]; then
118+
docker build $NOCACHEARG "${BINDING_BUILD_ARGS[@]}" \
119+
-t $(image_ref spark-py) \
120+
-f "$PYDOCKERFILE" .
121+
if [ $? -ne 0 ]; then
122+
error "Failed to build PySpark Docker image, please refer to Docker build output for details."
123+
fi
124+
else
125+
echo "Skipped building PySpark docker image."
126+
fi
127+
128+
if [ "${RDOCKERFILE}" != "skip" ] && [ -d "${SPARK_HOME}/R/lib" ]; then
129+
docker build $NOCACHEARG "${BINDING_BUILD_ARGS[@]}" \
130+
-t $(image_ref spark-r) \
131+
-f "$RDOCKERFILE" .
108132
if [ $? -ne 0 ]; then
109-
error "Failed to build PySpark Docker image, please refer to Docker build output for details."
133+
error "Failed to build SparkR Docker image, please refer to Docker build output for details."
110134
fi
111-
docker build $NOCACHEARG "${BINDING_BUILD_ARGS[@]}" \
112-
-t $(image_ref spark-r) \
113-
-f "$RDOCKERFILE" .
114-
if [ $? -ne 0 ]; then
115-
error "Failed to build SparkR Docker image, please refer to Docker build output for details."
135+
else
136+
echo "Skipped building SparkR docker image."
116137
fi
117138
}
118139

119140
function push {
120-
docker push "$(image_ref spark)"
121-
if [ $? -ne 0 ]; then
122-
error "Failed to push Spark JVM Docker image."
123-
fi
124-
docker push "$(image_ref spark-py)"
125-
if [ $? -ne 0 ]; then
126-
error "Failed to push PySpark Docker image."
127-
fi
128-
docker push "$(image_ref spark-r)"
129-
if [ $? -ne 0 ]; then
130-
error "Failed to push SparkR Docker image."
131-
fi
141+
docker_push "spark"
142+
docker_push "spark-py"
143+
docker_push "spark-r"
132144
}
133145

134146
function usage {
@@ -145,6 +157,8 @@ Options:
145157
-f file Dockerfile to build for JVM based Jobs. By default builds the Dockerfile shipped with Spark.
146158
-p file Dockerfile to build for PySpark Jobs. Builds Python dependencies and ships with Spark.
147159
-R file Dockerfile to build for SparkR Jobs. Builds R dependencies and ships with Spark.
160+
-pskip Skip building PySpark docker image.
161+
-Rskip Skip building SparkR docker image.
148162
-r repo Repository address.
149163
-t tag Tag to apply to the built image, or to identify the image to be pushed.
150164
-m Use minikube's Docker daemon.

0 commit comments

Comments
 (0)