cd42d4c73653de8d7c51ce7314d2c5e11295cfa9
[demo.git] / vnfs / DAaaS / applications / sample-spark-app / Dockerfile
1 # Copyright (c) 2019 Intel Corporation
2 # Licensed to the Apache Software Foundation (ASF) under one or more
3 # contributor license agreements.  See the NOTICE file distributed with
4 # this work for additional information regarding copyright ownership.
5 # The ASF licenses this file to You under the Apache License, Version 2.0
6 # (the "License"); you may not use this file except in compliance with
7 # the License.  You may obtain a copy of the License at
8 #
9 #    http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 # Ported kubernetes spark image to Ubuntu
19
20 FROM ubuntu:18.04
21
22 # Install jdk
23 RUN apt update -yqq 
24 RUN apt install -y locales openjdk-8-jdk && rm -rf /var/lib/apt/lists/* \
25     && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
26
27 # Install all the essentials
28 RUN apt-get update --fix-missing && \
29     apt-get install -y numactl wget curl bzip2 ca-certificates libglib2.0-0 libxext6 libsm6 libxrender1 \
30                        git mercurial subversion build-essential openssh-server openssh-client net-tools && \
31     apt-get clean && \
32     rm -rf /var/lib/apt/lists/*
33
34 ENV LANG en_US.utf8
35 ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
36 ENV PATH $JAVA_HOME/bin:$PATH
37 ENV PATH /opt/conda/bin:$PATH
38 ENV OPENMPI_VERSION 3.1
39
40 # Install openMPI
41 RUN mkdir /tmp/openmpi && \
42     cd /tmp/openmpi && \
43     wget --quiet https://www.open-mpi.org/software/ompi/v${OPENMPI_VERSION}/downloads/openmpi-${OPENMPI_VERSION}.2.tar.gz -O openmpi.tar.gz && \
44     tar zxf openmpi.tar.gz && \
45     cd openmpi-3.1.2 && \
46     ./configure --enable-orterun-prefix-by-default && \
47     make -j $(nproc) all && \
48     make install && \
49     ldconfig && \
50     rm -rf /tmp/openmpi
51
52 # Install miniconda
53 RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
54     /bin/bash ~/miniconda.sh -b -p /opt/conda && \
55     rm ~/miniconda.sh && \
56     ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
57     echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
58     echo "conda activate base" >> ~/.bashrc
59
60 # Install tf & keras using conda in the virtual_environment:tf_env
61 SHELL ["/bin/bash", "-c"]
62 RUN conda update -n base -c defaults conda && \
63     conda create -n tf_env
64 RUN conda install -n tf_env -y -c anaconda \
65     pip tensorflow keras nltk
66
67 RUN echo "conda activate tf_env" >> ~/.bashrc && \
68     conda install -n tf_env -y -c conda-forge clangdev
69
70 RUN source ~/.bashrc
71 RUN HOROVOD_WITH_TENSORFLOW=1 /opt/conda/envs/tf_env/bin/pip install --no-cache-dir horovod
72
73 # openMPI sane defaults:
74 RUN echo "hwloc_base_binding_policy = none" >> /usr/local/etc/openmpi-mca-params.conf && \
75     echo "rmaps_base_mapping_policy = slot" >> /usr/local/etc/openmpi-mca-params.conf && \
76     echo "btl_tcp_if_exclude = lo,docker0" >> /usr/local/etc/openmpi-mca-params.conf
77
78 # Allow OpenSSH to talk to containers without asking for confirmation
79 RUN cat /etc/ssh/ssh_config | grep -v StrictHostKeyChecking > /etc/ssh/ssh_config.new && \
80     echo "    StrictHostKeyChecking no" >> /etc/ssh/ssh_config.new && \
81     mv /etc/ssh/ssh_config.new /etc/ssh/ssh_config
82
83 # Install tini
84 RUN apt-get install -y curl grep sed dpkg && \
85     TINI_VERSION=`curl https://github.com/krallin/tini/releases/latest | grep -o "/v.*\"" | sed 's:^..\(.*\).$:\1:'` && echo ${TINI_VERSION} && \
86     curl -L "https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini_${TINI_VERSION}.deb" > tini.deb && \
87     dpkg -i tini.deb && \
88     rm tini.deb && \
89     apt clean
90
91 # This is needed to match the original entrypoint.sh file.
92 RUN cp /usr/bin/tini /sbin
93
94 # Begin: Installing spark
95 ARG spark_jars=jars
96 ARG img_path=kubernetes/dockerfiles
97 ARG k8s_tests=kubernetes/tests
98
99 # Before building the docker image, first build and make a Spark distribution following
100 # the instructions in http://spark.apache.org/docs/latest/building-spark.html.
101 # If this docker file is being used in the context of building your images from a Spark
102 # distribution, the docker build command should be invoked from the top level directory
103 # of the Spark distribution. E.g.:
104 # docker build -t spark:latest -f kubernetes/dockerfiles/spark/ubuntu18.04/Dockerfile .
105
106 RUN mkdir -p /opt/spark && \
107     mkdir -p /opt/spark/work-dir && \
108     touch /opt/spark/RELEASE && \
109     rm /bin/sh && \
110     ln -sv /bin/bash /bin/sh && \
111     echo "auth required pam_wheel.so use_uid" >> /etc/pam.d/su && \
112     chgrp root /etc/passwd && chmod ug+rw /etc/passwd
113
114
115 COPY ${spark_jars} /opt/spark/jars
116 COPY bin /opt/spark/bin
117 COPY sbin /opt/spark/sbin
118 COPY ${img_path}/spark/entrypoint.sh /opt/
119 COPY examples /opt/spark/examples
120 COPY ${k8s_tests} /opt/spark/tests
121 COPY data /opt/spark/data
122 ENV SPARK_HOME /opt/spark
123
124 RUN mkdir /opt/spark/python
125 COPY python/pyspark /opt/spark/python/pyspark
126 COPY python/lib /opt/spark/python/lib
127 ENV PYTHONPATH /opt/spark/python/lib/pyspark.zip:/opt/spark/python/lib/py4j-*.zip
128
129 WORKDIR /opt/spark/work-dir
130
131 ENTRYPOINT [ "/opt/entrypoint.sh" ]
132
133 # End: Installing spark