Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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" |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 22 | |
Alex Stancu | a58e0a0 | 2021-06-02 12:22:14 +0300 | [diff] [blame] | 23 | RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 24 | # basic tools |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 25 | tzdata build-essential git cmake pkg-config \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 26 | # libyang dependencies |
| 27 | libpcre3-dev \ |
| 28 | # libssh dependencies |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 29 | zlib1g-dev libssl-dev \ |
| 30 | && rm -rf /var/lib/apt/lists/* |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 31 | |
| 32 | # add netconf user and configure access |
| 33 | RUN \ |
| 34 | adduser --system netconf && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 35 | echo "netconf:netconf!" | chpasswd |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 44 | git clone --single-branch --branch v1.7.14 https://github.com/DaveGamble/cJSON.git && \ |
Alex Stancu | 1d48882 | 2021-06-02 13:45:14 +0300 | [diff] [blame] | 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 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 47 | git clone --single-branch --branch libssh-0.9.2 https://git.libssh.org/projects/libssh.git && \ |
Alex Stancu | 1d48882 | 2021-06-02 13:45:14 +0300 | [diff] [blame] | 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 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 57 | make -j4 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 58 | make install && \ |
| 59 | ldconfig |
| 60 | |
| 61 | # build and install libyang |
| 62 | RUN \ |
| 63 | cd libyang && \ |
| 64 | mkdir build && cd build && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 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 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 67 | make install && \ |
| 68 | ldconfig |
| 69 | |
| 70 | # build and install sysrepo |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 71 | COPY ./deploy/base/common.h.in /opt/dev/sysrepo/src/common.h.in |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 72 | RUN \ |
| 73 | cd sysrepo && \ |
| 74 | mkdir build && cd build && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 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 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 .. && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 85 | make -j4 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 86 | make install && \ |
| 87 | ldconfig |
| 88 | |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 .. && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 94 | make -j4 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 .. && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 103 | make -j4 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 104 | make install |
| 105 | |
| 106 | # build and install cURL |
| 107 | RUN \ |
| 108 | cd curl && \ |
| 109 | mkdir build && cd build && \ |
| 110 | cmake -DBUILD_TESTING=OFF .. && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 111 | make -j4 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 126 | ARG BUILD_WITH_DEBUG |
| 127 | ENV BUILD_WITH_DEBUG=${BUILD_WITH_DEBUG} |
| 128 | |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 && \ |
Alex Stancu | 6d03d77 | 2021-05-10 19:35:52 +0300 | [diff] [blame] | 138 | ./build_ntsim-ng.sh && \ |
| 139 | rm -rf source && \ |
| 140 | rm -f build_ntsim-ng.sh |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 146 | COPY ./deploy/base/client.key /home/netconf/.ssh/client.key |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 147 | COPY ./deploy/base/generate-ssh-keys.sh /home/netconf/.ssh/generate-ssh-keys.sh |
| 148 | |
| 149 | ############################# |
| 150 | #### Lightweight Base #### |
| 151 | ############################# |
| 152 | |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 153 | |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 154 | FROM ubuntu:20.04 |
| 155 | LABEL maintainer="alexandru.stancu@highstreet-technologies.com / adrian.lita@highstreet-technologies.com" |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 156 | |
Alex Stancu | a58e0a0 | 2021-06-02 12:22:14 +0300 | [diff] [blame] | 157 | RUN apt-get update && apt-get install -y --no-install-recommends \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 158 | psmisc \ |
Alex Stancu | 6d03d77 | 2021-05-10 19:35:52 +0300 | [diff] [blame] | 159 | unzip \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 160 | openssl \ |
| 161 | openssh-client \ |
| 162 | vsftpd \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 163 | openssh-server \ |
Alex Stancu | 22cd306 | 2021-09-30 11:18:20 +0300 | [diff] [blame^] | 164 | iproute2 \ |
Alex Stancu | a58e0a0 | 2021-06-02 12:22:14 +0300 | [diff] [blame] | 165 | && rm -rf /var/lib/apt/lists/* |
| 166 | |
Alex Stancu | a58e0a0 | 2021-06-02 12:22:14 +0300 | [diff] [blame] | 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 |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 170 | |
| 171 | # add netconf user and configure access |
| 172 | RUN \ |
| 173 | adduser netconf && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 174 | echo "netconf:netconf!" | chpasswd && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 | |
Alex Stancu | 6d03d77 | 2021-05-10 19:35:52 +0300 | [diff] [blame] | 199 | ### FTP and SFTP configuration |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 200 | RUN \ |
| 201 | mkdir /ftp && \ |
Alex Stancu | 6d03d77 | 2021-05-10 19:35:52 +0300 | [diff] [blame] | 202 | chown -R netconf:netconf /ftp && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 203 | mkdir /var/run/vsftpd && \ |
| 204 | mkdir /var/run/vsftpd/empty && \ |
| 205 | mkdir /run/sshd && \ |
Alex Stancu | 6d03d77 | 2021-05-10 19:35:52 +0300 | [diff] [blame] | 206 | echo "Match User netconf\n ChrootDirectory /\n X11Forwarding no\n AllowTcpForwarding no\n ForceCommand internal-sftp -d /ftp" >> /etc/ssh/sshd_config |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 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} |