Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Commit 78baf9b

Browse files
johscheuerash211
authored andcommitted
Create base-image and minimize layer count (#324)
* Create base-image and minimize layer count * Create running-on-kubernetes.md
1 parent bcf57cf commit 78baf9b

File tree

8 files changed

+50
-76
lines changed

8 files changed

+50
-76
lines changed

docs/running-on-kubernetes.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,24 @@ If you wish to use pre-built docker images, you may use the images published in
4949
</table>
5050

5151
You may also build these docker images from sources, or customize them as required. Spark distributions include the
52-
Docker files for the driver, executor, and init-container at `dockerfiles/driver/Dockerfile`,
52+
Docker files for the base-image, driver, executor, and init-container at `dockerfiles/spark-base/Dockerfile`, `dockerfiles/driver/Dockerfile`,
5353
`dockerfiles/executor/Dockerfile`, and `dockerfiles/init-container/Dockerfile` respectively. Use these Docker files to
5454
build the Docker images, and then tag them with the registry that the images should be sent to. Finally, push the images
5555
to the registry.
5656

5757
For example, if the registry host is `registry-host` and the registry is listening on port 5000:
5858

5959
cd $SPARK_HOME
60+
docker build -t registry-host:5000/spark-base:latest -f dockerfiles/driver/spark-base .
6061
docker build -t registry-host:5000/spark-driver:latest -f dockerfiles/driver/Dockerfile .
6162
docker build -t registry-host:5000/spark-executor:latest -f dockerfiles/executor/Dockerfile .
6263
docker build -t registry-host:5000/spark-init:latest -f dockerfiles/init-container/Dockerfile .
64+
docker push registry-host:5000/spark-base:latest
6365
docker push registry-host:5000/spark-driver:latest
6466
docker push registry-host:5000/spark-executor:latest
6567
docker push registry-host:5000/spark-init:latest
68+
69+
Note that `spark-base` is the base image for the other images. It must be built first before the other images, and then afterwards the other images can be built in any order.
6670

6771
## Submitting Applications to Kubernetes
6872

resource-managers/kubernetes/docker-minimal-bundle/src/main/docker/driver/Dockerfile

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,13 @@
1515
# limitations under the License.
1616
#
1717

18-
FROM openjdk:8-alpine
18+
FROM spark-base
1919

2020
# If this docker file is being used in the context of building your images from a Spark distribution, the docker build
2121
# command should be invoked from the top level directory of the Spark distribution. E.g.:
2222
# docker build -t spark-driver:latest -f dockerfiles/driver/Dockerfile .
2323

24-
RUN apk upgrade --update
25-
RUN apk add --update bash tini
26-
RUN mkdir -p /opt/spark
27-
RUN touch /opt/spark/RELEASE
28-
29-
ADD jars /opt/spark/jars
30-
ADD examples /opt/spark/examples
31-
ADD bin /opt/spark/bin
32-
ADD sbin /opt/spark/sbin
33-
ADD conf /opt/spark/conf
34-
35-
ENV SPARK_HOME /opt/spark
36-
37-
WORKDIR /opt/spark
24+
COPY examples /opt/spark/examples
3825

3926
CMD SPARK_CLASSPATH="${SPARK_HOME}/jars/*" && \
4027
if ! [ -z ${SPARK_MOUNTED_CLASSPATH+x} ]; then SPARK_CLASSPATH="$SPARK_MOUNTED_CLASSPATH:$SPARK_CLASSPATH"; fi && \

resource-managers/kubernetes/docker-minimal-bundle/src/main/docker/executor/Dockerfile

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,13 @@
1515
# limitations under the License.
1616
#
1717

18-
FROM openjdk:8-alpine
18+
FROM spark-base
1919

2020
# If this docker file is being used in the context of building your images from a Spark distribution, the docker build
2121
# command should be invoked from the top level directory of the Spark distribution. E.g.:
2222
# docker build -t spark-executor:latest -f dockerfiles/executor/Dockerfile .
2323

24-
RUN apk upgrade --update
25-
RUN apk add --update bash tini
26-
RUN mkdir -p /opt/spark
27-
RUN touch /opt/spark/RELEASE
28-
29-
ADD jars /opt/spark/jars
30-
ADD examples /opt/spark/examples
31-
ADD bin /opt/spark/bin
32-
ADD sbin /opt/spark/sbin
33-
ADD conf /opt/spark/conf
34-
35-
ENV SPARK_HOME /opt/spark
36-
37-
WORKDIR /opt/spark
24+
COPY examples /opt/spark/examples
3825

3926
# TODO support spark.executor.extraClassPath
4027
CMD SPARK_CLASSPATH="${SPARK_HOME}/jars/*" && \

resource-managers/kubernetes/docker-minimal-bundle/src/main/docker/init-container/Dockerfile

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,10 @@
1515
# limitations under the License.
1616
#
1717

18-
FROM openjdk:8-alpine
18+
FROM spark-base
1919

2020
# If this docker file is being used in the context of building your images from a Spark distribution, the docker build
2121
# command should be invoked from the top level directory of the Spark distribution. E.g.:
2222
# docker build -t spark-executor:latest -f dockerfiles/executor/Dockerfile .
2323

24-
RUN apk upgrade --update
25-
RUN apk add --update bash tini
26-
RUN mkdir -p /opt/spark
27-
RUN touch /opt/spark/RELEASE
28-
29-
ADD jars /opt/spark/jars
30-
ADD bin /opt/spark/bin
31-
ADD sbin /opt/spark/sbin
32-
ADD conf /opt/spark/conf
33-
34-
ENV SPARK_HOME /opt/spark
35-
36-
WORKDIR /opt/spark
37-
3824
ENTRYPOINT [ "/sbin/tini", "--", "bin/spark-class", "org.apache.spark.deploy.rest.kubernetes.KubernetesSparkDependencyDownloadInitContainer" ]

resource-managers/kubernetes/docker-minimal-bundle/src/main/docker/resource-staging-server/Dockerfile

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,10 @@
1515
# limitations under the License.
1616
#
1717

18-
FROM openjdk:8-alpine
18+
FROM spark-base
1919

2020
# If this docker file is being used in the context of building your images from a Spark distribution, the docker build
2121
# command should be invoked from the top level directory of the Spark distribution. E.g.:
2222
# docker build -t spark-executor:latest -f dockerfiles/executor/Dockerfile .
2323

24-
RUN apk upgrade --update
25-
RUN apk add --update bash tini
26-
RUN mkdir -p /opt/spark
27-
RUN touch /opt/spark/RELEASE
28-
29-
ADD jars /opt/spark/jars
30-
ADD bin /opt/spark/bin
31-
ADD sbin /opt/spark/sbin
32-
ADD conf /opt/spark/conf
33-
34-
ENV SPARK_HOME /opt/spark
35-
36-
WORKDIR /opt/spark
37-
3824
ENTRYPOINT [ "/sbin/tini", "--", "bin/spark-class", "org.apache.spark.deploy.rest.kubernetes.ResourceStagingServer" ]

resource-managers/kubernetes/docker-minimal-bundle/src/main/docker/shuffle-service/Dockerfile

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,12 @@
1515
# limitations under the License.
1616
#
1717

18-
FROM openjdk:8-alpine
18+
FROM spark-base
1919

2020
# If this docker file is being used in the context of building your images from a Spark distribution, the docker build
2121
# command should be invoked from the top level directory of the Spark distribution. E.g.:
2222
# docker build -t spark-shuffle:latest -f dockerfiles/shuffle/Dockerfile .
2323

24-
RUN apk upgrade --update
25-
RUN apk add --update bash tini
26-
RUN mkdir -p /opt/spark
27-
RUN touch /opt/spark/RELEASE
28-
29-
ADD jars /opt/spark/jars
30-
ADD examples /opt/spark/examples
31-
ADD bin /opt/spark/bin
32-
ADD sbin /opt/spark/sbin
33-
ADD conf /opt/spark/conf
34-
35-
ENV SPARK_HOME /opt/spark
36-
37-
WORKDIR /opt/spark
24+
COPY examples /opt/spark/examples
3825

3926
ENTRYPOINT [ "/sbin/tini", "--", "bin/spark-class", "org.apache.spark.deploy.kubernetes.KubernetesExternalShuffleService", "1" ]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
FROM openjdk:8-alpine
18+
19+
# If this docker file is being used in the context of building your images from a Spark distribution, the docker build
20+
# command should be invoked from the top level directory of the Spark distribution. E.g.:
21+
# docker build -t spark-base:latest -f dockerfiles/spark-base/Dockerfile .
22+
23+
RUN apk upgrade --no-cache && \
24+
apk add --no-cache bash tini && \
25+
mkdir -p /opt/spark && \
26+
touch /opt/spark/RELEASE
27+
28+
COPY jars /opt/spark/jars
29+
COPY bin /opt/spark/bin
30+
COPY sbin /opt/spark/sbin
31+
COPY conf /opt/spark/conf
32+
33+
ENV SPARK_HOME /opt/spark
34+
35+
WORKDIR /opt/spark

resource-managers/kubernetes/integration-tests/src/test/scala/org/apache/spark/deploy/kubernetes/integrationtest/docker/SparkDockerImageBuilder.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ private[spark] class SparkDockerImageBuilder(private val dockerEnv: Map[String,
2828

2929
private val DOCKER_BUILD_PATH = Paths.get("target", "docker")
3030
// Dockerfile paths must be relative to the build path.
31+
private val BASE_DOCKER_FILE = "dockerfiles/spark-base/Dockerfile"
3132
private val DRIVER_DOCKER_FILE = "dockerfiles/driver/Dockerfile"
3233
private val EXECUTOR_DOCKER_FILE = "dockerfiles/executor/Dockerfile"
3334
private val SHUFFLE_SERVICE_DOCKER_FILE = "dockerfiles/shuffle-service/Dockerfile"
@@ -60,6 +61,7 @@ private[spark] class SparkDockerImageBuilder(private val dockerEnv: Map[String,
6061

6162
def buildSparkDockerImages(): Unit = {
6263
Eventually.eventually(TIMEOUT, INTERVAL) { dockerClient.ping() }
64+
buildImage("spark-base", BASE_DOCKER_FILE)
6365
buildImage("spark-driver", DRIVER_DOCKER_FILE)
6466
buildImage("spark-executor", EXECUTOR_DOCKER_FILE)
6567
buildImage("spark-shuffle", SHUFFLE_SERVICE_DOCKER_FILE)

0 commit comments

Comments
 (0)