blob: be86b974e0b3484485dd437a0a2ab57d35e120dc [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
23RUN apt-get clean
Alex Stancuf1d5c912020-11-02 17:34:59 +020024RUN apt-get update
25RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y \
26 # basic tools
Alex Stancu3bbf9d82021-04-09 15:13:00 +030027 tzdata build-essential git cmake pkg-config \
Alex Stancuf1d5c912020-11-02 17:34:59 +020028 # libyang dependencies
29 libpcre3-dev \
30 # libssh dependencies
Alex Stancu3bbf9d82021-04-09 15:13:00 +030031 zlib1g-dev libssl-dev \
32 && rm -rf /var/lib/apt/lists/*
Alex Stancuf1d5c912020-11-02 17:34:59 +020033
34# add netconf user and configure access
35RUN \
36 adduser --system netconf && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030037 echo "netconf:netconf!" | chpasswd
Alex Stancuf1d5c912020-11-02 17:34:59 +020038
39# use /opt/dev as working directory
40RUN mkdir /opt/dev
41WORKDIR /opt/dev
42
43# get required build libs from git
44RUN \
45 git config --global advice.detachedHead false && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030046 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 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +020049 git clone --single-branch --branch libssh-0.9.2 https://git.libssh.org/projects/libssh.git && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030050 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 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +020052 git clone --single-branch --branch curl-7_72_0 https://github.com/curl/curl.git
53
54# build and install cJSON
55RUN \
56 cd cJSON && \
57 mkdir build && cd build && \
58 cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_CJSON_TEST=Off && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030059 make -j4 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +020060 make install && \
61 ldconfig
62
63# build and install libyang
64RUN \
65 cd libyang && \
66 mkdir build && cd build && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030067 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 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +020069 make install && \
70 ldconfig
71
72# build and install sysrepo
Alex Stancu3bbf9d82021-04-09 15:13:00 +030073COPY ./deploy/base/common.h.in /opt/dev/sysrepo/src/common.h.in
Alex Stancuf1d5c912020-11-02 17:34:59 +020074RUN \
75 cd sysrepo && \
76 mkdir build && cd build && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030077 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 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +020079 make install && \
80 ldconfig
81
82# build and install libssh-dev
83RUN \
84 cd libssh && \
85 mkdir build && cd build && \
86 cmake -DWITH_EXAMPLES=OFF .. && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030087 make -j4 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +020088 make install && \
89 ldconfig
90
Alex Stancuf1d5c912020-11-02 17:34:59 +020091# build and install libnetconf2
92RUN \
93 cd libnetconf2 && \
94 mkdir build && cd build && \
95 cmake -DCMAKE_BUILD_TYPE:String="Release" -DENABLE_BUILD_TESTS=OFF .. && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +030096 make -j4 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +020097 make install && \
98 ldconfig
99
100# build and install netopeer2
101RUN \
102 cd netopeer2 && \
103 mkdir build && cd build && \
104 cmake -DCMAKE_BUILD_TYPE:String="Release" -DGENERATE_HOSTKEY=OFF -DMERGE_LISTEN_CONFIG=OFF .. && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300105 make -j4 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +0200106 make install
107
108# build and install cURL
109RUN \
110 cd curl && \
111 mkdir build && cd build && \
112 cmake -DBUILD_TESTING=OFF .. && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300113 make -j4 && \
Alex Stancuf1d5c912020-11-02 17:34:59 +0200114 make install && \
115 ldconfig
116
117# regxstring copy, build and install
118RUN mkdir /opt/dev/regxstring
119COPY ./regxstring /opt/dev/regxstring
120COPY ./deploy/base/build_regxstring.sh /opt/dev/regxstring/build_regxstring.sh
121RUN \
122 cd /opt/dev/regxstring && \
123 ./build_regxstring.sh && \
124 cp regxstring /usr/bin && \
125 cd ..
126
127# ntsim-ng copy and build
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300128ARG BUILD_WITH_DEBUG
129ENV BUILD_WITH_DEBUG=${BUILD_WITH_DEBUG}
130
Alex Stancuf1d5c912020-11-02 17:34:59 +0200131RUN \
132 mkdir /opt/dev/ntsim-ng && \
133 mkdir /opt/dev/ntsim-ng/config && \
134 mkdir /opt/dev/ntsim-ng/source
135COPY ./ntsim-ng /opt/dev/ntsim-ng/source
136COPY ./deploy/base/build_ntsim-ng.sh /opt/dev/ntsim-ng/build_ntsim-ng.sh
137RUN \
138 cd /opt/dev/ntsim-ng && \
139 sed -i '/argp/d' build_ntsim-ng.sh && \
Alex Stancu6d03d772021-05-10 19:35:52 +0300140 ./build_ntsim-ng.sh && \
141 rm -rf source && \
142 rm -f build_ntsim-ng.sh
Alex Stancuf1d5c912020-11-02 17:34:59 +0200143
144# copy SSH related scripts and keys
145COPY ./deploy/base/ca.key /home/netconf/.ssh/ca.key
146COPY ./deploy/base/ca.pem /home/netconf/.ssh/ca.pem
147COPY ./deploy/base/client.crt /home/netconf/.ssh/client.crt
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300148COPY ./deploy/base/client.key /home/netconf/.ssh/client.key
Alex Stancuf1d5c912020-11-02 17:34:59 +0200149COPY ./deploy/base/generate-ssh-keys.sh /home/netconf/.ssh/generate-ssh-keys.sh
150
151#############################
152#### Lightweight Base ####
153#############################
154
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300155
Alex Stancuf1d5c912020-11-02 17:34:59 +0200156FROM ubuntu:20.04
157LABEL maintainer="alexandru.stancu@highstreet-technologies.com / adrian.lita@highstreet-technologies.com"
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300158RUN apt-get clean
Alex Stancuf1d5c912020-11-02 17:34:59 +0200159RUN apt-get update
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300160
161ARG BUILD_WITH_DEBUG
162ENV BUILD_WITH_DEBUG=${BUILD_WITH_DEBUG}
Alex Stancu6d03d772021-05-10 19:35:52 +0300163RUN if [ -n "${BUILD_WITH_DEBUG}" ]; then DEBIAN_FRONTEND="noninteractive" apt-get install -y gdb valgrind nano mc ; fi
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300164
165RUN apt-get install -y --no-install-recommends \
166 psmisc \
Alex Stancu6d03d772021-05-10 19:35:52 +0300167 unzip \
Alex Stancuf1d5c912020-11-02 17:34:59 +0200168 openssl \
169 openssh-client \
170 vsftpd \
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300171 openssh-server \
172 && rm -rf /var/lib/apt/lists/* \
173 && unset BUILD_WITH_DEBUG
Alex Stancuf1d5c912020-11-02 17:34:59 +0200174
175# add netconf user and configure access
176RUN \
177 adduser netconf && \
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300178 echo "netconf:netconf!" | chpasswd && \
Alex Stancuf1d5c912020-11-02 17:34:59 +0200179 mkdir -p /home/netconf/.ssh
180
181COPY --from=builder /usr/local/bin /usr/local/bin
182COPY --from=builder /usr/local/lib /usr/local/lib
183COPY --from=builder /usr/local/share /usr/local/share
184
185COPY --from=builder /etc/sysrepo /etc/sysrepo
186RUN ldconfig
187
188# use /opt/dev as working directory
189RUN mkdir /opt/dev
190WORKDIR /opt/dev
191
192# copy common NTS yang models
193RUN mkdir /opt/dev/deploy
194COPY ./deploy/base/yang /opt/dev/deploy/yang
195
196# copy ntsim-ng and dependencies
197COPY --from=builder /usr/bin/regxstring /usr/bin/regxstring
198COPY --from=builder /opt/dev/ntsim-ng /opt/dev/ntsim-ng
199
200# copy SSH related scripts and keys
201COPY --from=builder /home/netconf/.ssh /home/netconf/.ssh
202
Alex Stancu6d03d772021-05-10 19:35:52 +0300203### FTP and SFTP configuration
Alex Stancuf1d5c912020-11-02 17:34:59 +0200204RUN \
205 mkdir /ftp && \
Alex Stancu6d03d772021-05-10 19:35:52 +0300206 chown -R netconf:netconf /ftp && \
Alex Stancuf1d5c912020-11-02 17:34:59 +0200207 mkdir /var/run/vsftpd && \
208 mkdir /var/run/vsftpd/empty && \
209 mkdir /run/sshd && \
Alex Stancu6d03d772021-05-10 19:35:52 +0300210 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 +0200211
212COPY ./deploy/base/vsftpd.conf /etc/vsftpd.conf
213COPY ./deploy/base/vsftpd.userlist /etc/vsftpd.userlist
214COPY ./deploy/base/pm_files /ftp
215
216WORKDIR /opt/dev/workspace
217
218ENV SSH_CONNECTIONS=1
219ENV TLS_CONNECTIONS=0
220ENV IPv6_ENABLED=false
Alex Stancu3bbf9d82021-04-09 15:13:00 +0300221
222ARG NTS_BUILD_VERSION
223ENV NTS_BUILD_VERSION=${NTS_BUILD_VERSION}
224
225ARG NTS_BUILD_DATE
226ENV NTS_BUILD_DATE=${NTS_BUILD_DATE}