98f6cebd8e4b4eba14af98e266cb56854f0192d4
[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 SCRIPTS_DIR="/opt/scripts" \
21 PW="root" \
22 API_PORT="15101" \
23 API_LISTEN_ADDR="0.0.0.0" \
24 HTTPS_PORT="443" \
25 HOST_ADDR="127.0.0.1" \
26 STARTUP="/etc/remoteinstaller/startup.sh" \
27 CA_CERT="cacert.pem" \
28 CLIENT_CERT="clientcert.pem" \
29 CLIENT_KEY="clientkey.pem" \
30 SERVER_CERT="servercert.pem" \
31 SERVER_KEY="serverkey.pem" \
32 INSTALLER_MOUNT="/opt/remoteinstaller" \
33 SSH_PORT="22"
34
35 ENV IMAGES_STORE="$INSTALLER_MOUNT/images"
36 ENV IMAGES_HTML="/var/www/lighttpd/images"
37
38 RUN mkdir -p "$INSTALLER_MOUNT"
39
40 # prepare for basic systemd services
41 RUN yum -y install systemd epel-release; yum clean all \
42 && (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done) \
43 && rm -f /lib/systemd/system/multi-user.target.wants/* \
44 && rm -f /etc/systemd/system/*.wants/* \
45 && rm -f /lib/systemd/system/local-fs.target.wants/* \
46 && rm -f /lib/systemd/system/sockets.target.wants/*udev* \
47 && rm -f /lib/systemd/system/sockets.target.wants/*initctl* \
48 && rm -f /lib/systemd/system/basic.target.wants/* \
49 && rm -f /lib/systemd/system/anaconda.target.wants/* \
50 \
51 # Services for the workload \
52 && yum install -y iproute wget openssh-server lighttpd nfs-utils \
53 python-setuptools python2-eventlet python-routes PyYAML \
54 python-netaddr pexpect net-tools tcpdump \
55 ipmitool openssh-clients sshpass nmap-ncat \
56 # mod_ssl \
57 && systemctl enable sshd \
58 && systemctl enable lighttpd \
59 && systemctl enable nfs-server \
60 && echo "$IMAGES_STORE" "*(rw,sync,no_root_squash,no_all_squash)" >>/etc/exports
61
62
63 # lighthttpd configuration
64
65 RUN sed -i 's/server.use-ipv6 = "enable"/server.use-ipv6 = "disable"/' /etc/lighttpd/lighttpd.conf \
66 && echo $'\n\
67 # SSL configuration\n\
68 ssl.engine = "enable"\n\
69 ssl.privkey = "/opt/remoteinstaller/certificates/serverkey.pem"\n\
70 ssl.pemfile = "/opt/remoteinstaller/certificates/servercert.pem"\n\
71 ssl.ca-file = "/opt/remoteinstaller/certificates/cacert.pem"\n\
72 ssl.verifyclient.activate = "enable"\n\
73 ssl.verifyclient.enforce = "enable"\n\
74 ' >> /etc/lighttpd/lighttpd.conf \
75 && mkdir -p "$IMAGES_HTML"
76
77
78 # Install hw-detector from LF
79 RUN wget -O x.tgz 'https://gerrit.akraino.org/r/gitweb?p=ta/hw-detector.git;a=snapshot;h=HEAD;sf=tgz' \
80 && tar -xzf x.tgz \
81 && rm -f x.tgz \
82 && pushd hw-detector*/src \
83 && python setup.py install \
84 && popd \
85 && rm -rf hw-detector*
86
87
88 # Install remote-installer to image
89 COPY src "$INSTALLER_MOUNT"
90 RUN pushd "$INSTALLER_MOUNT" \
91 && python setup.py install \
92 && rm -rf * \
93 && popd
94
95 RUN mkdir -p "$SCRIPTS_DIR" \
96 && mkdir -p "$ETC_REMOTE_INST"
97
98 COPY src/scripts/get_journals.sh src/scripts/print_hosts.py "$SCRIPTS_DIR"/
99
100 RUN echo '#!/bin/bash -x' >>$STARTUP \
101 && echo "function handle_sigterm() {" >>$STARTUP \
102 && echo -e "  echo Stopping nfs-server" >>$STARTUP \
103 && echo -e "  systemctl stop nfs-server" >>$STARTUP \
104 && echo -e "  exit 0" >>$STARTUP \
105 && echo "}" >>$STARTUP \
106 && echo "trap 'handle_sigterm' 15" >>$STARTUP \
107 && echo 'printenv >/etc/remoteinstaller/environment' >>$STARTUP \
108 && echo 'mkdir /run/systemd/system' >>$STARTUP \
109 && echo 'nohup /usr/lib/systemd/systemd --system' '&>/dev/null &' >>$STARTUP \
110 && echo "echo -e \"\$PW\n\$PW\n\n\" |passwd" >>$STARTUP \
111 && echo mount -o bind "$IMAGES_STORE" "$IMAGES_HTML" >>$STARTUP \
112 && echo 'sed -i "s/server.port = 80/server.port = $HTTPS_PORT/" /etc/lighttpd/lighttpd.conf' >>$STARTUP \
113 && echo 'sed -i "s/.*Port 22/Port $SSH_PORT/" /etc/ssh/sshd_config' >>$STARTUP \
114 # && echo "echo \\\$SERVER[\\\"sockets\\\"] == \\\"0.0.0.0:\$HTTPS_PORT {}\\\" >> /etc/lighttpd/lighttpd.conf" >>$STARTUP \
115 && echo python /lib/python2.7/site-packages/remoteinstaller-1.0-py2.7.egg/remoteinstaller/server/server.py \
116    -H \$API_LISTEN_ADDR -P \$API_PORT -S \$HOST_ADDR -T \$HTTPS_PORT \
117    -C \$SERVER_CERT -K \$SERVER_KEY -c \$CLIENT_CERT -k \$CLIENT_KEY -A \$CA_CERT -d \& \
118    >>$STARTUP \
119 && echo 'while [ false ]; do sleep 5 ;done' >>$STARTUP  \
120 && chmod +x $STARTUP
121
122 ENTRYPOINT ["/etc/remoteinstaller/startup.sh"]
123
124 #  CMD [ "arg1" ]
125