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