0c06de4e382816179787218d30a6f44ca6893209
[ta/remote-installer.git] / docker-build / remote-installer / Dockerfile
1 # Copyright 2019 Nokia
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 FROM centos:7.6.1810
16 MAINTAINER Ralf Mueller <ralf.1.mueller@nokia.com>
17
18 ENV \
19 ETC_REMOTE_INST="/etc/remoteinstaller" \
20 PW="root" \
21 API_PORT="15101" \
22 API_LISTEN_ADDR="0.0.0.0" \
23 HTTPS_PORT="443" \
24 HOST_ADDR="127.0.0.1" \
25 STARTUP="/etc/remoteinstaller/startup.sh" \
26 CA_CERT="cacert.pem" \
27 CLIENT_CERT="clientcert.pem" \
28 CLIENT_KEY="clientkey.pem" \
29 SERVER_CERT="servercert.pem" \
30 SERVER_KEY="serverkey.pem" \
31 INSTALLER_MOUNT="/opt/remoteinstaller"
32
33 ENV IMAGES_STORE="$INSTALLER_MOUNT/images"
34 ENV IMAGES_HTML="/var/www/lighttpd/images"
35
36 RUN mkdir -p "$INSTALLER_MOUNT"
37
38 # prepare for basic systemd services
39 RUN yum -y install systemd epel-release; yum clean all \
40 && (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done) \
41 && rm -f /lib/systemd/system/multi-user.target.wants/* \
42 && rm -f /etc/systemd/system/*.wants/* \
43 && rm -f /lib/systemd/system/local-fs.target.wants/* \
44 && rm -f /lib/systemd/system/sockets.target.wants/*udev* \
45 && rm -f /lib/systemd/system/sockets.target.wants/*initctl* \
46 && rm -f /lib/systemd/system/basic.target.wants/* \
47 && rm -f /lib/systemd/system/anaconda.target.wants/* \
48 \
49 # Services for the workload \
50 && yum install -y iproute wget openssh-server lighttpd nfs-utils \
51 python-setuptools python2-eventlet python-routes PyYAML \
52 python-netaddr pexpect net-tools tcpdump \
53 ipmitool \
54 # mod_ssl \
55 && systemctl enable sshd \
56 && systemctl enable lighttpd \
57 && systemctl enable nfs-server \
58 && echo "$IMAGES_STORE" "*(rw,sync,no_root_squash,no_all_squash)" >>/etc/exports
59
60
61 # lighthttpd configuration
62
63 RUN sed -i 's/server.use-ipv6 = "enable"/server.use-ipv6 = "disable"/' /etc/lighttpd/lighttpd.conf \
64 && echo $'\n\
65 # SSL configuration\n\
66 ssl.engine = "enable"\n\
67 ssl.privkey = "/opt/remoteinstaller/certificates/serverkey.pem"\n\
68 ssl.pemfile = "/opt/remoteinstaller/certificates/servercert.pem"\n\
69 ssl.ca-file = "/opt/remoteinstaller/certificates/cacert.pem"\n\
70 ssl.verifyclient.activate = "enable"\n\
71 ssl.verifyclient.enforce = "enable"\n\
72 ' >> /etc/lighttpd/lighttpd.conf \
73 && mkdir -p "$IMAGES_HTML"
74
75
76 # Install hw-detector from LF
77 RUN wget -O x.tgz 'https://gerrit.akraino.org/r/gitweb?p=ta/hw-detector.git;a=snapshot;h=HEAD;sf=tgz' \
78 && tar -xzf x.tgz \
79 && rm -f x.tgz \
80 && pushd hw-detector*/src \
81 && python setup.py install \
82 && popd \
83 && rm -rf hw-detector*
84
85
86 # Install remote-installer to image
87 COPY src "$INSTALLER_MOUNT"
88 RUN pushd "$INSTALLER_MOUNT" \
89 && python setup.py install \
90 && rm -rf * \
91 && popd
92
93 RUN mkdir -p "$ETC_REMOTE_INST"
94
95 RUN echo '#!/bin/bash' >>$STARTUP \
96 && echo 'printenv >/etc/remoteinstaller/environment' >>$STARTUP \
97 && echo mkdir /run/systemd/system >>$STARTUP \
98 && echo nohup /usr/lib/systemd/systemd --system '&>/dev/null &' >>$STARTUP \
99 && echo "echo -e \"\$PW\n\$PW\n\n\" |passwd" >>$STARTUP \
100 && echo mount -o bind "$IMAGES_STORE" "$IMAGES_HTML" >>$STARTUP \
101 && echo 'sed -i "s/server.port = 80/server.port = $HTTPS_PORT/" /etc/lighttpd/lighttpd.conf' >>$STARTUP \
102 # && echo "echo \\\$SERVER[\\\"sockets\\\"] == \\\"0.0.0.0:\$HTTPS_PORT {}\\\" >> /etc/lighttpd/lighttpd.conf" >>$STARTUP \
103 && echo python /lib/python2.7/site-packages/remoteinstaller-1.0-py2.7.egg/remoteinstaller/server/server.py \
104    -H \$API_LISTEN_ADDR -P \$API_PORT -S \$HOST_ADDR \
105    -C \$SERVER_CERT -K \$SERVER_KEY -c \$CLIENT_CERT -k \$CLIENT_KEY -A \$CA_CERT -d \
106    >>$STARTUP \
107 && echo 'while [ false ]; do sleep 5 ;done' >>$STARTUP  \
108 && chmod +x $STARTUP
109
110 ENTRYPOINT ["/etc/remoteinstaller/startup.sh"]
111
112 #  CMD [ "arg1" ]
113