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 | |
| 23 | RUN apt-get clean |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 24 | RUN apt-get update |
| 25 | RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y \ |
| 26 | # basic tools |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 27 | tzdata build-essential git cmake pkg-config \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 28 | # libyang dependencies |
| 29 | libpcre3-dev \ |
| 30 | # libssh dependencies |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 31 | zlib1g-dev libssl-dev \ |
| 32 | && rm -rf /var/lib/apt/lists/* |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 33 | |
| 34 | # add netconf user and configure access |
| 35 | RUN \ |
| 36 | adduser --system netconf && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 37 | echo "netconf:netconf!" | chpasswd |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 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 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 49 | git clone --single-branch --branch libssh-0.9.2 https://git.libssh.org/projects/libssh.git && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 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 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 59 | make -j4 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 60 | make install && \ |
| 61 | ldconfig |
| 62 | |
| 63 | # build and install libyang |
| 64 | RUN \ |
| 65 | cd libyang && \ |
| 66 | mkdir build && cd build && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 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 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 69 | make install && \ |
| 70 | ldconfig |
| 71 | |
| 72 | # build and install sysrepo |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 73 | 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] | 74 | RUN \ |
| 75 | cd sysrepo && \ |
| 76 | mkdir build && cd build && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 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 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 .. && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 87 | make -j4 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 88 | make install && \ |
| 89 | ldconfig |
| 90 | |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 .. && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 96 | make -j4 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 .. && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 105 | make -j4 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 106 | make install |
| 107 | |
| 108 | # build and install cURL |
| 109 | RUN \ |
| 110 | cd curl && \ |
| 111 | mkdir build && cd build && \ |
| 112 | cmake -DBUILD_TESTING=OFF .. && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 113 | make -j4 && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 128 | ARG BUILD_WITH_DEBUG |
| 129 | ENV BUILD_WITH_DEBUG=${BUILD_WITH_DEBUG} |
| 130 | |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 && \ |
Alex Stancu | 6d03d77 | 2021-05-10 19:35:52 +0300 | [diff] [blame^] | 140 | ./build_ntsim-ng.sh && \ |
| 141 | rm -rf source && \ |
| 142 | rm -f build_ntsim-ng.sh |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 148 | COPY ./deploy/base/client.key /home/netconf/.ssh/client.key |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 149 | COPY ./deploy/base/generate-ssh-keys.sh /home/netconf/.ssh/generate-ssh-keys.sh |
| 150 | |
| 151 | ############################# |
| 152 | #### Lightweight Base #### |
| 153 | ############################# |
| 154 | |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 155 | |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 156 | FROM ubuntu:20.04 |
| 157 | LABEL maintainer="alexandru.stancu@highstreet-technologies.com / adrian.lita@highstreet-technologies.com" |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 158 | RUN apt-get clean |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 159 | RUN apt-get update |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 160 | |
| 161 | ARG BUILD_WITH_DEBUG |
| 162 | ENV BUILD_WITH_DEBUG=${BUILD_WITH_DEBUG} |
Alex Stancu | 6d03d77 | 2021-05-10 19:35:52 +0300 | [diff] [blame^] | 163 | RUN if [ -n "${BUILD_WITH_DEBUG}" ]; then DEBIAN_FRONTEND="noninteractive" apt-get install -y gdb valgrind nano mc ; fi |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 164 | |
| 165 | RUN apt-get install -y --no-install-recommends \ |
| 166 | psmisc \ |
Alex Stancu | 6d03d77 | 2021-05-10 19:35:52 +0300 | [diff] [blame^] | 167 | unzip \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 168 | openssl \ |
| 169 | openssh-client \ |
| 170 | vsftpd \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 171 | openssh-server \ |
| 172 | && rm -rf /var/lib/apt/lists/* \ |
| 173 | && unset BUILD_WITH_DEBUG |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 174 | |
| 175 | # add netconf user and configure access |
| 176 | RUN \ |
| 177 | adduser netconf && \ |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 178 | echo "netconf:netconf!" | chpasswd && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 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 | |
Alex Stancu | 6d03d77 | 2021-05-10 19:35:52 +0300 | [diff] [blame^] | 203 | ### FTP and SFTP configuration |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 204 | RUN \ |
| 205 | mkdir /ftp && \ |
Alex Stancu | 6d03d77 | 2021-05-10 19:35:52 +0300 | [diff] [blame^] | 206 | chown -R netconf:netconf /ftp && \ |
Alex Stancu | f1d5c91 | 2020-11-02 17:34:59 +0200 | [diff] [blame] | 207 | mkdir /var/run/vsftpd && \ |
| 208 | mkdir /var/run/vsftpd/empty && \ |
| 209 | mkdir /run/sshd && \ |
Alex Stancu | 6d03d77 | 2021-05-10 19:35:52 +0300 | [diff] [blame^] | 210 | 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] | 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 |
Alex Stancu | 3bbf9d8 | 2021-04-09 15:13:00 +0300 | [diff] [blame] | 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} |