Bug fixes for SIM-72.
[sim/o1-interface.git] / ntsimulator / deploy / base / ubuntu.Dockerfile
1 #
2 # Copyright 2020 highstreet technologies GmbH and others
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 #### BUILDER ####
18 #################
19
20 FROM ubuntu:20.04 as builder
21 LABEL maintainer="alexandru.stancu@highstreet-technologies.com / adrian.lita@highstreet-technologies.com"
22
23 RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y \
24     # basic tools
25     tzdata build-essential git cmake pkg-config \
26     # libyang dependencies
27     libpcre3-dev \
28     # libssh dependencies
29     zlib1g-dev libssl-dev \
30     && rm -rf /var/lib/apt/lists/*
31
32 # add netconf user and configure access
33 RUN \
34     adduser --system netconf && \
35     echo "netconf:netconf!" | chpasswd
36
37 # use /opt/dev as working directory
38 RUN mkdir /opt/dev
39 WORKDIR /opt/dev
40
41 # get required build libs from git
42 RUN \
43     git config --global advice.detachedHead false && \
44     git clone --single-branch --branch v1.7.14 https://github.com/DaveGamble/cJSON.git && \
45     git clone --single-branch --branch v1.0.240 https://github.com/CESNET/libyang.git && \
46     git clone --single-branch --branch v1.4.140 https://github.com/sysrepo/sysrepo.git && \
47     git clone --single-branch --branch libssh-0.9.2 https://git.libssh.org/projects/libssh.git && \
48     git clone --single-branch --branch v1.1.46 https://github.com/CESNET/libnetconf2.git && \
49     git clone --single-branch --branch v1.1.76 https://github.com/CESNET/netopeer2.git && \
50     git clone --single-branch --branch curl-7_72_0 https://github.com/curl/curl.git
51
52 # build and install cJSON
53 RUN \
54     cd cJSON && \
55     mkdir build && cd build && \
56     cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_CJSON_TEST=Off && \
57     make -j4 && \
58     make install && \
59     ldconfig
60
61 # build and install libyang
62 RUN \
63     cd libyang && \
64     mkdir build && cd build  && \
65     cmake -DCMAKE_BUILD_TYPE:String="Release" -DGEN_LANGUAGE_BINDINGS=ON -DGEN_CPP_BINDINGS=ON -DGEN_PYTHON_BINDINGS=OFF -DENABLE_BUILD_TESTS=OFF .. && \
66     make -j4  && \
67     make install && \
68     ldconfig
69
70 # build and install sysrepo
71 COPY ./deploy/base/common.h.in /opt/dev/sysrepo/src/common.h.in
72 RUN \
73     cd sysrepo && \
74     mkdir build && cd build  && \
75     cmake -DCMAKE_BUILD_TYPE:String="Release" -DGEN_LANGUAGE_BINDINGS=ON -DGEN_CPP_BINDINGS=ON -DGEN_PYTHON_BINDINGS=OFF -DENABLE_TESTS=OFF -DREPOSITORY_LOC:PATH=/etc/sysrepo -DREQUEST_TIMEOUT=60 -DOPER_DATA_PROVIDE_TIMEOUT=60 .. && \
76     make -j4 && \
77     make install && \
78     ldconfig
79
80 # build and install libssh-dev
81 RUN \
82     cd libssh && \
83     mkdir build && cd build  && \
84     cmake -DWITH_EXAMPLES=OFF ..  && \
85     make -j4 && \
86     make install && \
87     ldconfig
88
89 # build and install libnetconf2
90 RUN \
91     cd libnetconf2 && \
92     mkdir build && cd build && \
93     cmake -DCMAKE_BUILD_TYPE:String="Release" -DENABLE_BUILD_TESTS=OFF .. && \
94     make -j4 && \
95     make install && \
96     ldconfig
97
98 # build and install netopeer2
99 RUN \
100     cd netopeer2 && \
101     mkdir build && cd build && \
102     cmake -DCMAKE_BUILD_TYPE:String="Release" -DGENERATE_HOSTKEY=OFF -DMERGE_LISTEN_CONFIG=OFF .. && \
103     make -j4 && \
104     make install
105
106 # build and install cURL
107 RUN \
108     cd curl && \
109     mkdir build && cd build && \
110     cmake -DBUILD_TESTING=OFF .. && \
111     make -j4 && \
112     make install && \
113     ldconfig
114
115 # regxstring copy, build and install
116 RUN mkdir /opt/dev/regxstring
117 COPY ./regxstring /opt/dev/regxstring
118 COPY ./deploy/base/build_regxstring.sh /opt/dev/regxstring/build_regxstring.sh
119 RUN \
120     cd /opt/dev/regxstring && \
121     ./build_regxstring.sh && \
122     cp regxstring /usr/bin && \
123     cd ..
124
125 # ntsim-ng copy and build
126 ARG BUILD_WITH_DEBUG
127 ENV BUILD_WITH_DEBUG=${BUILD_WITH_DEBUG}
128
129 RUN \
130     mkdir /opt/dev/ntsim-ng && \
131     mkdir /opt/dev/ntsim-ng/config && \
132     mkdir /opt/dev/ntsim-ng/source
133 COPY ./ntsim-ng /opt/dev/ntsim-ng/source
134 COPY ./deploy/base/build_ntsim-ng.sh /opt/dev/ntsim-ng/build_ntsim-ng.sh
135 RUN \
136     cd /opt/dev/ntsim-ng && \
137     sed -i '/argp/d' build_ntsim-ng.sh && \
138     ./build_ntsim-ng.sh && \
139     rm -rf source && \
140     rm -f build_ntsim-ng.sh
141
142 # copy SSH related scripts and keys
143 COPY ./deploy/base/ca.key /home/netconf/.ssh/ca.key
144 COPY ./deploy/base/ca.pem /home/netconf/.ssh/ca.pem
145 COPY ./deploy/base/client.crt /home/netconf/.ssh/client.crt
146 COPY ./deploy/base/client.key /home/netconf/.ssh/client.key
147 COPY ./deploy/base/generate-ssh-keys.sh /home/netconf/.ssh/generate-ssh-keys.sh
148
149 #############################
150 #### Lightweight Base ####
151 #############################
152
153
154 FROM ubuntu:20.04
155 LABEL maintainer="alexandru.stancu@highstreet-technologies.com / adrian.lita@highstreet-technologies.com"
156
157 RUN apt-get update && apt-get install -y --no-install-recommends \
158     psmisc \
159     unzip \
160     openssl \
161     openssh-client \
162     vsftpd \
163     openssh-server \
164     && rm -rf /var/lib/apt/lists/*
165     
166
167 ARG BUILD_WITH_DEBUG
168 ENV BUILD_WITH_DEBUG=${BUILD_WITH_DEBUG}
169 RUN if [ -n "${BUILD_WITH_DEBUG}" ]; then DEBIAN_FRONTEND="noninteractive" apt-get install -y gdb valgrind nano mc && unset BUILD_WITH_DEBUG; fi
170
171 # add netconf user and configure access
172 RUN \
173     adduser netconf && \
174     echo "netconf:netconf!" | chpasswd && \
175     mkdir -p /home/netconf/.ssh
176
177 COPY --from=builder /usr/local/bin /usr/local/bin
178 COPY --from=builder /usr/local/lib /usr/local/lib
179 COPY --from=builder /usr/local/share /usr/local/share
180
181 COPY --from=builder /etc/sysrepo /etc/sysrepo
182 RUN ldconfig
183
184 # use /opt/dev as working directory
185 RUN mkdir /opt/dev
186 WORKDIR /opt/dev
187
188 # copy common NTS yang models
189 RUN mkdir /opt/dev/deploy
190 COPY ./deploy/base/yang /opt/dev/deploy/yang
191
192 # copy ntsim-ng and dependencies
193 COPY --from=builder /usr/bin/regxstring /usr/bin/regxstring
194 COPY --from=builder /opt/dev/ntsim-ng /opt/dev/ntsim-ng
195
196 # copy SSH related scripts and keys
197 COPY --from=builder /home/netconf/.ssh /home/netconf/.ssh
198
199 ### FTP and SFTP configuration
200 RUN \
201     mkdir /ftp && \
202     chown -R netconf:netconf /ftp && \
203     mkdir /var/run/vsftpd && \
204     mkdir /var/run/vsftpd/empty  && \
205     mkdir /run/sshd && \
206     echo "Match User netconf\n    ChrootDirectory /\n    X11Forwarding no\n    AllowTcpForwarding no\n    ForceCommand internal-sftp -d /ftp" >> /etc/ssh/sshd_config
207
208 COPY ./deploy/base/vsftpd.conf /etc/vsftpd.conf
209 COPY ./deploy/base/vsftpd.userlist /etc/vsftpd.userlist
210 COPY ./deploy/base/pm_files /ftp
211
212 WORKDIR /opt/dev/workspace
213
214 ENV SSH_CONNECTIONS=1
215 ENV TLS_CONNECTIONS=0
216 ENV IPv6_ENABLED=false
217
218 ARG NTS_BUILD_VERSION
219 ENV NTS_BUILD_VERSION=${NTS_BUILD_VERSION}
220
221 ARG NTS_BUILD_DATE
222 ENV NTS_BUILD_DATE=${NTS_BUILD_DATE}