Use ubuntu for containers
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / rapid / Dockerfile
1 ##
2 ## Copyright (c) 2019 Intel Corporation
3 ##
4 ## Licensed under the Apache License, Version 2.0 (the "License");
5 ## you may not use this file except in compliance with the License.
6 ## You may obtain a copy of the License at
7 ##
8 ##     http://www.apache.org/licenses/LICENSE-2.0
9 ##
10 ## Unless required by applicable law or agreed to in writing, software
11 ## distributed under the License is distributed on an "AS IS" BASIS,
12 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ## See the License for the specific language governing permissions and
14 ## limitations under the License.
15 ##
16
17 ##################################################
18 # Build all components in separate builder image #
19 ##################################################
20
21 FROM ubuntu:20.04 as builder
22
23 ARG DPDK_VERSION=22.07
24 ENV DPDK_VERSION=${DPDK_VERSION}
25
26 ARG BUILD_DIR="/opt/rapid"
27 ENV BUILD_DIR=${BUILD_DIR}
28
29 ENV DEBIAN_FRONTEND=noninteractive
30
31 # Install Dependencies
32 RUN apt update && apt -y install git wget gcc unzip libpcap-dev libncurses5-dev \
33         libedit-dev liblua5.3-dev linux-headers-generic iperf3 pciutils \
34         libnuma-dev vim tuna wireshark make driverctl openssh-server sudo \
35         meson python3-pyelftools pkg-config
36
37 WORKDIR ${BUILD_DIR}
38
39 # Install DPDK
40 RUN wget http://fast.dpdk.org/rel/dpdk-${DPDK_VERSION}.tar.xz \
41     && tar -xf ./dpdk-${DPDK_VERSION}.tar.xz \
42     && cd dpdk-${DPDK_VERSION} \
43     && meson build -Dlibdir=lib/x86_64-linux-gnu -Denable_driver_sdk=true \
44     && ninja -C build install
45
46 WORKDIR ${BUILD_DIR}
47
48 # Install Prox
49 RUN git clone https://gerrit.opnfv.org/gerrit/samplevnf \
50     && cd samplevnf/VNFs/DPPD-PROX \
51     && COMMIT_ID=$(git rev-parse HEAD) \
52     && echo "${COMMIT_ID}" > ${BUILD_DIR}/commit_id \
53     && meson build \
54     && ninja -C build \
55     && cp ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX/build/prox ${BUILD_DIR}/prox
56
57 # Build and copy port info app
58 WORKDIR ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX/helper-scripts/rapid/port_info
59 RUN meson build \
60     && ninja -C build \
61     && cp ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX/helper-scripts/rapid/port_info/build/port_info_app ${BUILD_DIR}/port_info_app
62
63 RUN ldconfig && pkg-config --modversion libdpdk > ${BUILD_DIR}/dpdk_version
64 # Create Minimal Install
65 RUN ldd ${BUILD_DIR}/prox | awk '$2 ~ /=>/ {print $3}' >> ${BUILD_DIR}/list_of_install_components \
66     && echo "${BUILD_DIR}/prox" >> ${BUILD_DIR}/list_of_install_components \
67     && echo "${BUILD_DIR}/port_info_app" >> ${BUILD_DIR}/list_of_install_components \
68     && echo "${BUILD_DIR}/commit_id" >> ${BUILD_DIR}/list_of_install_components \
69     && echo "${BUILD_DIR}/dpdk_version" >> ${BUILD_DIR}/list_of_install_components \
70     && find /usr/local/lib/x86_64-linux-gnu -not -path '*/\.*' >> ${BUILD_DIR}/list_of_install_components \
71     && tar -czvhf ${BUILD_DIR}/install_components.tgz -T ${BUILD_DIR}/list_of_install_components
72
73 #############################
74 # Create slim runtime image #
75 #############################
76 FROM ubuntu:20.04
77
78 ARG BUILD_DIR="/opt/rapid"
79 ENV BUILD_DIR=${BUILD_DIR}
80
81 ENV DEBIAN_FRONTEND=noninteractive
82
83 # Install Runtime  Dependencies
84 RUN apt update -y
85 # Install required dynamically linked libraries + required packages
86 RUN apt -y install sudo openssh-server libatomic1
87
88 COPY --from=builder ${BUILD_DIR}/install_components.tgz ${BUILD_DIR}/install_components.tgz
89
90 WORKDIR /
91 RUN tar -xvf ${BUILD_DIR}/install_components.tgz --skip-old-files
92 RUN ldconfig
93 RUN rm ${BUILD_DIR}/install_components.tgz
94
95 # Expose SSH and PROX ports
96 EXPOSE 22 8474
97
98 RUN useradd -rm -d /home/rapid -s /bin/bash -g root -G sudo -u 1000 rapid \
99     && chmod 777 ${BUILD_DIR} \
100     && echo 'rapid:rapid' | chpasswd \
101     && mkdir /home/rapid/.ssh
102
103 # Copy SSH keys
104 COPY ./rapid_rsa_key.pub /home/rapid/.ssh/authorized_keys
105 COPY ./rapid_rsa_key.pub /root/.ssh/authorized_keys
106
107 RUN chown rapid:root /home/rapid/.ssh/authorized_keys \
108  && chmod 600 /home/rapid/.ssh/authorized_keys \
109  && chown root:root /root/.ssh/authorized_keys \
110  && chmod 600 /root/.ssh/authorized_keys
111
112 #RUN apt-get clean && apt autoremove --purge
113 RUN apt-get autoremove -y && apt-get clean all && rm -rf /var/cache/apt
114
115 # Copy startup script
116 COPY ./start.sh /start.sh
117 RUN chmod +x /start.sh
118
119 ENTRYPOINT ["/start.sh"]