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