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