Collectd operator utilties
[demo.git] / vnfs / DAaaS / sample-apps / training / sample-horovod-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 nmap vim ca-certificates libglib2.0-0 libxext6 libsm6 libxrender1 \
30                        git mercurial subversion build-essential openssh-server openssh-client net-tools && \
31     mkdir -p /var/run/sshd && \
32     apt-get clean && \
33     rm -rf /var/lib/apt/lists/*
34
35 ENV LANG en_US.utf8
36 ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
37 ENV PATH $JAVA_HOME/bin:$PATH
38 ENV PATH /opt/conda/bin:/opt/spark/bin:$PATH
39 ENV OPENMPI_VERSION 3.1
40
41 # Install openMPI
42 RUN mkdir /tmp/openmpi && \
43     cd /tmp/openmpi && \
44     wget --quiet https://www.open-mpi.org/software/ompi/v${OPENMPI_VERSION}/downloads/openmpi-${OPENMPI_VERSION}.2.tar.gz -O openmpi.tar.gz && \
45     tar zxf openmpi.tar.gz && \
46     cd openmpi-3.1.2 && \
47     ./configure --enable-orterun-prefix-by-default && \
48     make -j $(nproc) all && \
49     make install && \
50     ldconfig && \
51     rm -rf /tmp/openmpi
52
53 # Install miniconda
54 RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
55     /bin/bash ~/miniconda.sh -b -p /opt/conda && \
56     rm ~/miniconda.sh && \
57     ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
58     echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
59     echo "conda activate base" >> ~/.bashrc
60
61 # Install tf & keras using conda in the virtual_environment:tf_env
62 SHELL ["/bin/bash", "-c"]
63 RUN conda update -n base -c defaults conda && \
64     conda create -n tf_env
65 RUN conda install -n tf_env -y -c anaconda \
66     pip tensorflow keras nltk pyarrow
67 RUN conda install -n tf_env -y -c anaconda h5py
68
69 RUN conda install -n tf_env -y -c pytorch pytorch-cpu
70 RUN conda install -n tf_env -y -c conda-forge matplotlib
71
72 RUN echo "conda activate tf_env" >> ~/.bashrc && \
73     conda install -n tf_env -y -c conda-forge clangdev
74
75 RUN source ~/.bashrc
76 RUN HOROVOD_WITH_TENSORFLOW=1 /opt/conda/envs/tf_env/bin/pip install --no-cache-dir horovod
77
78 # openMPI sane defaults:
79 RUN echo "hwloc_base_binding_policy = none" >> /usr/local/etc/openmpi-mca-params.conf && \
80     echo "rmaps_base_mapping_policy = slot" >> /usr/local/etc/openmpi-mca-params.conf && \
81     echo "btl_tcp_if_exclude = lo,docker0" >> /usr/local/etc/openmpi-mca-params.conf
82
83 # Allow OpenSSH to talk to containers without asking for confirmation
84 RUN cat /etc/ssh/ssh_config | grep -v StrictHostKeyChecking > /etc/ssh/ssh_config.new && \
85     echo "    StrictHostKeyChecking no" >> /etc/ssh/ssh_config.new && \
86     mv /etc/ssh/ssh_config.new /etc/ssh/ssh_config
87
88 # Install tini
89 RUN apt-get install -y curl grep sed dpkg && \
90     TINI_VERSION=`curl https://github.com/krallin/tini/releases/latest | grep -o "/v.*\"" | sed 's:^..\(.*\).$:\1:'` && echo ${TINI_VERSION} && \
91     curl -L "https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini_${TINI_VERSION}.deb" > tini.deb && \
92     dpkg -i tini.deb && \
93     rm tini.deb && \
94     apt clean
95
96 # This is needed to match the original entrypoint.sh file.
97 RUN cp /usr/bin/tini /sbin
98
99 # Begin: Installing spark
100 ARG spark_jars=jars
101 ARG img_path=kubernetes/dockerfiles
102 ARG k8s_tests=kubernetes/tests
103
104 # Before building the docker image, first build and make a Spark distribution following
105 # the instructions in http://spark.apache.org/docs/latest/building-spark.html.
106 # If this docker file is being used in the context of building your images from a Spark
107 # distribution, the docker build command should be invoked from the top level directory
108 # of the Spark distribution. E.g.:
109 # docker build -t spark:latest -f kubernetes/dockerfiles/spark/ubuntu18.04/Dockerfile .
110
111 RUN mkdir -p /opt/spark && \
112     mkdir -p /opt/spark/work-dir && \
113     touch /opt/spark/RELEASE && \
114     rm /bin/sh && \
115     ln -sv /bin/bash /bin/sh && \
116     echo "auth required pam_wheel.so use_uid" >> /etc/pam.d/su && \
117     chgrp root /etc/passwd && chmod ug+rw /etc/passwd
118
119
120 COPY ${spark_jars} /opt/spark/jars
121 COPY bin /opt/spark/bin
122 COPY sbin /opt/spark/sbin
123 COPY ${img_path}/spark/entrypoint.sh /opt/
124
125 COPY ${k8s_tests} /opt/spark/tests
126 COPY data /opt/spark/data
127 ENV SPARK_HOME /opt/spark
128
129 RUN mkdir /opt/spark/python
130 COPY python/pyspark /opt/spark/python/pyspark
131 COPY python/lib /opt/spark/python/lib
132 ENV PYTHONPATH /opt/spark/python/lib/pyspark.zip:/opt/spark/python/lib/py4j-*.zip
133 ENV PATH /opt/conda/envs/tf_env/bin:$PATH
134
135 RUN echo "export PATH=/opt/conda/envs/tf_env/bin:$PATH" >> ~/.bashrc
136 #    echo "activate tf_env\n" >> ~/.bashrc
137 RUN pip install petastorm
138 COPY examples /opt/spark/examples
139 WORKDIR /opt/spark/work-dir
140
141 ENTRYPOINT [ "/opt/entrypoint.sh" ]
142
143 # End: Installing spark