blob: cacd9d19c660cd7f26750f8631626e60a73b0aa7 [file] [log] [blame]
Alex Stancuf1d5c912020-11-02 17:34:59 +02001#
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
20FROM ubuntu:20.04 as builder
21LABEL maintainer="alexandru.stancu@highstreet-technologies.com / adrian.lita@highstreet-technologies.com"
Alex Stancu3bbf9d82021-04-09 15:13:00 +030022
Alex Stancua58e0a02021-06-02 12:22:14 +030023RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y \
Alex Stancuf1d5c912020-11-02 17:34:59 +020024 # basic tools
Alex Stancu3bbf9d82021-04-09 15:13:00 +030025 tzdata build-essential git cmake pkg-config \
Alex Stancuf1d5c912020-11-02 17:34:59 +020026 # libyang dependencies
27 libpcre3-dev \
28 # libssh dependencies
Alex Stancu3bbf9d82021-04-09 15:13:00 +030029 zlib1g-dev libssl-dev \
30 && rm -rf /var/lib/apt/lists/*
Alex Stancuf1d5c912020-11-02 17:34:59 +020031
32# add netconf user and configure access
33RUN \
34 adduser --system netconf && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030035 echo "netconf:netconf!" | chpasswd
Alex Stancuf1d5c912020-11-02 17:34:59 +020036
37# use /opt/dev as working directory
38RUN mkdir /opt/dev
39WORKDIR /opt/dev
40
41# get required build libs from git
42RUN \
43 git config --global advice.detachedHead false && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030044 git clone --single-branch --branch v1.7.14 https://github.com/DaveGamble/cJSON.git && \
Alex Stancu1d488822021-06-02 13:45:14 +030045 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 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +020047 git clone --single-branch --branch libssh-0.9.2 https://git.libssh.org/projects/libssh.git && \
Alex Stancu1d488822021-06-02 13:45:14 +030048 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 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +020050 git clone --single-branch --branch curl-7_72_0 https://github.com/curl/curl.git
51
52# build and install cJSON
53RUN \
54 cd cJSON && \
55 mkdir build && cd build && \
56 cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_CJSON_TEST=Off && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030057 make -j4 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +020058 make install && \
59 ldconfig
60
61# build and install libyang
62RUN \
63 cd libyang && \
64 mkdir build && cd build && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030065 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 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +020067 make install && \
68 ldconfig
69
70# build and install sysrepo
Alex Stancu3bbf9d82021-04-09 15:13:00 +030071COPY ./deploy/base/common.h.in /opt/dev/sysrepo/src/common.h.in
Alex Stancuf1d5c912020-11-02 17:34:59 +020072RUN \
73 cd sysrepo && \
74 mkdir build && cd build && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030075 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 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +020077 make install && \
78 ldconfig
79
80# build and install libssh-dev
81RUN \
82 cd libssh && \
83 mkdir build && cd build && \
84 cmake -DWITH_EXAMPLES=OFF .. && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030085 make -j4 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +020086 make install && \
87 ldconfig
88
Alex Stancuf1d5c912020-11-02 17:34:59 +020089# build and install libnetconf2
90RUN \
91 cd libnetconf2 && \
92 mkdir build && cd build && \
93 cmake -DCMAKE_BUILD_TYPE:String="Release" -DENABLE_BUILD_TESTS=OFF .. && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030094 make -j4 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +020095 make install && \
96 ldconfig
97
98# build and install netopeer2
99RUN \
100 cd netopeer2 && \
101 mkdir build && cd build && \
102 cmake -DCMAKE_BUILD_TYPE:String="Release" -DGENERATE_HOSTKEY=OFF -DMERGE_LISTEN_CONFIG=OFF .. && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300103 make -j4 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +0200104 make install
105
106# build and install cURL
107RUN \
108 cd curl && \
109 mkdir build && cd build && \
110 cmake -DBUILD_TESTING=OFF .. && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300111 make -j4 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +0200112 make install && \
113 ldconfig
114
115# regxstring copy, build and install
116RUN mkdir /opt/dev/regxstring
117COPY ./regxstring /opt/dev/regxstring
118COPY ./deploy/base/build_regxstring.sh /opt/dev/regxstring/build_regxstring.sh
119RUN \
120 cd /opt/dev/regxstring && \
121 ./build_regxstring.sh && \
122 cp regxstring /usr/bin && \
123 cd ..
124
125# ntsim-ng copy and build
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300126ARG BUILD_WITH_DEBUG
127ENV BUILD_WITH_DEBUG=${BUILD_WITH_DEBUG}
128
Alex Stancuf1d5c912020-11-02 17:34:59 +0200129RUN \
130 mkdir /opt/dev/ntsim-ng && \
131 mkdir /opt/dev/ntsim-ng/config && \
132 mkdir /opt/dev/ntsim-ng/source
133COPY ./ntsim-ng /opt/dev/ntsim-ng/source
134COPY ./deploy/base/build_ntsim-ng.sh /opt/dev/ntsim-ng/build_ntsim-ng.sh
135RUN \
136 cd /opt/dev/ntsim-ng && \
137 sed -i '/argp/d' build_ntsim-ng.sh && \
Alex Stancu6d03d772021-05-10 19:35:52 +0300138 ./build_ntsim-ng.sh && \
139 rm -rf source && \
140 rm -f build_ntsim-ng.sh
Alex Stancuf1d5c912020-11-02 17:34:59 +0200141
142# copy SSH related scripts and keys
143COPY ./deploy/base/ca.key /home/netconf/.ssh/ca.key
144COPY ./deploy/base/ca.pem /home/netconf/.ssh/ca.pem
145COPY ./deploy/base/client.crt /home/netconf/.ssh/client.crt
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300146COPY ./deploy/base/client.key /home/netconf/.ssh/client.key
Alex Stancuf1d5c912020-11-02 17:34:59 +0200147COPY ./deploy/base/generate-ssh-keys.sh /home/netconf/.ssh/generate-ssh-keys.sh
148
149#############################
150#### Lightweight Base ####
151#############################
152
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300153
Alex Stancuf1d5c912020-11-02 17:34:59 +0200154FROM ubuntu:20.04
155LABEL maintainer="alexandru.stancu@highstreet-technologies.com / adrian.lita@highstreet-technologies.com"
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300156
Alex Stancua58e0a02021-06-02 12:22:14 +0300157RUN apt-get update && apt-get install -y --no-install-recommends \
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300158 psmisc \
Alex Stancu6d03d772021-05-10 19:35:52 +0300159 unzip \
Alex Stancuf1d5c912020-11-02 17:34:59 +0200160 openssl \
161 openssh-client \
162 vsftpd \
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300163 openssh-server \
Alex Stancu22cd3062021-09-30 11:18:20 +0300164 iproute2 \
Alex Stancua58e0a02021-06-02 12:22:14 +0300165 && rm -rf /var/lib/apt/lists/*
166
Alex Stancua58e0a02021-06-02 12:22:14 +0300167ARG BUILD_WITH_DEBUG
168ENV BUILD_WITH_DEBUG=${BUILD_WITH_DEBUG}
169RUN if [ -n "${BUILD_WITH_DEBUG}" ]; then DEBIAN_FRONTEND="noninteractive" apt-get install -y gdb valgrind nano mc && unset BUILD_WITH_DEBUG; fi
Alex Stancuf1d5c912020-11-02 17:34:59 +0200170
171# add netconf user and configure access
172RUN \
173 adduser netconf && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300174 echo "netconf:netconf!" | chpasswd && \
Alex Stancuf1d5c912020-11-02 17:34:59 +0200175 mkdir -p /home/netconf/.ssh
176
177COPY --from=builder /usr/local/bin /usr/local/bin
178COPY --from=builder /usr/local/lib /usr/local/lib
179COPY --from=builder /usr/local/share /usr/local/share
180
181COPY --from=builder /etc/sysrepo /etc/sysrepo
182RUN ldconfig
183
184# use /opt/dev as working directory
185RUN mkdir /opt/dev
186WORKDIR /opt/dev
187
188# copy common NTS yang models
189RUN mkdir /opt/dev/deploy
190COPY ./deploy/base/yang /opt/dev/deploy/yang
191
192# copy ntsim-ng and dependencies
193COPY --from=builder /usr/bin/regxstring /usr/bin/regxstring
194COPY --from=builder /opt/dev/ntsim-ng /opt/dev/ntsim-ng
195
196# copy SSH related scripts and keys
197COPY --from=builder /home/netconf/.ssh /home/netconf/.ssh
198
Alex Stancu6d03d772021-05-10 19:35:52 +0300199### FTP and SFTP configuration
Alex Stancuf1d5c912020-11-02 17:34:59 +0200200RUN \
201 mkdir /ftp && \
Alex Stancu6d03d772021-05-10 19:35:52 +0300202 chown -R netconf:netconf /ftp && \
Alex Stancuf1d5c912020-11-02 17:34:59 +0200203 mkdir /var/run/vsftpd && \
204 mkdir /var/run/vsftpd/empty && \
205 mkdir /run/sshd && \
Alex Stancu6d03d772021-05-10 19:35:52 +0300206 echo "Match User netconf\n ChrootDirectory /\n X11Forwarding no\n AllowTcpForwarding no\n ForceCommand internal-sftp -d /ftp" >> /etc/ssh/sshd_config
Alex Stancuf1d5c912020-11-02 17:34:59 +0200207
208COPY ./deploy/base/vsftpd.conf /etc/vsftpd.conf
209COPY ./deploy/base/vsftpd.userlist /etc/vsftpd.userlist
210COPY ./deploy/base/pm_files /ftp
211
212WORKDIR /opt/dev/workspace
213
214ENV SSH_CONNECTIONS=1
215ENV TLS_CONNECTIONS=0
216ENV IPv6_ENABLED=false
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300217
218ARG NTS_BUILD_VERSION
219ENV NTS_BUILD_VERSION=${NTS_BUILD_VERSION}
220
221ARG NTS_BUILD_DATE
222ENV NTS_BUILD_DATE=${NTS_BUILD_DATE}